All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bookPlayer.cc
Go to the documentation of this file.
1 /* bookPlayer.cc
2  */
8 #include <iostream>
9 #include <stdexcept>
10 
14  : book(b), searcher(s), book_limit(-1), current_moves(0), valid_initial_position(true)
15 {
16 }
17 
20 {
21 }
22 
25 {
26  return new BookPlayer(book->clone(), searcher->clone());
27 }
28 
31 {
32  book_limit = new_limit;
33 }
34 
36 BookPlayer::setInitialState(const NumEffectState& state)
37 {
38  SimpleState usual(HIRATE);
39  valid_initial_position = (record::CompactBoard(state) == record::CompactBoard(usual));
40  if (book->isVerbose() && !valid_initial_position)
41  std::cerr << "book: end" << "\n";
42 }
43 
46 {
47  ++current_moves;
48  if (valid_initial_position)
49  book->update(m);
50  searcher->pushMove(m);
51 }
54 {
55  --current_moves;
56  if (valid_initial_position)
57  book->popMove();
58  searcher->popMove();
59 }
60 
63 {
64  return valid_initial_position
65  && (! book->isOutOfBook())
66  && (book_limit < 0 || current_moves < book_limit);
67 }
68 
71 {
72  if (bookAvailable())
73  {
74  const Move best_move = book->selectMove();
75  if (best_move.isNormal()
76  && (! state.isIllegal(best_move)))
77  return best_move;
78  }
79  return Move::INVALID();
80 }
81 
83 BookPlayer::selectBestMove(const GameState& state, int limit, int elapsed, int byoyomi)
84 {
85  const Move move = moveByBook(state);
86  if (move.isNormal())
87  return MoveWithComment(move);
88  return searcher->selectBestMove(state, limit, elapsed, byoyomi);
89 }
90 
93 {
94  const Move move = moveByBook(state);
95  if (move.isNormal())
96  return MoveWithComment(move);
98  = dynamic_cast<ComputerPlayerSelectBestMoveInTime *>(searcher.get()))
99  return p->selectBestMoveInTime(state, msec);
100  throw std::runtime_error("type error in BookPlayer::selectBestMoveInTime");
101 }
102 
105 {
107  searcher->allowSpeculativeSearch(value);
108 }
109 
112 {
113  ComputerPlayer::setRootIgnoreMoves(rim, prediction);
114  searcher->setRootIgnoreMoves(rim, prediction);
115 }
116 
119 {
120  return searcher->stopSearchNow();
121 }
122 
123 /* ------------------------------------------------------------------------- */
124 // ;;; Local Variables:
125 // ;;; mode:c++
126 // ;;; c-basic-offset:2
127 // ;;; End: