Base Alpha-Beta search class. More...
#include <HexAbSearch.hpp>
Classes | |
| struct | Statistics |
| Search statistics. More... | |
Public Member Functions | |
| HexAbSearch () | |
| Constructor. | |
| virtual | ~HexAbSearch () |
| Destructor. | |
| void | SetTT (SearchTT *tt) |
| Sets the transposition table to be used during search. | |
| bool | GuiFx () const |
| Writes progress of search in guifx format after each root move completes. | |
| void | SetGuiFx (bool flag) |
| Sets whether guifx output should be dumped. | |
| HexEval | Search (HexBoard &brd, HexColor color, const std::vector< int > &plywidth, const std::vector< int > &depths_to_search, int timelimit, std::vector< HexPoint > &PV) |
| Runs the AlphaBeta search. | |
| virtual HexEval | Evaluate ()=0 |
| Evaluates leaf position. | |
| virtual void | GenerateMoves (std::vector< HexPoint > &moves)=0 |
| Generates moves for this position. | |
| virtual void | ExecuteMove (HexPoint move)=0 |
| Plays the given move. | |
| virtual void | UndoMove (HexPoint move)=0 |
| Undoes the given move. | |
| virtual void | EnteredNewState () |
| Hook function called upon entering new position. | |
| virtual void | OnStartSearch () |
| Hook function called at the very start of the search. | |
| virtual void | OnSearchComplete () |
| Hook function called after the search has completed. | |
| virtual void | AfterStateSearched () |
| Hook function called after a states moves have been searched. | |
| std::string | DumpStats () |
| Output stats from search. | |
Protected Attributes | |
| HexBoard * | m_brd |
| The board we are playing on. | |
| HexColor | m_toplay |
| Color of player to move next. | |
| SearchTT * | m_tt |
| Transposition table to use during search, if any. | |
| bool | m_use_guifx |
| int | m_current_depth |
| Number of moves from the root. | |
| PointSequence | m_sequence |
| Sequences of moves to the current state. | |
| HexPoint | m_tt_bestmove |
| If current state exists in TT, but TT state was not deep enough, this will hold the best move for that state; otherwise it will be INVALID_MOVE. | |
| bool | m_tt_info_available |
Private Member Functions | |
| void | ClearStats () |
| void | UpdatePV (int current_depth, HexEval value, std::vector< HexPoint > &cv) |
| HexEval | CheckTerminalState () |
| bool | CheckAbort () |
| Checks SgUserAbort() and sets m_aborted if true. | |
| HexEval | SearchState (const std::vector< int > &plywidth, int depth, HexEval alpha, HexEval beta, std::vector< HexPoint > &cv) |
Private Attributes | |
| Statistics | m_statistics |
| std::vector< HexMoveValue > | m_eval |
| Evaluations for each move from the root state. | |
| bool | m_aborted |
| True if the search was aborted due to timelimit or user intervention. | |
Base Alpha-Beta search class.
Definition at line 25 of file HexAbSearch.hpp.
| HexAbSearch::HexAbSearch | ( | ) | [explicit] |
Constructor.
Definition at line 74 of file HexAbSearch.cpp.
| HexAbSearch::~HexAbSearch | ( | ) | [virtual] |
Destructor.
Definition at line 81 of file HexAbSearch.cpp.
| void HexAbSearch::AfterStateSearched | ( | ) | [virtual] |
Hook function called after a states moves have been searched.
Default implementation does nothing.
Reimplemented in WolveSearch.
Definition at line 93 of file HexAbSearch.cpp.
Referenced by SearchState().
| bool HexAbSearch::CheckAbort | ( | ) | [private] |
Checks SgUserAbort() and sets m_aborted if true.
Definition at line 181 of file HexAbSearch.cpp.
References LogInfo(), and m_aborted.
Referenced by SearchState().
| HexEval HexAbSearch::CheckTerminalState | ( | ) | [private] |
Definition at line 170 of file HexAbSearch.cpp.
References IMMEDIATE_LOSS, IMMEDIATE_WIN, EndgameUtils::IsLostGame(), EndgameUtils::IsWonGame(), m_brd, m_current_depth, and m_toplay.
Referenced by SearchState().
| void HexAbSearch::ClearStats | ( | ) | [private] |
| std::string HexAbSearch::DumpStats | ( | ) |
Output stats from search.
Definition at line 379 of file HexAbSearch.cpp.
References HexAbSearch::Statistics::Dump(), m_eval, and m_statistics.
Referenced by WolvePlayer::Search().
| void HexAbSearch::EnteredNewState | ( | ) | [virtual] |
Hook function called upon entering new position.
Default implementation does nothing.
Reimplemented in WolveSearch.
Definition at line 87 of file HexAbSearch.cpp.
Referenced by SearchState().
| virtual HexEval HexAbSearch::Evaluate | ( | ) | [pure virtual] |
| virtual void HexAbSearch::ExecuteMove | ( | HexPoint | move | ) | [pure virtual] |
| virtual void HexAbSearch::GenerateMoves | ( | std::vector< HexPoint > & | moves | ) | [pure virtual] |
Generates moves for this position.
Moves will be played in the returned order.
Implemented in WolveSearch.
Referenced by SearchState().
| bool HexAbSearch::GuiFx | ( | ) | const [inline] |
Writes progress of search in guifx format after each root move completes.
Off by default.
Definition at line 200 of file HexAbSearch.hpp.
References m_use_guifx.
Referenced by WolveEngine::WolveParam().
| void HexAbSearch::OnSearchComplete | ( | ) | [virtual] |
Hook function called after the search has completed.
Default implementation does nothing.
Reimplemented in WolveSearch.
Definition at line 91 of file HexAbSearch.cpp.
Referenced by Search().
| void HexAbSearch::OnStartSearch | ( | ) | [virtual] |
Hook function called at the very start of the search.
Default implementation does nothing.
Reimplemented in WolveSearch.
Definition at line 89 of file HexAbSearch.cpp.
Referenced by Search().
| HexEval HexAbSearch::Search | ( | HexBoard & | brd, | |
| HexColor | color, | |||
| const std::vector< int > & | plywidth, | |||
| const std::vector< int > & | depths_to_search, | |||
| int | timelimit, | |||
| std::vector< HexPoint > & | PV | |||
| ) |
Runs the AlphaBeta search.
| brd | board to play one. | |
| color | color to play. | |
| plywidth | depth of the search set to plywidth.size() and plywidth[j] top moves are explored. | |
| depths_to_search | successive depths to search (like in ID). | |
| timelimit | amount of time in which to finish search. | |
| PV | the principal variation will be stored here. |
If search is aborted by the user or the timelimit is reached, then the last valid result from interative deepening is returned. If the first iteration has not completed, then a score of -EVAL_INFINITY and a PV containing only INVALID_POINT are returned.
Definition at line 95 of file HexAbSearch.cpp.
References HexAbSearch::Statistics::elapsed_time, EVAL_INFINITY, Get(), IMMEDIATE_LOSS, IMMEDIATE_WIN, INVALID_POINT, LogInfo(), m_aborted, m_brd, m_current_depth, m_eval, m_sequence, m_statistics, m_toplay, OnSearchComplete(), OnStartSearch(), HexAbSearch::Statistics::pv, SearchState(), UNUSED(), and HexAbSearch::Statistics::value.
Referenced by WolvePlayer::Search().
| HexEval HexAbSearch::SearchState | ( | const std::vector< int > & | plywidth, | |
| int | depth, | |||
| HexEval | alpha, | |||
| HexEval | beta, | |||
| std::vector< HexPoint > & | cv | |||
| ) | [private] |
Definition at line 194 of file HexAbSearch.cpp.
References SearchedState::ACCURATE, AfterStateSearched(), SearchedState::bound, CheckAbort(), CheckTerminalState(), HexAbSearch::Statistics::cuts, SearchedState::depth, EnteredNewState(), EVAL_INFINITY, Evaluate(), ExecuteMove(), GenerateMoves(), HexBoard::GetPosition(), StoneBoard::Hash(), HexAssert, HexEval, IMMEDIATE_WIN, INVALID_POINT, LogFine(), SearchedState::LOWER_BOUND, m_aborted, m_brd, m_current_depth, m_eval, m_sequence, m_statistics, m_toplay, m_tt, m_tt_bestmove, m_tt_info_available, m_use_guifx, SearchedState::move, HexAbSearch::Statistics::mustplay_branches, HexAbSearch::Statistics::numinternal, HexAbSearch::Statistics::numleafs, HexAbSearch::Statistics::numstates, HexAbSearch::Statistics::numterminal, SearchedState::score, HexPointUtil::ToString(), HexAbSearch::Statistics::total_branches, HexAbSearch::Statistics::tt_cuts, HexAbSearch::Statistics::tt_hits, UndoMove(), SearchedState::UPPER_BOUND, and HexAbSearch::Statistics::visited_branches.
Referenced by Search().
| void HexAbSearch::SetGuiFx | ( | bool | flag | ) | [inline] |
Sets whether guifx output should be dumped.
Definition at line 195 of file HexAbSearch.hpp.
References m_use_guifx.
Referenced by WolveEngine::WolveParam().
| void HexAbSearch::SetTT | ( | SearchTT * | tt | ) | [inline] |
Sets the transposition table to be used during search.
Definition at line 190 of file HexAbSearch.hpp.
References m_tt.
Referenced by WolvePlayer::WolvePlayer().
| virtual void HexAbSearch::UndoMove | ( | HexPoint | move | ) | [pure virtual] |
| void HexAbSearch::UpdatePV | ( | int | current_depth, | |
| HexEval | value, | |||
| std::vector< HexPoint > & | cv | |||
| ) | [private] |
bool HexAbSearch::m_aborted [private] |
True if the search was aborted due to timelimit or user intervention.
Definition at line 187 of file HexAbSearch.hpp.
Referenced by CheckAbort(), Search(), and SearchState().
HexBoard* HexAbSearch::m_brd [protected] |
The board we are playing on.
Definition at line 112 of file HexAbSearch.hpp.
Referenced by WolveSearch::AfterStateSearched(), CheckTerminalState(), WolveSearch::ComputeResistance(), WolveSearch::ExecuteMove(), WolveSearch::GenerateMoves(), Search(), SearchState(), and WolveSearch::UndoMove().
int HexAbSearch::m_current_depth [protected] |
Number of moves from the root.
Definition at line 124 of file HexAbSearch.hpp.
Referenced by WolveSearch::AfterStateSearched(), CheckTerminalState(), WolveSearch::GenerateMoves(), Search(), and SearchState().
std::vector<HexMoveValue> HexAbSearch::m_eval [private] |
Evaluations for each move from the root state.
Definition at line 183 of file HexAbSearch.hpp.
Referenced by DumpStats(), Search(), and SearchState().
PointSequence HexAbSearch::m_sequence [protected] |
Sequences of moves to the current state.
Definition at line 127 of file HexAbSearch.hpp.
Referenced by WolveSearch::AfterStateSearched(), WolveSearch::GenerateMoves(), Search(), and SearchState().
Statistics HexAbSearch::m_statistics [private] |
Definition at line 180 of file HexAbSearch.hpp.
Referenced by DumpStats(), Search(), and SearchState().
HexColor HexAbSearch::m_toplay [protected] |
Color of player to move next.
Definition at line 115 of file HexAbSearch.hpp.
Referenced by WolveSearch::AfterStateSearched(), CheckTerminalState(), WolveSearch::Evaluate(), WolveSearch::ExecuteMove(), WolveSearch::GenerateMoves(), Search(), and SearchState().
SearchTT* HexAbSearch::m_tt [protected] |
Transposition table to use during search, if any.
Definition at line 118 of file HexAbSearch.hpp.
Referenced by SearchState(), and SetTT().
HexPoint HexAbSearch::m_tt_bestmove [protected] |
If current state exists in TT, but TT state was not deep enough, this will hold the best move for that state; otherwise it will be INVALID_MOVE.
Could be used in GenerateMoves() to improve move ordering when using iterative deepening.
Definition at line 133 of file HexAbSearch.hpp.
Referenced by WolveSearch::GenerateMoves(), and SearchState().
bool HexAbSearch::m_tt_info_available [protected] |
Definition at line 134 of file HexAbSearch.hpp.
Referenced by SearchState().
bool HexAbSearch::m_use_guifx [protected] |
Definition at line 121 of file HexAbSearch.hpp.
Referenced by GuiFx(), SearchState(), and SetGuiFx().