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