All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
legal_moves.cc
Go to the documentation of this file.
1 /* legal_moves.cc
2  */
4 #include "osl/record/csa.h"
5 #include "osl/record/csaRecord.h"
13 #include "osl/record/csa.h"
14 #include <boost/program_options.hpp>
15 #include <iostream>
16 using namespace osl;
17 
22 int main(int argc, char **argv)
23 {
24  bool csa, generate_check, quiesce_check;
25  boost::program_options::options_description command_line_options;
26  command_line_options.add_options()
27  ("csa",
28  boost::program_options::value<bool>(&csa)->default_value(false),
29  "Show legal moves in CSA format")
30  ("input-file", boost::program_options::value< std::vector<std::string> >(),
31  "input files in kisen format")
32  ("generate-check",
33  boost::program_options::value<bool>(&generate_check)->default_value(false),
34  "generate only check moves instead of all legal moves")
35  ("generate-quiesce-check",
36  boost::program_options::value<bool>(&quiesce_check)->default_value(false),
37  "generate only check moves used in quiescence search")
38  ("help", "Show help message");
39  boost::program_options::variables_map vm;
40  boost::program_options::positional_options_description p;
41  p.add("input-file", -1);
42 
43  try
44  {
46  boost::program_options::command_line_parser(
47  argc, argv).options(command_line_options).positional(p).run(), vm);
48  boost::program_options::notify(vm);
49  if (vm.count("help"))
50  {
51  std::cerr << "Usage: " << argv[0] << " [options] CSA_FILE1 CSA_FILE2 ..."
52  << std::endl;
53  std::cout << command_line_options << std::endl;
54  return 0;
55  }
56  }
57  catch (std::exception &e)
58  {
59  std::cerr << "error in parsing options" << std::endl
60  << e.what() << std::endl;
61  std::cerr << "Usage: " << argv[0] << " [options] CSA_FILE1 CSA_FILE2 ..."
62  << std::endl;
63  std::cerr << command_line_options << std::endl;
64  return 1;
65  }
66 
67  const std::vector<std::string> files =
68  vm["input-file"].as< std::vector<std::string> >();
69 
70  for (size_t i = 0; i < files.size(); ++i)
71  {
72  const Record record = CsaFile(files[i]).getRecord();
73  NumEffectState state(record.getInitialState());
74  const vector<Move> moves=record.getMoves();
75  for (vector<Move>::const_iterator p=moves.begin(); p!=moves.end(); ++p)
76  {
77  state.makeMove(*p);
78  }
79  MoveVector legal_moves;
80  if (generate_check)
81  {
82  move_action::Store store(legal_moves);
83  move_generator::GenerateAddEffectWithEffect::generate<true>
84  (state.turn(), state, state.kingPiece(alt(state.turn())).square(), store);
85  }
86  else if (quiesce_check)
87  {
88  const checkmate::King8Info info(state.Iking8Info(state.turn()));
89  if (state.turn() == BLACK)
90  search::QuiescenceGenerator<BLACK>::check(state, state.pin(WHITE), legal_moves, info.libertyCount()==0);
91  else
92  search::QuiescenceGenerator<WHITE>::check(state, state.pin(WHITE), legal_moves, info.libertyCount()==0);
93  }
94  else
95  {
96  LegalMoves::generate(state, legal_moves);
97  }
98  if (i > 0)
99  {
100  std::cout << std::endl;
101  }
102  if (csa)
103  {
104  for (size_t i = 0; i < legal_moves.size(); ++i)
105  {
106  std::cout << osl::record::csa::show(legal_moves[i]) << std::endl;
107  }
108  }
109  else
110  {
111  std::cout << legal_moves;
112  }
113  }
114 }
115 
116 
117 
118 /* ------------------------------------------------------------------------- */
119 // ;;; Local Variables:
120 // ;;; mode:c++
121 // ;;; c-basic-offset:2
122 // ;;; coding:utf-8
123 // ;;; End: