00001 #include "osl/record/opening/openingBook.h"
00002 #include "osl/record/csa.h"
00003 #include "osl/search/quiescenceSearch.h"
00004 #include "osl/search/quiescenceSearch.tcc"
00005 #include "osl/eval/pieceEval.h"
00006 #include "osl/stl/vector.h"
00007 #include <iostream>
00008 #include <cstring>
00009
00010 using namespace osl::record::opening;
00011
00012
00013 static int qsearch(osl::state::SimpleState &s, osl::Move lastMove)
00014 {
00015 typedef osl::search::QuiescenceSearch<osl::eval::PieceEval> qsearch_t;
00016
00017 osl::state::HashEffectState state(s);
00018 osl::search::SimpleHashTable table(100000, -16, false);
00019 osl::search::SearchStateCore::checkmate_t checkmate_searcher;
00020 osl::search::SearchStateCore core(state, checkmate_searcher);
00021 qsearch_t qs(core, table);
00022 osl::eval::PieceEval ev(state);
00023 return qs.search(state.getTurn(), ev, lastMove);
00024 }
00025
00026 int main(int argc, char **argv)
00027 {
00028 if (argc != 2)
00029 {
00030 std::cerr << "Usage: " << argv[0] << " FILENAME" << std::endl;
00031 return 1;
00032 }
00033
00034 WeightedBook book(argv[1]);
00035 bool states[book.getTotalState()];
00036
00037 memset(states, 0, sizeof(bool) * book.getTotalState());
00038 osl::stl::vector<int> stateToVisit;
00039
00040 stateToVisit.push_back(book.getStartState());
00041 const int threshold = osl::eval::Ptype_Eval_Table.value(osl::SILVER);
00042
00043 while (!stateToVisit.empty())
00044 {
00045 const int stateIndex = stateToVisit.back();
00046 stateToVisit.pop_back();
00047 states[stateIndex] = true;
00048
00049 osl::state::SimpleState state = book.getBoard(stateIndex);
00050 int value = qsearch(state,
00051 osl::Move::PASS(alt(state.getTurn())));
00052
00053 const osl::stl::vector<WMove> moves = book.getMoves(stateIndex);
00054 for (size_t i = 0; i < moves.size(); i++)
00055 {
00056 const int nextIndex = moves[i].getStateIndex();
00057 osl::state::SimpleState newState = book.getBoard(nextIndex);
00058 osl::Move move = moves[i].getMove();
00059 int newValue = qsearch(newState, move);
00060
00061 int diff = newValue - value;
00062
00063
00064 if ((state.getTurn() == osl::BLACK && diff < -threshold)
00065 || (state.getTurn() == osl::WHITE && diff > threshold))
00066 std::cout << "----" << std::endl
00067 << state << osl::record::csa::show(move) << std::endl;
00068
00069 if ((state.getTurn() == osl::BLACK && diff > threshold)
00070 || (state.getTurn() == osl::WHITE && diff < -threshold))
00071 std::cout << "++++" << std::endl
00072 << state << osl::record::csa::show(move) << std::endl;
00073
00074 if (! states[nextIndex])
00075 {
00076 stateToVisit.push_back(nextIndex);
00077 }
00078 }
00079 }
00080 }