All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
opening-validator.cc
Go to the documentation of this file.
2 #include "osl/record/csa.h"
5 #include "osl/eval/pieceEval.h"
6 #include "osl/stl/vector.h"
7 #include <iostream>
8 #include <cstring>
9 
10 using namespace osl::record::opening;
11 
12 
13 static int qsearch(osl::state::SimpleState &s, osl::Move lastMove)
14 {
16 
18  osl::search::SimpleHashTable table(100000, -16, false);
20  osl::search::SearchState2Core core(state, checkmate_searcher);
21  qsearch_t qs(core, table);
22  osl::eval::PieceEval ev(state);
23  return qs.search(state.turn(), ev, lastMove);
24 }
25 
26 int main(int argc, char **argv)
27 {
28  if (argc != 2)
29  {
30  std::cerr << "Usage: " << argv[0] << " FILENAME" << std::endl;
31  return 1;
32  }
33 
34  WeightedBook book(argv[1]);
35  bool states[book.getTotalState()];
36 
37  memset(states, 0, sizeof(bool) * book.getTotalState());
38  osl::stl::vector<int> stateToVisit;
39 
40  stateToVisit.push_back(book.getStartState());
42 
43  while (!stateToVisit.empty())
44  {
45  const int stateIndex = stateToVisit.back();
46  stateToVisit.pop_back();
47  states[stateIndex] = true;
48 
49  osl::state::SimpleState state = book.getBoard(stateIndex);
50  int value = qsearch(state,
51  osl::Move::PASS(alt(state.turn())));
52 
53  const osl::stl::vector<WMove> moves = book.getMoves(stateIndex);
54  for (size_t i = 0; i < moves.size(); i++)
55  {
56  const int nextIndex = moves[i].getStateIndex();
57  osl::state::SimpleState newState = book.getBoard(nextIndex);
58  osl::Move move = moves[i].getMove();
59  int newValue = qsearch(newState, move);
60 
61  int diff = newValue - value;
62 
63  // the loss too big
64  if ((state.turn() == osl::BLACK && diff < -threshold)
65  || (state.turn() == osl::WHITE && diff > threshold))
66  std::cout << "----" << std::endl
67  << state << osl::record::csa::show(move) << std::endl;
68  // the gain too big
69  if ((state.turn() == osl::BLACK && diff > threshold)
70  || (state.turn() == osl::WHITE && diff < -threshold))
71  std::cout << "++++" << std::endl
72  << state << osl::record::csa::show(move) << std::endl;
73 
74  if (! states[nextIndex])
75  {
76  stateToVisit.push_back(nextIndex);
77  }
78  }
79  }
80 }