00001
00002
00003 #include "osl/game_playing/gameState.h"
00004 #include "osl/record/kisen.h"
00005 #include "osl/record/csaRecord.h"
00006 #include "osl/container/moveVector.h"
00007 #include "osl/sennichite.h"
00008 #include <boost/program_options.hpp>
00009 #include <boost/foreach.hpp>
00010 #include <iostream>
00011 #include <cmath>
00012 namespace po = boost::program_options;
00013
00014 using namespace osl;
00015 void run(const NumEffectState& initial, const vector<Move>& moves)
00016 {
00017 game_playing::GameState state(initial);
00018 for (size_t i=0; i<moves.size(); ++i){
00019 MoveVector normal, loss;
00020 state.generateNotLosingMoves(normal, loss);
00021 bool show = ! loss.empty() || ! normal.isMember(moves[i]);
00022 if (show) {
00023 std::cerr << state.state();
00024 std::cerr << "history ";
00025 for (size_t j=0; j<=i; ++j)
00026 std::cerr << " " << record::csa::show(moves[j]);
00027 }
00028 if (! loss.empty()) {
00029 BOOST_FOREACH(Move m, loss) {
00030 std::cerr << " " << record::csa::show(m);
00031 }
00032 std::cerr << "\n";
00033 }
00034 if (! normal.isMember(moves[i]))
00035 std::cerr << " error? " << moves[i] << "\n";
00036 state.pushMove(moves[i]);
00037
00038 }
00039 }
00040
00041
00042 int main(int argc, char **argv) {
00043 std::string kisen_filename;
00044 po::options_description options("Options");
00045 options.add_options()
00046 ("kisen,k",
00047 po::value<std::string>(&kisen_filename),
00048 "kisen filename")
00049 ("csa-file", po::value<std::vector<std::string> >())
00050 ("help", "produce help message")
00051 ;
00052 po::positional_options_description p;
00053 p.add("csa-file", -1);
00054
00055 po::variables_map vm;
00056 std::vector<std::string> filenames;
00057 try {
00058 po::store(po::command_line_parser(argc, argv).
00059 options(options).positional(p).run(), vm);
00060 notify(vm);
00061 if (vm.count("help")) {
00062 std::cout << options << std::endl;
00063 return 0;
00064 }
00065 if (vm.count("csa-file"))
00066 filenames = vm["csa-file"].as<std::vector<std::string> >();
00067 }
00068 catch (std::exception& e) {
00069 std::cerr << "error in parsing options" << std::endl
00070 << e.what() << std::endl;
00071 std::cerr << options << std::endl;
00072 return 1;
00073 }
00074
00075 if (kisen_filename != "") {
00076 KisenFile kisen(kisen_filename);
00077 for (size_t i=0; i<kisen.size(); ++i) {
00078 std::cerr << '.';
00079 NumEffectState state(kisen.getInitialState());
00080 vector<Move> moves = kisen.getMoves(i);
00081 run(state, moves);
00082 }
00083 }
00084 for (size_t i=0; i<filenames.size(); ++i) {
00085 std::cerr << '.';
00086 CsaFile file(filenames[i].c_str());
00087 NumEffectState state(file.getInitialState());
00088 vector<Move> moves = file.getRecord().getMoves();
00089 run(state, moves);
00090 }
00091 }
00092
00093
00094
00095
00096