All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bad-moves.cc
Go to the documentation of this file.
1 #include <boost/program_options.hpp>
2 #include <iostream>
4 #include "osl/record/csaRecord.h"
5 #include "osl/record/csa.h"
6 #include "osl/record/record.h"
8 
9 static int eval_threshold = 128;
10 static int critical_drop = 64;
11 
12 struct MoveData
13 {
14  MoveData() : index(0), value(0), next_value(0) { }
15  MoveData(size_t i, int v, int next_v)
16  : index(i), value(v), next_value(next_v) { }
17  size_t index;
18  int value;
20 };
21 
22 void find_bad_moves(bool sente, const std::string &filename)
23 {
24  osl::record::csa::CsaFile file(filename);
25  osl::vector<osl::Move> moves;
26  osl::vector<std::string> dummy1;
27  osl::vector<int> time;
28  osl::vector<osl::record::SearchInfo> info;
29  file.getRecord().getMoves(moves, time, dummy1, info);
30  int prev_value = 0;
31  osl::vector<MoveData> bad_indices;
32 
33  for (size_t i = sente ? 0 : 1; i < info.size(); i += 2)
34  {
35  // skip joseki
36  if (time[i] == 1 && info[i].value == 0 && prev_value == 0)
37  {
38  }
39  else
40  {
41  if ((sente && info[i].value > -eval_threshold &&
42  info[i].value - prev_value < -critical_drop) ||
43  (!sente && info[i].value < eval_threshold &&
44  info[i].value - prev_value > critical_drop))
45  {
46  bad_indices.push_back(MoveData(i - 2, prev_value, info[i].value));
47  }
48  }
49  prev_value = info[i].value;
50  }
52  for (size_t i = 0, j = 0; i < moves.size() && j < bad_indices.size();
53  i++)
54  {
55  if (bad_indices[j].index == i)
56  {
57  std::cout << state
58  << "' " << i << ": " << info[i].value << " -> "
59  << info[i+2].value<< std::endl
60  << osl::record::csa::show(moves[i]) << std::endl
61  << osl::record::csa::show(moves[i+1]) << std::endl
62  << osl::record::csa::show(moves[i+2]) << std::endl;
63  osl::stl::vector<osl::Move> &pv_moves = info[i+2].moves;
64  bool found_pass = false;
65  for (size_t k = 0; k < pv_moves.size(); k++)
66  {
67  if (found_pass)
68  std::cout << "' ";
69  if (pv_moves[k].isPass())
70  {
71  if (!found_pass)
72  std::cout << "' ";
73  else
74  found_pass = true;
75  std::cout << "%PASS" << std::endl;
76  }
77  else
78  {
79  std::cout << osl::record::csa::show(pv_moves[k]) << std::endl;
80  }
81  }
82  j++;
83  }
84  state.makeMove(moves[i]);
85  }
86 }
87 
88 int main(int argc, char **argv)
89 {
90  bool sente;
91  boost::program_options::options_description command_line_options;
92  command_line_options.add_options()
93  ("sente",
94  boost::program_options::value<bool>(&sente)->default_value(true),
95  "Whether you want to check sente or gote moves")
96  ("input-file", boost::program_options::value< std::vector<std::string> >(),
97  "input files in CSA format")
98  ("help", "Show help message");
99  boost::program_options::variables_map vm;
100  boost::program_options::positional_options_description p;
101  p.add("input-file", -1);
102 
103  try
104  {
106  boost::program_options::command_line_parser(
107  argc, argv).options(command_line_options).positional(p).run(), vm);
108  boost::program_options::notify(vm);
109  if (vm.count("help"))
110  {
111  std::cerr << "Usage: " << argv[0] << " [options] csa-file"
112  << std::endl;
113  std::cout << command_line_options << std::endl;
114  return 0;
115  }
116  }
117  catch (std::exception &e)
118  {
119  std::cerr << "error in parsing options" << std::endl
120  << e.what() << std::endl;
121  std::cerr << "Usage: " << argv[0] << " [options] csa-file" << std::endl;
122  std::cerr << command_line_options << std::endl;
123  return 1;
124  }
125 
126  const std::vector<std::string> files =
127  vm["input-file"].as< std::vector<std::string> >();
128  for (size_t i = 0; i < files.size(); i++)
129  {
130  find_bad_moves(sente, files[i]);
131  }
132  return 0;
133 }