Player using UCT to generate moves. More...
#include <MoHexPlayer.hpp>
Public Member Functions | |
MoHexPlayer () | |
Constructor. | |
virtual | ~MoHexPlayer () |
Destructor. | |
std::string | Name () const |
Returns "mohex". | |
HexUctSearch & | Search () |
Returns the search. | |
const HexUctSearch & | Search () const |
Returns the search. | |
HexUctSharedPolicy & | SharedPolicy () |
Returns the shared policy. | |
const HexUctSharedPolicy & | SharedPolicy () const |
Returns the shared policy. | |
void | CopySettingsFrom (const MoHexPlayer &other) |
Copy settings from other player. | |
HexPoint | GenMove (const HexState &state, const Game &game, HexBoard &brd, double maxTime, double &score) |
Generates a move from this board position. | |
bool | SearchSingleton () const |
Search states with only a single move? | |
void | SetSearchSingleton (bool flag) |
See SetSearchSingleton(). | |
Parameters | |
bool | BackupIceInfo () const |
void | SetBackupIceInfo (bool enable) |
int | MaxGames () const |
Max number of games to play. | |
void | SetMaxGames (int games) |
See MaxGames(). | |
double | MaxTime () const |
Maximum time to spend on search (in seconds). | |
void | SetMaxTime (double time) |
See MaxTime(). | |
bool | UseTimeManagement () const |
Use time control to determine how much time to use per move. | |
void | SetUseTimeManagement (bool flag) |
See UseTimeManagement(). | |
bool | ReuseSubtree () const |
Search is initialized using the subttree of the last search tree rooted at the current position. | |
void | SetReuseSubtree (bool reuse) |
See ReuseSubtree(). | |
bool | Ponder () const |
Searches while waiting for a command. | |
void | SetPonder (bool flag) |
See Ponder(). | |
bool | PerformPreSearch () const |
Searches 1ply for easy wins before the search. | |
void | SetPerformPreSearch (bool flag) |
See PerformPreSearch(). | |
Protected Member Functions | |
HexPoint | Search (const HexState &state, const Game &game, HexBoard &brd, const bitset_t &consider, double maxTime, double &score) |
Generates a move in the given gamestate using uct. | |
HexPoint | LastMoveFromHistory (const MoveSequence &history) |
Returns INVALID_POINT if history is empty, otherwise last move played to the board, ie, skips swap move. | |
bool | PerformPreSearch (HexBoard &brd, HexColor color, bitset_t &consider, float maxTime, PointSequence &winningSequence) |
Does a 1-ply search. | |
void | PrintParameters (HexColor color, double remaining) |
SgUctTree * | TryReuseSubtree (const HexUctSharedData &oldData, HexUctSharedData &newData) |
Extracts relevant portion of old tree for use in upcoming search. | |
void | CopyKnowledgeData (const SgUctTree &tree, const SgUctNode &node, HexColor color, MoveSequence &sequence, const HexUctSharedData &oldData, HexUctSharedData &newData) const |
bool | FillinCausedWin () const |
Protected Attributes | |
HexUctSharedPolicy | m_shared_policy |
HexUctSearch | m_search |
bool | m_backup_ice_info |
int | m_max_games |
See MaxGames(). | |
double | m_max_time |
See MaxTime(). | |
bool | m_useTimeManagement |
See UseTimeManagement(). | |
bool | m_reuse_subtree |
See ReuseSubtree(). | |
bool | m_ponder |
See Ponder(). | |
bool | m_performPreSearch |
bool | m_fillinCausedWin |
HexColor | m_fillinWinner |
Player using UCT to generate moves.
Definition at line 18 of file MoHexPlayer.hpp.
MoHexPlayer::MoHexPlayer | ( | ) |
Constructor.
Definition at line 59 of file MoHexPlayer.cpp.
MoHexPlayer::~MoHexPlayer | ( | ) | [virtual] |
Destructor.
Definition at line 74 of file MoHexPlayer.cpp.
bool MoHexPlayer::BackupIceInfo | ( | ) | const [inline] |
Definition at line 165 of file MoHexPlayer.hpp.
References m_backup_ice_info.
Referenced by CopySettingsFrom(), and MoHexEngine::MoHexParam().
void MoHexPlayer::CopyKnowledgeData | ( | const SgUctTree & | tree, | |
const SgUctNode & | node, | |||
HexColor | color, | |||
MoveSequence & | sequence, | |||
const HexUctSharedData & | oldData, | |||
HexUctSharedData & | newData | |||
) | const [protected] |
Definition at line 451 of file MoHexPlayer.cpp.
References HexUctSharedData::game_sequence, HashMap< T >::get(), SequenceHash::Hash(), hash_t, HashMap< T >::put(), and HexUctSharedData::stones.
Referenced by TryReuseSubtree().
void MoHexPlayer::CopySettingsFrom | ( | const MoHexPlayer & | other | ) |
Copy settings from other player.
Definition at line 78 of file MoHexPlayer.cpp.
References BackupIceInfo(), HexUctSearch::LiveGfx(), HexUctSearch::LiveGfxInterval(), MaxGames(), MaxTime(), PerformPreSearch(), HexUctSearch::PlayoutUpdateRadius(), Search(), SetBackupIceInfo(), HexUctSearch::SetLiveGfx(), HexUctSearch::SetLiveGfxInterval(), SetMaxGames(), SetMaxTime(), SetPerformPreSearch(), HexUctSearch::SetPlayoutUpdateRadius(), HexUctSearch::SetTreeUpdateRadius(), SetUseTimeManagement(), HexUctSearch::TreeUpdateRadius(), and UseTimeManagement().
bool BenzenePlayer::FillinCausedWin | ( | ) | const [inline, protected, inherited] |
Definition at line 86 of file BenzenePlayer.hpp.
References BenzenePlayer::m_fillinCausedWin.
Referenced by PerfectPlayer::Search().
HexPoint BenzenePlayer::GenMove | ( | const HexState & | state, | |
const Game & | game, | |||
HexBoard & | brd, | |||
double | maxTime, | |||
double & | score | |||
) | [virtual, inherited] |
Generates a move from this board position.
If the game is already over (somebody has won), returns RESIGN.
Derived Benzene players that use different search algorithms should not extend this method, but the protected virtual method Search() below.
If state is terminal (game over, vc/fill-in win/loss), returns "appropriate" move. Otherwise, calls Search().
Implements HexPlayer.
Definition at line 27 of file BenzenePlayer.cpp.
References BenzenePlayer::CheckEndgame(), BenzenePlayer::InitSearch(), INVALID_POINT, LogInfo(), BenzenePlayer::Search(), and HexState::ToPlay().
Referenced by MoHexEngine::DoSearch(), WolveEngine::GenMove(), PlayAndSolve::PlayerThread::operator()(), and BookBuilder< PLAYER >::Worker::operator()().
HexPoint MoHexPlayer::LastMoveFromHistory | ( | const MoveSequence & | history | ) | [protected] |
Returns INVALID_POINT if history is empty, otherwise last move played to the board, ie, skips swap move.
Definition at line 210 of file MoHexPlayer.cpp.
References HexAssert, INVALID_POINT, and SWAP_PIECES.
Referenced by Search().
int MoHexPlayer::MaxGames | ( | ) | const [inline] |
Max number of games to play.
Definition at line 175 of file MoHexPlayer.hpp.
References m_max_games.
Referenced by CopySettingsFrom(), and MoHexEngine::MoHexParam().
double MoHexPlayer::MaxTime | ( | ) | const [inline] |
Maximum time to spend on search (in seconds).
Definition at line 185 of file MoHexPlayer.hpp.
References m_max_time.
Referenced by CopySettingsFrom(), MoHexEngine::MoHexParam(), and MoHexEngine::TimeForMove().
std::string MoHexPlayer::Name | ( | ) | const [inline, virtual] |
bool MoHexPlayer::PerformPreSearch | ( | HexBoard & | brd, | |
HexColor | color, | |||
bitset_t & | consider, | |||
float | maxTime, | |||
PointSequence & | winningSequence | |||
) | [protected] |
Does a 1-ply search.
For each move in the consider set, if the move is a win, returns true and the move. If the move is a loss, prune it out of the consider set if there are non-losing moves in the consider set. If all moves are losing, perform no pruning, search will resist.
Returns true if there is a win, false otherwise.
Definition at line 237 of file MoHexPlayer.cpp.
References benzene_bitset< _Nb >::any(), benzene_bitset< _Nb >::count(), Resistance::Evaluate(), HexAssert, EndgameUtils::IsDeterminedState(), EndgameUtils::IsLostGame(), BitsetUtil::IsSubsetOf(), EndgameUtils::IsWonGame(), LogFine(), LogInfo(), m_backup_ice_info, EndgameUtils::MovesToConsider(), HexBoard::PlayMove(), benzene_bitset< _Nb >::set(), HexBoard::UndoMove(), and HexBoard::Write().
bool MoHexPlayer::PerformPreSearch | ( | ) | const [inline] |
Searches 1ply for easy wins before the search.
Definition at line 225 of file MoHexPlayer.hpp.
References m_performPreSearch.
Referenced by CopySettingsFrom(), MoHexEngine::MoHexParam(), and Search().
bool MoHexPlayer::Ponder | ( | ) | const [inline] |
Searches while waiting for a command.
Definition at line 215 of file MoHexPlayer.hpp.
References m_ponder.
Referenced by MoHexEngine::MoHexParam().
void MoHexPlayer::PrintParameters | ( | HexColor | color, | |
double | remaining | |||
) | [protected] |
Definition at line 314 of file MoHexPlayer.cpp.
References LogInfo(), m_max_games, and m_search.
Referenced by Search().
bool MoHexPlayer::ReuseSubtree | ( | ) | const [inline] |
Search is initialized using the subttree of the last search tree rooted at the current position.
Definition at line 205 of file MoHexPlayer.hpp.
References m_reuse_subtree.
Referenced by MoHexEngine::MoHexParam().
HexPoint MoHexPlayer::Search | ( | const HexState & | state, | |
const Game & | game, | |||
HexBoard & | brd, | |||
const bitset_t & | consider, | |||
double | maxTime, | |||
double & | score | |||
) | [protected, virtual] |
Generates a move in the given gamestate using uct.
Implements BenzenePlayer.
Definition at line 105 of file MoHexPlayer.cpp.
References HexUctSharedData::board_height, HexUctSharedData::board_width, PatternState::ClearPatternCheckStats(), Time::Formatted(), HexUctSharedData::game_sequence, HexBoard::GetGroups(), HexBoard::GetPatternState(), HexBoard::GetPosition(), HexBoard::Height(), HexAssert, Game::History(), IMMEDIATE_WIN, Groups::IsGameOver(), LastMoveFromHistory(), LogInfo(), LogWarning(), m_max_games, m_performPreSearch, m_reuse_subtree, m_search, m_shared_policy, HexUctUtil::MoveString(), PerformPreSearch(), PrintParameters(), BoardUtils::RandomEmptyCell(), HexUctSharedData::root_consider, HexUctSharedData::root_last_move_played, HexUctSharedData::root_stones, HexUctSharedData::root_to_play, HexUctSearch::SetBoard(), HexUctSearch::SetSharedData(), PatternState::SetUpdateRadius(), HexUctSearch::SharedData(), HexState::ToPlay(), HexUctSearch::TreeUpdateRadius(), TryReuseSubtree(), PatternState::UpdateRadius(), and HexBoard::Width().
const HexUctSearch & MoHexPlayer::Search | ( | ) | const [inline] |
HexUctSearch & MoHexPlayer::Search | ( | ) | [inline] |
Returns the search.
Definition at line 145 of file MoHexPlayer.hpp.
References m_search.
Referenced by MoHexEngine::Bounds(), CopySettingsFrom(), MoHexEngine::MoHexParam(), MoHexEngine::RaveValues(), MoHexEngine::SaveGames(), MoHexEngine::SaveTree(), and MoHexEngine::Values().
bool BenzenePlayer::SearchSingleton | ( | ) | const [inline, inherited] |
Search states with only a single move?
Definition at line 76 of file BenzenePlayer.hpp.
References BenzenePlayer::m_search_singleton.
Referenced by MoHexEngine::MoHexParam(), and WolveEngine::WolveParam().
void MoHexPlayer::SetBackupIceInfo | ( | bool | enable | ) | [inline] |
Definition at line 170 of file MoHexPlayer.hpp.
References m_backup_ice_info.
Referenced by CopySettingsFrom(), and MoHexEngine::MoHexParam().
void MoHexPlayer::SetMaxGames | ( | int | games | ) | [inline] |
See MaxGames().
Definition at line 180 of file MoHexPlayer.hpp.
References m_max_games.
Referenced by CopySettingsFrom(), and MoHexEngine::MoHexParam().
void MoHexPlayer::SetMaxTime | ( | double | time | ) | [inline] |
See MaxTime().
Definition at line 190 of file MoHexPlayer.hpp.
References m_max_time.
Referenced by CopySettingsFrom(), and MoHexEngine::MoHexParam().
void MoHexPlayer::SetPerformPreSearch | ( | bool | flag | ) | [inline] |
See PerformPreSearch().
Definition at line 230 of file MoHexPlayer.hpp.
References m_performPreSearch.
Referenced by CopySettingsFrom(), and MoHexEngine::MoHexParam().
void MoHexPlayer::SetPonder | ( | bool | flag | ) | [inline] |
See Ponder().
Definition at line 220 of file MoHexPlayer.hpp.
References m_ponder.
Referenced by MoHexEngine::MoHexParam().
void MoHexPlayer::SetReuseSubtree | ( | bool | reuse | ) | [inline] |
See ReuseSubtree().
Definition at line 210 of file MoHexPlayer.hpp.
References m_reuse_subtree.
Referenced by MoHexEngine::MoHexParam().
void BenzenePlayer::SetSearchSingleton | ( | bool | flag | ) | [inline, inherited] |
See SetSearchSingleton().
Definition at line 81 of file BenzenePlayer.hpp.
References BenzenePlayer::m_search_singleton.
Referenced by MoHexEngine::MoHexParam(), and WolveEngine::WolveParam().
void MoHexPlayer::SetUseTimeManagement | ( | bool | flag | ) | [inline] |
See UseTimeManagement().
Definition at line 200 of file MoHexPlayer.hpp.
References m_useTimeManagement.
Referenced by CopySettingsFrom(), and MoHexEngine::MoHexParam().
const HexUctSharedPolicy & MoHexPlayer::SharedPolicy | ( | ) | const [inline] |
Returns the shared policy.
Definition at line 160 of file MoHexPlayer.hpp.
References m_shared_policy.
HexUctSharedPolicy & MoHexPlayer::SharedPolicy | ( | ) | [inline] |
Returns the shared policy.
Definition at line 155 of file MoHexPlayer.hpp.
References m_shared_policy.
Referenced by MoHexEngine::MoHexPolicyParam().
SgUctTree * MoHexPlayer::TryReuseSubtree | ( | const HexUctSharedData & | oldData, | |
HexUctSharedData & | newData | |||
) | [protected] |
Extracts relevant portion of old tree for use in upcoming search.
Returns valid pointer to new tree on success, 0 on failure.
Definition at line 327 of file MoHexPlayer.cpp.
References HexUctStoneData::black, BLACK, HexUctSharedData::board_height, HexUctSharedData::board_width, CopyKnowledgeData(), HashMap< T >::count(), HexUctSharedData::game_sequence, HashMap< T >::get(), SequenceHash::Hash(), hash_t, HexAssert, LogInfo(), LogWarning(), m_search, HexUctStoneData::played, HexUctSharedData::root_consider, HexUctSharedData::root_stones, HexUctSharedData::root_to_play, StoneBoard::SetColor(), StoneBoard::SetPlayed(), StoneBoard::StartNewGame(), HexUctSharedData::stones, HexUctStoneData::white, and WHITE.
Referenced by Search().
bool MoHexPlayer::UseTimeManagement | ( | ) | const [inline] |
Use time control to determine how much time to use per move.
Definition at line 195 of file MoHexPlayer.hpp.
References m_useTimeManagement.
Referenced by CopySettingsFrom(), MoHexEngine::MoHexParam(), and MoHexEngine::TimeForMove().
bool MoHexPlayer::m_backup_ice_info [protected] |
Definition at line 100 of file MoHexPlayer.hpp.
Referenced by BackupIceInfo(), PerformPreSearch(), and SetBackupIceInfo().
bool BenzenePlayer::m_fillinCausedWin [protected, inherited] |
Definition at line 46 of file BenzenePlayer.hpp.
Referenced by BenzenePlayer::FillinCausedWin(), and BenzenePlayer::InitSearch().
HexColor BenzenePlayer::m_fillinWinner [protected, inherited] |
Definition at line 48 of file BenzenePlayer.hpp.
Referenced by BenzenePlayer::InitSearch(), and PerfectPlayer::Search().
int MoHexPlayer::m_max_games [protected] |
See MaxGames().
Definition at line 103 of file MoHexPlayer.hpp.
Referenced by MaxGames(), PrintParameters(), Search(), and SetMaxGames().
double MoHexPlayer::m_max_time [protected] |
See MaxTime().
Definition at line 106 of file MoHexPlayer.hpp.
Referenced by MaxTime(), and SetMaxTime().
bool MoHexPlayer::m_performPreSearch [protected] |
Definition at line 117 of file MoHexPlayer.hpp.
Referenced by PerformPreSearch(), Search(), and SetPerformPreSearch().
bool MoHexPlayer::m_ponder [protected] |
See Ponder().
Definition at line 115 of file MoHexPlayer.hpp.
Referenced by Ponder(), and SetPonder().
bool MoHexPlayer::m_reuse_subtree [protected] |
See ReuseSubtree().
Definition at line 112 of file MoHexPlayer.hpp.
Referenced by ReuseSubtree(), Search(), and SetReuseSubtree().
HexUctSearch MoHexPlayer::m_search [protected] |
Definition at line 98 of file MoHexPlayer.hpp.
Referenced by PrintParameters(), Search(), and TryReuseSubtree().
HexUctSharedPolicy MoHexPlayer::m_shared_policy [protected] |
Definition at line 96 of file MoHexPlayer.hpp.
Referenced by Search(), and SharedPolicy().
bool MoHexPlayer::m_useTimeManagement [protected] |
See UseTimeManagement().
Definition at line 109 of file MoHexPlayer.hpp.
Referenced by SetUseTimeManagement(), and UseTimeManagement().