Go to the documentation of this file.00001
00002
00003 #include "osl/state/numEffectState.h"
00004 #include "osl/record/csa.h"
00005 #include "osl/record/csaRecord.h"
00006 #include "osl/container/moveVector.h"
00007 #include "osl/move_generator/legalMoves.h"
00008 #include "osl/move_action/store.h"
00009 #include "osl/move_generator/addEffectWithEffect.h"
00010 #include "osl/move_generator/addEffect_.h"
00011 #include "osl/search/quiescenceGenerator.tcc"
00012 #include "osl/checkmate/king8Info.h"
00013 #include "osl/record/csa.h"
00014 #include <boost/program_options.hpp>
00015 #include <iostream>
00016 using namespace osl;
00017
00022 int main(int argc, char **argv)
00023 {
00024 bool csa, generate_check, quiesce_check;
00025 boost::program_options::options_description command_line_options;
00026 command_line_options.add_options()
00027 ("csa",
00028 boost::program_options::value<bool>(&csa)->default_value(false),
00029 "Show legal moves in CSA format")
00030 ("input-file", boost::program_options::value< std::vector<std::string> >(),
00031 "input files in kisen format")
00032 ("generate-check",
00033 boost::program_options::value<bool>(&generate_check)->default_value(false),
00034 "generate only check moves instead of all legal moves")
00035 ("generate-quiesce-check",
00036 boost::program_options::value<bool>(&quiesce_check)->default_value(false),
00037 "generate only check moves used in quiescence search")
00038 ("help", "Show help message");
00039 boost::program_options::variables_map vm;
00040 boost::program_options::positional_options_description p;
00041 p.add("input-file", -1);
00042
00043 try
00044 {
00045 boost::program_options::store(
00046 boost::program_options::command_line_parser(
00047 argc, argv).options(command_line_options).positional(p).run(), vm);
00048 boost::program_options::notify(vm);
00049 if (vm.count("help"))
00050 {
00051 std::cerr << "Usage: " << argv[0] << " [options] CSA_FILE1 CSA_FILE2 ..."
00052 << std::endl;
00053 std::cout << command_line_options << std::endl;
00054 return 0;
00055 }
00056 }
00057 catch (std::exception &e)
00058 {
00059 std::cerr << "error in parsing options" << std::endl
00060 << e.what() << std::endl;
00061 std::cerr << "Usage: " << argv[0] << " [options] CSA_FILE1 CSA_FILE2 ..."
00062 << std::endl;
00063 std::cerr << command_line_options << std::endl;
00064 return 1;
00065 }
00066
00067 const std::vector<std::string> files =
00068 vm["input-file"].as< std::vector<std::string> >();
00069
00070 for (size_t i = 0; i < files.size(); ++i)
00071 {
00072 const Record record = CsaFile(files[i]).getRecord();
00073 NumEffectState state(record.getInitialState());
00074 const vector<Move> moves=record.getMoves();
00075 for (vector<Move>::const_iterator p=moves.begin(); p!=moves.end(); ++p)
00076 {
00077 state.makeMove(*p);
00078 }
00079 MoveVector legal_moves;
00080 if (generate_check)
00081 {
00082 move_action::Store store(legal_moves);
00083 move_generator::GenerateAddEffectWithEffect::generate<true>
00084 (state.turn(), state, state.kingPiece(alt(state.turn())).square(), store);
00085 }
00086 else if (quiesce_check)
00087 {
00088 const checkmate::King8Info info(state.Iking8Info(state.turn()));
00089 if (state.turn() == BLACK)
00090 search::QuiescenceGenerator<BLACK>::check(state, state.pin(WHITE), legal_moves, info.libertyCount()==0);
00091 else
00092 search::QuiescenceGenerator<WHITE>::check(state, state.pin(WHITE), legal_moves, info.libertyCount()==0);
00093 }
00094 else
00095 {
00096 LegalMoves::generate(state, legal_moves);
00097 }
00098 if (i > 0)
00099 {
00100 std::cout << std::endl;
00101 }
00102 if (csa)
00103 {
00104 for (size_t i = 0; i < legal_moves.size(); ++i)
00105 {
00106 std::cout << osl::record::csa::show(legal_moves[i]) << std::endl;
00107 }
00108 }
00109 else
00110 {
00111 std::cout << legal_moves;
00112 }
00113 }
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123