All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
showRecord.cc
Go to the documentation of this file.
1 /*
2  *
3  */
4 
5 #include "osl/record/csaRecord.h"
6 #include "osl/record/kisen.h"
9 
10 #include <iostream>
11 #include <cstdlib>
12 #include <unistd.h>
13 
14 using namespace osl;
15 
16 void usage(const char *prog)
17 {
18  using namespace std;
19  cerr << "Usage: " << prog << " [-N atmost-N-games] [-k kisenFileName] csa-filenames "
20  << endl;
21  // kisenファイル と csaファイル を再生
22  exit(1);
23 }
24 
25 void processKifu (osl::vector<Move> const& moves)
26 {
27  NumEffectState state((SimpleState(HIRATE)));
28  std::cout << state << std::endl;
29  for (size_t i=0; i<moves.size (); ++i)
30  {
31  if (state.inCheck(alt(state.turn())))
32  {
33  // 自分の手番で相手の王が利きがある => 直前の手が非合法手
34  std::cerr << "e"; // state;
35  break;
36  }
37  state.makeMove(moves[i]);
38  std::cout << state << std::endl;
39  }
40  std::cout << state << std::endl;
41 }
42 
43 int main(int argc, char **argv)
44 {
45  const char *program_name = argv[0];
46  bool error_flag = false;
47  bool verbose = false;
48  const char *kisenFilename = 0;
49 
50  extern char *optarg;
51  extern int optind;
52  char c;
53  size_t num_records = 1;
54  while ((c = getopt(argc, argv, "N:k:vh")) != EOF)
55  {
56  switch(c)
57  {
58  case 'k': kisenFilename = optarg;
59  break;
60  case 'N': num_records = atoi(optarg);
61  break;
62  case 'v': verbose = true;
63  break;
64  default: error_flag = true;
65  }
66  }
67  argc -= optind;
68  argv += optind;
69 
70  if (error_flag)
71  usage(program_name);
72 
73  try
74  {
75  nice(20);
76  size_t record_processed = 0;
77 
78  //最初は Kisenファイルを処理
79  if (kisenFilename)
80  {
81  KisenFile kisenFile(kisenFilename);
82 
83  for (size_t i=0; i<kisenFile.size(); i++)
84  {
85  if (++record_processed > num_records)
86  break;
87  const vector<Move> moves=kisenFile.getMoves(i);
88  processKifu (moves);
89  }
90  }
91 
92  //次に CSAファイルを処理
93  for (int i=0; i<argc; ++i)
94  {
95  if (++record_processed > num_records)
96  break;
97  CsaFile file(argv [i]);
98  const vector<Move> moves=file.getRecord().getMoves();
99 
100  processKifu (moves);
101  }
102  }
103 
104  catch (std::exception& e)
105  {
106  std::cerr << e.what() << "\n";
107  return 1;
108  }
109 }
110 
111 // ;;; Local Variables:
112 // ;;; mode:c++
113 // ;;; c-basic-offset:2
114 // ;;; End: