All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
check-kisen.cc
Go to the documentation of this file.
2 #include "osl/record/kisen.h"
4 
5 #include <boost/scoped_ptr.hpp>
6 #include <iostream>
7 
8 void usage (const char *program_name)
9 {
10  std::cerr << "Usage: " << program_name << " KISEN-FILE [out]"
11  << std::endl;
12  exit(1);
13 }
14 
15 void check_all(const char*filename, const char *output)
16 {
17  osl::record::KisenFile kisen(filename);
18  boost::scoped_ptr<std::ofstream> os;
19  boost::scoped_ptr<osl::record::OKisenStream> out;
20  if (output) {
21  os.reset(new std::ofstream(output));
22  out.reset(new osl::record::OKisenStream(*os));
23  }
24 
25  for (size_t i = 0; i < kisen.size(); i++)
26  {
27  std::cout << i;
28  if ((i % 16) == 15 || i + 1 == kisen.size())
29  std::cout << std::endl;
30  else
31  std::cout << ' ';
33  osl::vector<osl::Move> moves;
34  size_t j = 0;
35  try {
36  moves = kisen.getMoves(i);
37  for (; j < moves.size(); j++)
38  {
39  const osl::Square opKingSquare
40  = state.kingSquare(alt(state.turn()));
41  if (state.hasEffectAt(state.turn(), opKingSquare))
42  {
43  if (j)
44  --j;
45  break;
46  }
47  state.makeMove(moves[j]);
48  }
49  moves.resize(j);
50  }
51  catch (osl::record::csa::CsaIOError& e) {
52  std::cerr << e.what();
53  }
54 
55  if (out)
56  out->save(kisen.getInitialState(), moves);
57  }
58 }
59 
60 int main(int argc, char **argv)
61 {
62  if (! (argc == 2 || argc == 3))
63  usage(argv[0]);
64 
65  check_all(argv[1], (argc == 3) ? argv[2] : "");
66 
67  return 0;
68 }
69 // ;;; Local Variables:
70 // ;;; mode:c++
71 // ;;; c-basic-offset:2
72 // ;;; End: