00001 //---------------------------------------------------------------------------- 00002 /** @file BenzenePlayer.hpp 00003 */ 00004 //---------------------------------------------------------------------------- 00005 00006 #ifndef BENZENEPLAYER_HPP 00007 #define BENZENEPLAYER_HPP 00008 00009 #include "HexBoard.hpp" 00010 #include "HexEval.hpp" 00011 #include "HexPlayer.hpp" 00012 #include "ICEngine.hpp" 00013 00014 _BEGIN_BENZENE_NAMESPACE_ 00015 00016 //---------------------------------------------------------------------------- 00017 00018 /** Abstract base class for all players using the Benzene systems. */ 00019 class BenzenePlayer: public HexPlayer 00020 { 00021 public: 00022 explicit BenzenePlayer(); 00023 00024 virtual ~BenzenePlayer(); 00025 00026 /** Generates a move from this board position. If the game is 00027 already over (somebody has won), returns RESIGN. 00028 00029 Derived Benzene players that use different search algorithms 00030 should not extend this method, but the protected virtual 00031 method Search() below. 00032 00033 If state is terminal (game over, vc/fill-in win/loss), 00034 returns "appropriate" move. Otherwise, calls Search(). 00035 */ 00036 HexPoint GenMove(const HexState& state, const Game& game, 00037 HexBoard& brd, double maxTime, double& score); 00038 00039 /** Search states with only a single move? */ 00040 bool SearchSingleton() const; 00041 00042 /** See SetSearchSingleton() */ 00043 void SetSearchSingleton(bool flag); 00044 00045 protected: 00046 bool m_fillinCausedWin; 00047 00048 HexColor m_fillinWinner; 00049 00050 bool FillinCausedWin() const; 00051 00052 /** Generates a move in the given gamestate. Derived players 00053 must implement this method. Score can be stored in score. 00054 @param state Position and color to play. 00055 @param game Game history up to this point. 00056 @param brd Board to use for work. 00057 @param consider Moves to consider in this state. 00058 @param maxTime Max time available for move. 00059 @param score Score of the move to play. 00060 @return The move to play. 00061 */ 00062 virtual HexPoint Search(const HexState& state, const Game& game, 00063 HexBoard& brd, const bitset_t& consider, 00064 double maxTime, double& score) = 0; 00065 00066 private: 00067 bool m_search_singleton; 00068 00069 HexPoint InitSearch(HexBoard& brd, HexColor color, 00070 bitset_t& consider, double& score); 00071 00072 HexPoint CheckEndgame(HexBoard& brd, HexColor color, 00073 bitset_t& consider, double& score); 00074 }; 00075 00076 inline bool BenzenePlayer::SearchSingleton() const 00077 { 00078 return m_search_singleton; 00079 } 00080 00081 inline void BenzenePlayer::SetSearchSingleton(bool flag) 00082 { 00083 m_search_singleton = flag; 00084 } 00085 00086 inline bool BenzenePlayer::FillinCausedWin() const 00087 { 00088 return m_fillinCausedWin; 00089 } 00090 00091 //---------------------------------------------------------------------------- 00092 00093 _END_BENZENE_NAMESPACE_ 00094 00095 #endif // BENZENEPLAYER_HPP