00001 //---------------------------------------------------------------------------- 00002 /** @file EndgameUtils.hpp 00003 */ 00004 //---------------------------------------------------------------------------- 00005 00006 #ifndef ENDGAMEUTILS_HPP 00007 #define ENDGAMEUTILS_HPP 00008 00009 #include "Hex.hpp" 00010 #include "HexBoard.hpp" 00011 #include "HexEval.hpp" 00012 00013 _BEGIN_BENZENE_NAMESPACE_ 00014 00015 //---------------------------------------------------------------------------- 00016 00017 /** Utilities on endgames: detecting, playing, etc. */ 00018 namespace EndgameUtils 00019 { 00020 00021 /** Returns true if color wins in this state. This checks 00022 for solid chains and for winning scs/vcs. */ 00023 bool IsWonGame(const HexBoard& brd, HexColor color, bitset_t& proof); 00024 00025 bool IsWonGame(const HexBoard& brd, HexColor color); 00026 00027 /** Returns true if color loses in this state. This checks for 00028 solid chains and for winning scs/vcs. */ 00029 bool IsLostGame(const HexBoard& brd, HexColor color, bitset_t& proof); 00030 00031 bool IsLostGame(const HexBoard& brd, HexColor color); 00032 00033 /** Returns true if this is a winning/losing state for color (as 00034 defined by IsWonGame() and IsLostGame()), score is set to 00035 IMMEDIATE_WIN on win, IMMEDIATE_LOSS on a loss, or 0 00036 otherwise. */ 00037 bool IsDeterminedState(const HexBoard& brd, HexColor color, 00038 HexEval& score, bitset_t& proof); 00039 00040 bool IsDeterminedState(const HexBoard& brd, HexColor color, 00041 HexEval& score); 00042 00043 bool IsDeterminedState(const HexBoard& brd, HexColor color); 00044 00045 /** Plays the "best" move in a determined state. Assumes 00046 IsDetermined() returns true, but requires that 00047 brd.isGameOver() is false. That is, is, it cannot play a move 00048 if a solid chain exists on this board. 00049 00050 @see @ref playingdeterminedstates 00051 */ 00052 HexPoint PlayDeterminedState(const HexBoard& brd, HexColor color); 00053 00054 /** Returns the set of moves that need to be considered from the 00055 given boardstate; that is, without the moves that we can 00056 provably ignore. Returned set of moves to consider is 00057 guaranteed to be non-empty. This assumes IsDeterminedState() 00058 returns false. 00059 00060 @todo MOVE THIS OUT OF HERE! 00061 00062 @see @ref computingmovestoconsider 00063 */ 00064 bitset_t MovesToConsider(const HexBoard& brd, HexColor color); 00065 } 00066 00067 //---------------------------------------------------------------------------- 00068 00069 inline bool EndgameUtils::IsDeterminedState(const HexBoard& brd, 00070 HexColor color, HexEval& eval) 00071 00072 { 00073 bitset_t proof; 00074 return IsDeterminedState(brd, color, eval, proof); 00075 } 00076 00077 inline bool EndgameUtils::IsDeterminedState(const HexBoard& brd, HexColor color) 00078 { 00079 HexEval eval; 00080 bitset_t proof; 00081 return IsDeterminedState(brd, color, eval, proof); 00082 } 00083 00084 inline bool EndgameUtils::IsLostGame(const HexBoard& brd, HexColor color) 00085 { 00086 bitset_t proof; 00087 return IsLostGame(brd, color, proof); 00088 } 00089 00090 inline bool EndgameUtils::IsWonGame(const HexBoard& brd, HexColor color) 00091 { 00092 bitset_t proof; 00093 return IsWonGame(brd, color, proof); 00094 } 00095 00096 //---------------------------------------------------------------------------- 00097 00098 _END_BENZENE_NAMESPACE_ 00099 00100 #endif // ENDGAMEUTILS_HPP