All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
show_repetition.cc
Go to the documentation of this file.
1 /* show_repetition.cc
2  */
4 #include "osl/record/csaRecord.h"
5 #include "osl/record/csa.h"
6 #include <iostream>
7 #include <cstdio>
8 
9 void usage(const char *program_name)
10 {
11 }
12 
13 using namespace osl;
14 
15 void processRecord(osl::vector<Move> const& moves)
16 {
17  NumEffectState state((SimpleState(HIRATE)));
18  RepetitionCounter counter(state);
19  for (size_t i=0; i<moves.size (); ++i)
20  {
21  std::cout << i+1 << " " << record::csa::show(moves[i]) << std::endl;
22  std::cout << counter.isSennichite(state, moves[i]) << std::endl;
23  std::cout << "("
24  << counter.isAlmostSennichite(HashKey(state).newHashWithMove(moves[i]))
25  << ")\n";
26  state.makeMove(moves[i]);
27  counter.push(state);
28  const int times = counter.countRepetition(HashKey(state));
29  if (times > 1)
30  {
31  std::cout << times
32  << "-times, first appeared at "
33  << counter.getFirstMove(HashKey(state))
34  << " check " << counter.checkCount(BLACK)
35  << " " << counter.checkCount(WHITE)
36  << "\n";
37  }
38  std::cout << "\n";
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 
49  // extern char *optarg;
50  extern int optind;
51  char c;
52  while ((c = getopt(argc, argv, "vh")) != EOF)
53  {
54  switch(c)
55  {
56  case 'v': verbose = true;
57  break;
58  default: error_flag = true;
59  }
60  }
61  argc -= optind;
62  argv += optind;
63 
64  if (error_flag)
65  usage(program_name);
66 
67  nice(20);
68 
69  //次に CSAファイルを処理
70  for (int i=0; i<argc; ++i)
71  {
72  CsaFile file(argv [i]);
73  const vector<Move> moves=file.getRecord().getMoves();
74 
75  processRecord(moves);
76  }
77 }
78 
79 /* ------------------------------------------------------------------------- */
80 // ;;; Local Variables:
81 // ;;; mode:c++
82 // ;;; c-basic-offset:2
83 // ;;; End: