File: opening-validator.cc

package info (click to toggle)
libosl 0.8.0-4.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,328 kB
  • sloc: cpp: 114,345; ruby: 1,290; ansic: 915; makefile: 431; perl: 309; sh: 35
file content (79 lines) | stat: -rw-r--r-- 2,274 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "osl/book/openingBook.h"
#include "osl/csa.h"
#include "osl/search/quiescenceSearch2.h"
#include "osl/search/quiescenceSearch2.tcc"
#include "osl/eval/pieceEval.h"
#include <iostream>
#include <cstring>

using namespace osl::book;


static int qsearch(osl::SimpleState &s, osl::Move lastMove)
{
  typedef osl::search::QuiescenceSearch2<osl::eval::PieceEval> qsearch_t;

  osl::NumEffectState state(s);
  osl::search::SimpleHashTable table(100000, -16, false);
  osl::search::SearchState2Core::checkmate_t checkmate_searcher;
  osl::search::SearchState2Core core(state, checkmate_searcher);
  qsearch_t qs(core, table);
  osl::eval::PieceEval ev(state);
  return qs.search(state.turn(), ev, lastMove);
}

int main(int argc, char **argv)
{
  if (argc != 2)
  {
    std::cerr << "Usage: " << argv[0] << " FILENAME" << std::endl;
    return 1;
  }

  WeightedBook book(argv[1]);
  bool states[book.totalState()];

  memset(states, 0, sizeof(bool) * book.totalState());
  std::vector<int> stateToVisit;

  stateToVisit.push_back(book.startState());
  const int threshold = osl::eval::Ptype_Eval_Table.value(osl::SILVER);

  while (!stateToVisit.empty())
  {
    const int stateIndex = stateToVisit.back();
    stateToVisit.pop_back();
    states[stateIndex] = true;

    osl::SimpleState state = book.board(stateIndex);
    int value = qsearch(state,
			osl::Move::PASS(alt(state.turn())));

    const auto moves = book.moves(stateIndex);
    for (size_t i = 0; i < moves.size(); i++)
    {
      const int nextIndex = moves[i].stateIndex();
      osl::SimpleState newState = book.board(nextIndex);
      osl::Move move = moves[i].move;
      int newValue = qsearch(newState, move);

      int diff = newValue - value;

      // the loss too big
      if ((state.turn() == osl::BLACK && diff < -threshold)
	  || (state.turn() == osl::WHITE && diff > threshold))
	std::cout << "----" << std::endl
		  << state << osl::csa::show(move) << std::endl;
      // the gain too big
      if ((state.turn() == osl::BLACK && diff > threshold)
	  || (state.turn() == osl::WHITE && diff < -threshold))
	std::cout << "++++" << std::endl
		  << state << osl::csa::show(move) << std::endl;

      if (! states[nextIndex])
      {
	stateToVisit.push_back(nextIndex);
      }
    }
  }
}