find-losing-moves.cc
Go to the documentation of this file.
00001 /* find-illegal-moves.cc
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       std::cerr << "\n";
00028     }
00029     if (! loss.empty()) {
00030       std::cerr << "losing moves ";
00031       BOOST_FOREACH(Move m, loss) {
00032         std::cerr << record::csa::show(m);
00033       }
00034       std::cerr << "\n";
00035     }
00036     if (! normal.isMember(moves[i]))
00037       std::cerr << "error? " << moves[i] << "\n";
00038     state.pushMove(moves[i]);
00039     
00040   }
00041 }
00042 
00043 
00044 int main(int argc, char **argv) {
00045   std::string kisen_filename;
00046   po::options_description options("Options");
00047   options.add_options()
00048     ("kisen,k", 
00049      po::value<std::string>(&kisen_filename),
00050      "kisen filename")
00051     ("csa-file", po::value<std::vector<std::string> >())
00052     ("help", "produce help message")
00053     ;
00054   po::positional_options_description p;
00055   p.add("csa-file", -1);
00056 
00057   po::variables_map vm;
00058   std::vector<std::string> filenames;
00059   try {
00060     po::store(po::command_line_parser(argc, argv).
00061               options(options).positional(p).run(), vm);
00062     notify(vm);
00063     if (vm.count("help")) {
00064       std::cout << options << std::endl;
00065       return 0;
00066     }
00067     if (vm.count("csa-file"))
00068       filenames = vm["csa-file"].as<std::vector<std::string> >();
00069   }
00070   catch (std::exception& e) {
00071     std::cerr << "error in parsing options" << std::endl
00072               << e.what() << std::endl;
00073     std::cerr << options << std::endl;
00074     return 1;
00075   }
00076 
00077   if (kisen_filename != "") {
00078     KisenFile kisen(kisen_filename);
00079     for (size_t i=0; i<kisen.size(); ++i) {
00080       std::cerr << '.';
00081       NumEffectState state(kisen.getInitialState());
00082       vector<Move> moves = kisen.getMoves(i);
00083       run(state, moves);
00084     }
00085   }
00086   for (size_t i=0; i<filenames.size(); ++i) {
00087     std::cerr << '.';
00088     CsaFile file(filenames[i].c_str());
00089     NumEffectState state(file.getInitialState());
00090     vector<Move> moves = file.getRecord().getMoves();
00091     run(state, moves);
00092   }  
00093 }
00094 // ;;; Local Variables:
00095 // ;;; mode:c++
00096 // ;;; c-basic-offset:2
00097 // ;;; End:
00098 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines