All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
find-losing-moves.cc
Go to the documentation of this file.
1 /* find-illegal-moves.cc
2  */
4 #include "osl/record/kisen.h"
5 #include "osl/record/csaRecord.h"
7 #include "osl/sennichite.h"
8 #include <boost/program_options.hpp>
9 #include <boost/foreach.hpp>
10 #include <iostream>
11 #include <cmath>
12 namespace po = boost::program_options;
13 
14 using namespace osl;
15 void run(const NumEffectState& initial, const vector<Move>& moves)
16 {
17  game_playing::GameState state(initial);
18  for (size_t i=0; i<moves.size(); ++i){
19  MoveVector normal, loss;
20  state.generateNotLosingMoves(normal, loss);
21  bool show = ! loss.empty() || ! normal.isMember(moves[i]);
22  if (show) {
23  std::cerr << state.state();
24  std::cerr << "history ";
25  for (size_t j=0; j<=i; ++j)
26  std::cerr << record::csa::show(moves[j]);
27  std::cerr << "\n";
28  }
29  if (! loss.empty()) {
30  std::cerr << "losing moves ";
31  BOOST_FOREACH(Move m, loss) {
32  std::cerr << record::csa::show(m);
33  }
34  std::cerr << "\n";
35  }
36  if (! normal.isMember(moves[i]))
37  std::cerr << "error? " << moves[i] << "\n";
38  state.pushMove(moves[i]);
39 
40  }
41 }
42 
43 
44 int main(int argc, char **argv) {
45  std::string kisen_filename;
46  po::options_description options("Options");
47  options.add_options()
48  ("kisen,k",
49  po::value<std::string>(&kisen_filename),
50  "kisen filename")
51  ("csa-file", po::value<std::vector<std::string> >())
52  ("help", "produce help message")
53  ;
54  po::positional_options_description p;
55  p.add("csa-file", -1);
56 
57  po::variables_map vm;
58  std::vector<std::string> filenames;
59  try {
60  po::store(po::command_line_parser(argc, argv).
61  options(options).positional(p).run(), vm);
62  notify(vm);
63  if (vm.count("help")) {
64  std::cout << options << std::endl;
65  return 0;
66  }
67  if (vm.count("csa-file"))
68  filenames = vm["csa-file"].as<std::vector<std::string> >();
69  }
70  catch (std::exception& e) {
71  std::cerr << "error in parsing options" << std::endl
72  << e.what() << std::endl;
73  std::cerr << options << std::endl;
74  return 1;
75  }
76 
77  if (kisen_filename != "") {
78  KisenFile kisen(kisen_filename);
79  for (size_t i=0; i<kisen.size(); ++i) {
80  std::cerr << '.';
81  NumEffectState state(kisen.getInitialState());
82  vector<Move> moves = kisen.getMoves(i);
83  run(state, moves);
84  }
85  }
86  for (size_t i=0; i<filenames.size(); ++i) {
87  std::cerr << '.';
88  CsaFile file(filenames[i].c_str());
89  NumEffectState state(file.getInitialState());
90  vector<Move> moves = file.getRecord().getMoves();
91  run(state, moves);
92  }
93 }
94 // ;;; Local Variables:
95 // ;;; mode:c++
96 // ;;; c-basic-offset:2
97 // ;;; End:
98