00001 /* bookPlayer.cc 00002 */ 00003 #include "osl/game_playing/bookPlayer.h" 00004 #include "osl/game_playing/gameState.h" 00005 #include "osl/game_playing/openingBookTracer.h" 00006 #include "osl/container/moveStack.h" 00007 00008 osl::game_playing:: 00009 BookPlayer:: 00010 BookPlayer(OpeningBookTracer *b, ComputerPlayer *s) 00011 : book(b), searcher(s), book_limit(-1), current_moves(0) 00012 { 00013 } 00014 00015 osl::game_playing:: 00016 BookPlayer::~BookPlayer() 00017 { 00018 } 00019 00020 osl::game_playing::ComputerPlayer* osl::game_playing:: 00021 BookPlayer::clone() const 00022 { 00023 return new BookPlayer(book->clone(), searcher->clone()); 00024 } 00025 00026 void osl::game_playing:: 00027 BookPlayer::setBookLimit(int new_limit) 00028 { 00029 book_limit = new_limit; 00030 } 00031 00032 void osl::game_playing:: 00033 BookPlayer::pushMove(Move m) 00034 { 00035 ++current_moves; 00036 book->update(m); 00037 searcher->pushMove(m); 00038 } 00039 void osl::game_playing:: 00040 BookPlayer::popMove() 00041 { 00042 --current_moves; 00043 book->popMove(); 00044 searcher->popMove(); 00045 } 00046 00047 bool osl::game_playing:: 00048 BookPlayer::bookAvailable() const 00049 { 00050 return (! book->isOutOfBook()) 00051 && (book_limit < 0 || current_moves < book_limit); 00052 } 00053 00054 const osl::game_playing::MoveWithComment osl::game_playing:: 00055 BookPlayer::selectBestMove(const GameState& state, int seconds, int byoyomi) 00056 { 00057 if (bookAvailable()) 00058 { 00059 const Move best_move = book->selectMove(); 00060 if (best_move.isNormal() 00061 && (! state.isIllegal(best_move))) 00062 { 00063 return MoveWithComment(best_move); 00064 } 00065 } 00066 return searcher->selectBestMove(state, seconds, byoyomi); 00067 } 00068 00069 void osl::game_playing:: 00070 BookPlayer::allowSpeculativeSearch(bool value) 00071 { 00072 ComputerPlayer::allowSpeculativeSearch(value); 00073 searcher->allowSpeculativeSearch(value); 00074 } 00075 00076 /* ------------------------------------------------------------------------- */ 00077 // ;;; Local Variables: 00078 // ;;; mode:c++ 00079 // ;;; c-basic-offset:2 00080 // ;;; End: