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