bad-moves.cc
Go to the documentation of this file.
00001 #include <boost/program_options.hpp>
00002 #include <iostream>
00003 #include "osl/state/simpleState.h"
00004 #include "osl/record/csaRecord.h"
00005 #include "osl/record/csa.h"
00006 #include "osl/record/record.h"
00007 #include "osl/record/searchInfo.h"
00008 
00009 static int eval_threshold = 128;
00010 static int critical_drop = 64;
00011 
00012 struct MoveData
00013 {
00014   MoveData() : index(0), value(0), next_value(0) { }
00015   MoveData(size_t i, int v, int next_v)
00016     : index(i), value(v), next_value(next_v) { }
00017   size_t index;
00018   int value;
00019   int next_value;
00020 };
00021 
00022 void find_bad_moves(bool sente, const std::string &filename)
00023 {
00024   osl::record::csa::CsaFile file(filename);
00025   osl::vector<osl::Move> moves;
00026   osl::vector<std::string> dummy1;
00027   osl::vector<int> time;
00028   osl::vector<osl::record::SearchInfo> info;
00029   file.getRecord().getMoves(moves, time, dummy1, info);
00030   int prev_value = 0;
00031   osl::vector<MoveData> bad_indices;
00032   
00033   for (size_t i = sente ? 0 : 1; i < info.size(); i += 2)
00034   {
00035     // skip joseki
00036     if (time[i] == 1 && info[i].value == 0 && prev_value == 0)
00037     {
00038     }
00039     else
00040     {
00041       if ((sente && info[i].value > -eval_threshold &&
00042            info[i].value - prev_value < -critical_drop) ||
00043           (!sente && info[i].value < eval_threshold &&
00044            info[i].value - prev_value > critical_drop))
00045       {
00046         bad_indices.push_back(MoveData(i - 2, prev_value, info[i].value));
00047       }
00048     }
00049     prev_value = info[i].value;
00050   }
00051   osl::state::NumEffectState state(file.getInitialState());
00052   for (size_t i = 0, j = 0; i < moves.size() && j < bad_indices.size();
00053        i++)
00054   {
00055     if (bad_indices[j].index == i)
00056     {
00057       std::cout << state
00058                 << "' " <<  i << ": " << info[i].value << " -> "
00059                 << info[i+2].value<< std::endl
00060                 << osl::record::csa::show(moves[i]) << std::endl
00061                 << osl::record::csa::show(moves[i+1]) << std::endl
00062                 << osl::record::csa::show(moves[i+2]) << std::endl;
00063       osl::stl::vector<osl::Move> &pv_moves = info[i+2].moves;
00064       bool found_pass = false;
00065       for (size_t k = 0; k < pv_moves.size(); k++)
00066       {
00067         if (found_pass)
00068           std::cout << "' ";
00069         if (pv_moves[k].isPass())
00070         {
00071           if (!found_pass)
00072             std::cout << "' ";
00073           else
00074             found_pass = true;
00075           std::cout << "%PASS" << std::endl;
00076         }
00077         else
00078         {
00079           std::cout << osl::record::csa::show(pv_moves[k]) << std::endl;
00080         }
00081       }
00082       j++;
00083     }
00084     state.makeMove(moves[i]);
00085   }
00086 }
00087 
00088 int main(int argc, char **argv)
00089 {
00090   bool sente;
00091   boost::program_options::options_description command_line_options;
00092   command_line_options.add_options()
00093     ("sente",
00094      boost::program_options::value<bool>(&sente)->default_value(true),
00095      "Whether you want to check sente or gote moves")
00096     ("input-file", boost::program_options::value< std::vector<std::string> >(),
00097      "input files in CSA format")
00098     ("help", "Show help message");
00099   boost::program_options::variables_map vm;
00100   boost::program_options::positional_options_description p;
00101   p.add("input-file", -1);
00102 
00103   try
00104   {
00105     boost::program_options::store(
00106       boost::program_options::command_line_parser(
00107         argc, argv).options(command_line_options).positional(p).run(), vm);
00108     boost::program_options::notify(vm);
00109     if (vm.count("help"))
00110     {
00111       std::cerr << "Usage: " << argv[0] << " [options] csa-file"
00112                 << std::endl;
00113       std::cout << command_line_options << std::endl;
00114       return 0;
00115     }
00116   }
00117   catch (std::exception &e)
00118   {
00119     std::cerr << "error in parsing options" << std::endl
00120               << e.what() << std::endl;
00121     std::cerr << "Usage: " << argv[0] << " [options] csa-file" << std::endl;
00122     std::cerr << command_line_options << std::endl;
00123     return 1;
00124   }
00125 
00126   const std::vector<std::string> files =
00127     vm["input-file"].as< std::vector<std::string> >();
00128   for (size_t i = 0; i < files.size(); i++)
00129   {
00130     find_bad_moves(sente, files[i]);
00131   }
00132   return 0;
00133 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines