00001 //---------------------------------------------------------------------------- 00002 /** @file GoPlayer.h 00003 Player. 00004 */ 00005 //---------------------------------------------------------------------------- 00006 00007 #ifndef GO_PLAYER_H 00008 #define GO_PLAYER_H 00009 00010 #include <string> 00011 #include "GoBoard.h" 00012 #include "GoBoardSynchronizer.h" 00013 #include "GoPlayerMove.h" 00014 #include "SgBoardColor.h" 00015 #include "SgPoint.h" 00016 00017 class SgNode; 00018 class SgTimeRecord; 00019 00020 //---------------------------------------------------------------------------- 00021 00022 /** Player. */ 00023 class GoPlayer 00024 : public GoBoardSynchronizer 00025 { 00026 public: 00027 /** Constructor. 00028 */ 00029 GoPlayer(const GoBoard& bd); 00030 00031 virtual ~GoPlayer(); 00032 00033 /** See m_board */ 00034 GoBoard& Board(); 00035 00036 /** See m_board */ 00037 const GoBoard& Board() const; 00038 00039 /** Generate a move. */ 00040 virtual SgPoint GenMove(const SgTimeRecord& time, 00041 SgBlackWhite toPlay) = 0; 00042 00043 /** Get the name of this player. 00044 Default implementation returns "Unknown" 00045 */ 00046 virtual std::string Name() const; 00047 00048 /** Get node for appending search traces */ 00049 SgNode* CurrentNode() const; 00050 00051 /** Set node for appending search traces */ 00052 void SetCurrentNode(SgNode* node); 00053 00054 /** Return value for a move. 00055 Not all players assign values to moves. 00056 If a player cannot score moves in general, or cannot score this move 00057 in particular, it should return numeric_limits<int>::min() 00058 (which is what the default implementation does). 00059 Values can be positive or negative; better moves should have higher 00060 values; the units of the values are not specified. 00061 */ 00062 virtual int MoveValue(SgPoint p); 00063 00064 /** Inform the player that the game was finished. 00065 This function gives the player the opportunity to do some work at 00066 the end of a game, for example perform some learning. 00067 However it is not guaranteed that this function will be called at 00068 all, the player should not rely on it. The reason is that a game 00069 start and end is not always well-defined (setup, undo, etc.) 00070 For example, it will be called in the GTP interface if after a change 00071 on the board GoBoardUtil::EndOfGame() is true. 00072 The default implementation does nothing. 00073 */ 00074 virtual void OnGameFinished(); 00075 00076 /** Inform the player that a new game was started. 00077 This function gives the player the opportunity to clear some cached 00078 data, that is useful only within the same game. 00079 However it is not guaranteed that this function will be called at 00080 all, the player should not rely on it. The reason is that a game 00081 start and end is not always well-defined (setup, undo, etc.) 00082 For example, it will be called in the GTP interface in 00083 GoGtpEngine::Init(), or on the clear_board and loadsgf commands. 00084 The default implementation does nothing. 00085 */ 00086 virtual void OnNewGame(); 00087 00088 /** Think during opponent's time. 00089 This function should poll SgUserAbort() and return immediately if 00090 it returns true. 00091 It is good style to enable pondering in the player with a parameter 00092 and return immediately if it is not enabled. If it is enabled, it 00093 should stop after some resource limit is reached to avoid that a 00094 program is hogging the CPU if it is just waiting for commands. 00095 The function Ponder() is typically called from a different thread but 00096 without overlap with other uses of the player, so the player does not 00097 have to care about thread-safety. 00098 Default implementation does nothing and returns immediately. 00099 */ 00100 virtual void Ponder(); 00101 00102 /** See m_variant */ 00103 int Variant() const; 00104 00105 /** See m_variant */ 00106 void SetVariant(int variant); 00107 00108 protected: 00109 /** Node in game tree. Used for appending search traces */ 00110 SgNode* m_currentNode; 00111 00112 private: 00113 /** The player's own Go board */ 00114 GoBoard m_bd; 00115 00116 /** Player variant. Used for short-term testing of small modifications. 00117 The default variant is 0. 00118 Do not use to create significantly different players - 00119 implement a new player instead. 00120 */ 00121 int m_variant; 00122 00123 /** Not implemented */ 00124 GoPlayer(const GoPlayer&); 00125 00126 /** Not implemented */ 00127 GoPlayer& operator=(const GoPlayer&); 00128 }; 00129 00130 inline GoBoard& GoPlayer::Board() 00131 { 00132 return m_bd; 00133 } 00134 00135 inline const GoBoard& GoPlayer::Board() const 00136 { 00137 return m_bd; 00138 } 00139 00140 inline SgNode* GoPlayer::CurrentNode() const 00141 { 00142 return m_currentNode; 00143 } 00144 00145 inline void GoPlayer::SetCurrentNode(SgNode* node) 00146 { 00147 m_currentNode = node; 00148 } 00149 00150 inline int GoPlayer::Variant() const 00151 { 00152 return m_variant; 00153 } 00154 00155 inline void GoPlayer::SetVariant(int variant) 00156 { 00157 m_variant = variant; 00158 } 00159 00160 //---------------------------------------------------------------------------- 00161 00162 #endif // GO_PLAYER_H 00163