00001 //---------------------------------------------------------------------------- 00002 /** @file MoHexPlayer.hpp 00003 */ 00004 //---------------------------------------------------------------------------- 00005 00006 #ifndef MOHEXPLAYER_HPP 00007 #define MOHEXPLAYER_HPP 00008 00009 #include "BenzenePlayer.hpp" 00010 #include "HexUctSearch.hpp" 00011 #include "HexUctPolicy.hpp" 00012 00013 _BEGIN_BENZENE_NAMESPACE_ 00014 00015 //---------------------------------------------------------------------------- 00016 00017 /** Player using UCT to generate moves. */ 00018 class MoHexPlayer : public BenzenePlayer 00019 { 00020 public: 00021 00022 /** Constructor. */ 00023 MoHexPlayer(); 00024 00025 /** Destructor. */ 00026 virtual ~MoHexPlayer(); 00027 00028 /** Returns "mohex". */ 00029 std::string Name() const; 00030 00031 /** Returns the search. */ 00032 HexUctSearch& Search(); 00033 00034 /** Returns the search. */ 00035 const HexUctSearch& Search() const; 00036 00037 /** Returns the shared policy. */ 00038 HexUctSharedPolicy& SharedPolicy(); 00039 00040 /** Returns the shared policy. */ 00041 const HexUctSharedPolicy& SharedPolicy() const; 00042 00043 /** Copy settings from other player. */ 00044 void CopySettingsFrom(const MoHexPlayer& other); 00045 00046 //----------------------------------------------------------------------- 00047 00048 /** @name Parameters */ 00049 // @{ 00050 00051 bool BackupIceInfo() const; 00052 00053 void SetBackupIceInfo(bool enable); 00054 00055 /** Max number of games to play. */ 00056 int MaxGames() const; 00057 00058 /** See MaxGames() */ 00059 void SetMaxGames(int games); 00060 00061 /** Maximum time to spend on search (in seconds). */ 00062 double MaxTime() const; 00063 00064 /** See MaxTime() */ 00065 void SetMaxTime(double time); 00066 00067 /** Use time control to determine how much time to use per move. */ 00068 bool UseTimeManagement() const; 00069 00070 /** See UseTimeManagement() */ 00071 void SetUseTimeManagement(bool flag); 00072 00073 /** Search is initialized using the subttree of the last search 00074 tree rooted at the current position. */ 00075 bool ReuseSubtree() const; 00076 00077 /** See ReuseSubtree() */ 00078 void SetReuseSubtree(bool reuse); 00079 00080 /** Searches while waiting for a command. */ 00081 bool Ponder() const; 00082 00083 /** See Ponder() */ 00084 void SetPonder(bool flag); 00085 00086 /** Searches 1ply for easy wins before the search. */ 00087 bool PerformPreSearch() const; 00088 00089 /** See PerformPreSearch() */ 00090 void SetPerformPreSearch(bool flag); 00091 00092 // @} 00093 00094 protected: 00095 00096 HexUctSharedPolicy m_shared_policy; 00097 00098 HexUctSearch m_search; 00099 00100 bool m_backup_ice_info; 00101 00102 /** See MaxGames() */ 00103 int m_max_games; 00104 00105 /** See MaxTime() */ 00106 double m_max_time; 00107 00108 /** See UseTimeManagement() */ 00109 bool m_useTimeManagement; 00110 00111 /** See ReuseSubtree() */ 00112 bool m_reuse_subtree; 00113 00114 /** See Ponder() */ 00115 bool m_ponder; 00116 00117 bool m_performPreSearch; 00118 00119 /** Generates a move in the given gamestate using uct. */ 00120 HexPoint Search(const HexState& state, const Game& game, 00121 HexBoard& brd, const bitset_t& consider, 00122 double maxTime, double& score); 00123 00124 HexPoint LastMoveFromHistory(const MoveSequence& history); 00125 00126 bool PerformPreSearch(HexBoard& brd, HexColor color, bitset_t& consider, 00127 float maxTime, PointSequence& winningSequence); 00128 00129 void PrintParameters(HexColor color, double remaining); 00130 00131 SgUctTree* TryReuseSubtree(const HexUctSharedData& oldData, 00132 HexUctSharedData& newData); 00133 00134 void CopyKnowledgeData(const SgUctTree& tree, const SgUctNode& node, 00135 HexColor color, MoveSequence& sequence, 00136 const HexUctSharedData& oldData, 00137 HexUctSharedData& newData) const; 00138 }; 00139 00140 inline std::string MoHexPlayer::Name() const 00141 { 00142 return "mohex"; 00143 } 00144 00145 inline HexUctSearch& MoHexPlayer::Search() 00146 { 00147 return m_search; 00148 } 00149 00150 inline const HexUctSearch& MoHexPlayer::Search() const 00151 { 00152 return m_search; 00153 } 00154 00155 inline HexUctSharedPolicy& MoHexPlayer::SharedPolicy() 00156 { 00157 return m_shared_policy; 00158 } 00159 00160 inline const HexUctSharedPolicy& MoHexPlayer::SharedPolicy() const 00161 { 00162 return m_shared_policy; 00163 } 00164 00165 inline bool MoHexPlayer::BackupIceInfo() const 00166 { 00167 return m_backup_ice_info; 00168 } 00169 00170 inline void MoHexPlayer::SetBackupIceInfo(bool enable) 00171 { 00172 m_backup_ice_info = enable; 00173 } 00174 00175 inline int MoHexPlayer::MaxGames() const 00176 { 00177 return m_max_games; 00178 } 00179 00180 inline void MoHexPlayer::SetMaxGames(int games) 00181 { 00182 m_max_games = games; 00183 } 00184 00185 inline double MoHexPlayer::MaxTime() const 00186 { 00187 return m_max_time; 00188 } 00189 00190 inline void MoHexPlayer::SetMaxTime(double time) 00191 { 00192 m_max_time = time; 00193 } 00194 00195 inline bool MoHexPlayer::UseTimeManagement() const 00196 { 00197 return m_useTimeManagement; 00198 } 00199 00200 inline void MoHexPlayer::SetUseTimeManagement(bool flag) 00201 { 00202 m_useTimeManagement = flag; 00203 } 00204 00205 inline bool MoHexPlayer::ReuseSubtree() const 00206 { 00207 return m_reuse_subtree; 00208 } 00209 00210 inline void MoHexPlayer::SetReuseSubtree(bool reuse) 00211 { 00212 m_reuse_subtree = reuse; 00213 } 00214 00215 inline bool MoHexPlayer::Ponder() const 00216 { 00217 return m_ponder; 00218 } 00219 00220 inline void MoHexPlayer::SetPonder(bool flag) 00221 { 00222 m_ponder = flag; 00223 } 00224 00225 inline bool MoHexPlayer::PerformPreSearch() const 00226 { 00227 return m_performPreSearch; 00228 } 00229 00230 inline void MoHexPlayer::SetPerformPreSearch(bool flag) 00231 { 00232 m_performPreSearch = flag; 00233 } 00234 00235 //---------------------------------------------------------------------------- 00236 00237 _END_BENZENE_NAMESPACE_ 00238 00239 #endif // MOHEXPLAYER_HPP