All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
find-uplevel-king.cc
Go to the documentation of this file.
1 /* find-uplevel-king.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 int count = 0;
16 bool run(const NumEffectState& initial, const vector<Move>& moves)
17 {
18  NumEffectState state(initial);
19  for (size_t i=0; i<moves.size(); ++i){
20  state.makeMove(moves[i]);
21  Player P = alt(state.turn());
22  if (state.kingSquare(P).squareForBlack(P).y() < 5) {
23  // std::cerr << state << moves[i] << "\n";
24  return true;
25  }
26  }
27  return false;
28 }
29 
30 
31 int main(int argc, char **argv) {
32  std::string kisen_filename;
33  po::options_description options("Options");
34  options.add_options()
35  ("kisen,k",
36  po::value<std::string>(&kisen_filename),
37  "kisen filename")
38  ("csa-file", po::value<std::vector<std::string> >())
39  ("help", "produce help message")
40  ;
41  po::positional_options_description p;
42  p.add("csa-file", -1);
43 
44  po::variables_map vm;
45  std::vector<std::string> filenames;
46  try {
47  po::store(po::command_line_parser(argc, argv).
48  options(options).positional(p).run(), vm);
49  notify(vm);
50  if (vm.count("help")) {
51  std::cout << options << std::endl;
52  return 0;
53  }
54  if (vm.count("csa-file"))
55  filenames = vm["csa-file"].as<std::vector<std::string> >();
56  }
57  catch (std::exception& e) {
58  std::cerr << "error in parsing options" << std::endl
59  << e.what() << std::endl;
60  std::cerr << options << std::endl;
61  return 1;
62  }
63 
64  if (kisen_filename != "") {
65  KisenFile kisen(kisen_filename);
66  for (size_t i=0; i<kisen.size(); ++i) {
67  std::cerr << '.';
68  NumEffectState state(kisen.getInitialState());
69  vector<Move> moves = kisen.getMoves(i);
70  if (run(state, moves))
71  std::cout << i << "\n";
72  }
73  }
74  for (size_t i=0; i<filenames.size(); ++i) {
75  std::cerr << '.';
76  CsaFile file(filenames[i].c_str());
77  NumEffectState state(file.getInitialState());
78  vector<Move> moves = file.getRecord().getMoves();
79  if (run(state, moves))
80  std::cout << filenames[i] << "\n";
81  }
82  std::cerr << "count = " << count << "\n";
83 }
84 // ;;; Local Variables:
85 // ;;; mode:c++
86 // ;;; c-basic-offset:2
87 // ;;; End:
88