Determines the winner of a gamestate. More...
#include <DfsSolver.hpp>
Classes | |
struct | GlobalStatistics |
Globabl statistics for the current solver run. More... | |
Public Member Functions | |
DfsSolver () | |
~DfsSolver () | |
HexColor | Solve (const HexState &state, HexBoard &board, DfsSolutionSet &solution, DfsStates &positions, int depthLimit=-1, double timeLimit=-1.0) |
Solves state using the given previously solved positions. | |
void | DumpStats (const DfsSolutionSet &solution) const |
Dumps the stats on # of states, branching factors, etc, for the last run. | |
DfsHistogram | Histogram () const |
Returns histogram of last search. | |
Parameters | |
bool | UseDecompositions () const |
Controls whether gamestates decomposible into separate components have each side solved separately and the proofs combined as necessary. | |
void | SetUseDecompositions (bool enable) |
See UseDecompositions(). | |
int | ProgressDepth () const |
Depth from root in which the current variation is printed. | |
void | SetProgressDepth (int depth) |
See ProgressDepth(). | |
int | UpdateDepth () const |
Depth at which the current state is dumped to the log. | |
void | SetUpdateDepth (int depth) |
See UpdateDepth(). | |
bool | ShrinkProofs () const |
Whether ICE is used to provably shrink proofs. | |
void | SetShrinkProofs (bool enable) |
See ShrinkProofs(). | |
bool | BackupIceInfo () const |
Use newly acquired ICE-info after the move ordering stage to prune the moves to consider. | |
void | SetBackupIceInfo (bool enable) |
See BackupIceInfo(). | |
bool | UseGuiFx () const |
void | SetUseGuiFx (bool enable) |
See UseGuiFx(). | |
int | MoveOrdering () const |
Returns the move order flags. | |
void | SetMoveOrdering (int flags) |
See MoveOrdering(). | |
Private Member Functions | |
void | PlayMove (HexPoint cell) |
Plays the move; updates the board. | |
void | UndoMove (HexPoint cell) |
Takes back the move played. | |
bool | CheckTransposition (DfsData &state) const |
void | StoreState (const DfsData &state, const bitset_t &proof) |
bool | CheckAbort () |
Checks timelimit and SgUserAbort(). | |
bool | HandleLeafNode (DfsData &state, bitset_t &proof) const |
Returns true if current data is a terminal node (win/loss), or a DB/TT hit. | |
bool | HandleTerminalNode (DfsData &state, bitset_t &proof) const |
Returns true if node is terminal. | |
bool | OrderMoves (bitset_t &mustplay, DfsSolutionSet &solution, std::vector< HexMoveValue > &moves) |
Orders the moves in mustplay using several heuristics. | |
bool | SolveState (PointSequence &variation, DfsSolutionSet &solution) |
Solves the current state. | |
bool | SolveDecomposition (PointSequence &variation, DfsSolutionSet &solution, HexPoint group) |
Solves each side of the decompsosition; combines proofs if necessary. | |
bool | SolveInteriorState (PointSequence &variation, DfsSolutionSet &solution) |
Does the recursive mustplay search. | |
void | HandleProof (const PointSequence &variation, bool winning_state, DfsSolutionSet &solution) |
Shrinks/verifies proof then stores it. | |
Private Attributes | |
DfsStates * | m_positions |
HexBoard * | m_workBrd |
double | m_start_time |
double | m_end_time |
std::vector< std::pair< int, int > > | m_completed |
bool | m_aborted |
DfsHistogram | m_histogram |
GlobalStatistics | m_statistics |
boost::scoped_ptr< HexState > | m_state |
bool | m_use_decompositions |
See UseDecompositions(). | |
int | m_update_depth |
See UpdateDepth(). | |
bool | m_shrink_proofs |
See ShrinkProofs(). | |
bool | m_backup_ice_info |
See BackupIceInfo(). | |
bool | m_use_guifx |
See UseGuiFx(). | |
int | m_move_ordering |
See MoveOrdering(). | |
unsigned | m_last_histogram_dump |
int | m_depthLimit |
double | m_timeLimit |
Determines the winner of a gamestate.
DfsSolver uses a mustplay driven depth-first search to determine the winner in the given state.
Definition at line 226 of file DfsSolver.hpp.
DfsSolver::DfsSolver | ( | ) |
Definition at line 39 of file DfsSolver.cpp.
DfsSolver::~DfsSolver | ( | ) |
Definition at line 52 of file DfsSolver.cpp.
bool DfsSolver::BackupIceInfo | ( | ) | const [inline] |
Use newly acquired ICE-info after the move ordering stage to prune the moves to consider.
Definition at line 426 of file DfsSolver.hpp.
References m_backup_ice_info.
Referenced by DfsCommands::CmdParamSolver().
bool DfsSolver::CheckAbort | ( | ) | [private] |
Checks timelimit and SgUserAbort().
Sets m_aborted if necessary, aborting the search. Returns true if search should be aborted, false otherwise.
Definition at line 136 of file DfsSolver.cpp.
References Time::Get(), LogInfo(), m_aborted, m_start_time, and m_timeLimit.
Referenced by SolveState().
bool DfsSolver::CheckTransposition | ( | DfsData & | state | ) | const [private] |
Definition at line 108 of file DfsSolver.cpp.
References SolverDB< HASH, DB, DATA >::Get(), m_positions, and m_state.
Referenced by HandleLeafNode(), OrderMoves(), and Solve().
void DfsSolver::DumpStats | ( | const DfsSolutionSet & | solution | ) | const |
Dumps the stats on # of states, branching factors, etc, for the last run.
Definition at line 856 of file DfsSolver.cpp.
References DfsBranchStatistics::branches_to_win, DfsBranchStatistics::cells_removed, SolverDB< HASH, DB, DATA >::Database(), DfsBranchStatistics::decompositions, DfsBranchStatistics::decompositions_won, DfsBranchStatistics::expanded_states, DfsBranchStatistics::explored_states, Time::Formatted(), StateDB< T >::GetStatistics(), SolverDB< HASH, DB, DATA >::HashTable(), LogInfo(), m_end_time, DfsSolutionSet::m_numMoves, m_positions, m_start_time, m_statistics, DfsBranchStatistics::minimal_explored, DfsBranchStatistics::moves_to_consider, DfsSolver::GlobalStatistics::played, DfsBranchStatistics::pruned, DfsSolutionSet::pv, DfsBranchStatistics::shrunk, DfsSolutionSet::stats, HexPointUtil::ToString(), DfsBranchStatistics::total_states, and DfsBranchStatistics::winning_expanded.
Referenced by DfsCommands::CmdSolverFindWinning(), and DfsCommands::CmdSolveState().
Returns true if current data is a terminal node (win/loss), or a DB/TT hit.
If so, info is stored in data.
Definition at line 182 of file DfsSolver.cpp.
References CheckTransposition(), HandleTerminalNode(), m_state, DfsData::m_win, m_workBrd, and ProofUtil::MaximumProofSet().
Referenced by SolveState().
void DfsSolver::HandleProof | ( | const PointSequence & | variation, | |
bool | winning_state, | |||
DfsSolutionSet & | solution | |||
) | [private] |
Shrinks/verifies proof then stores it.
Definition at line 462 of file DfsSolver.cpp.
References DfsBranchStatistics::cells_removed, HexPointUtil::colorEdge1(), HexPointUtil::colorEdge2(), BoardUtils::ConnectedOnBitset(), HexBoard::Const(), benzene_bitset< _Nb >::count(), EMPTY_BITSET, StoneBoard::GetColor(), HexBoard::GetDead(), HexBoard::GetPosition(), HexBoard::ICE(), INVALID_POINT, m_aborted, DfsSolutionSet::m_numMoves, m_shrink_proofs, m_state, m_workBrd, DfsSolutionSet::proof, DfsSolutionSet::pv, BoardUtils::ReachableOnBitset(), ProofUtil::ShrinkProof(), DfsBranchStatistics::shrunk, DfsSolutionSet::stats, StoreState(), HexPointUtil::ToString(), DfsBranchStatistics::total_states, and HexBoard::Write().
Referenced by SolveState().
Returns true if node is terminal.
Fills in data if terminal. Data's bestmove field is not specified here.
Definition at line 158 of file DfsSolver.cpp.
References EndgameUtils::IsLostGame(), EndgameUtils::IsWonGame(), m_histogram, DfsData::m_numMoves, DfsData::m_numStates, m_state, DfsData::m_win, m_workBrd, and DfsHistogram::terminal.
Referenced by HandleLeafNode(), OrderMoves(), and SolveDecomposition().
DfsHistogram DfsSolver::Histogram | ( | ) | const [inline] |
Returns histogram of last search.
Definition at line 456 of file DfsSolver.hpp.
References m_histogram.
Referenced by DfsCommands::CmdHistogram().
int DfsSolver::MoveOrdering | ( | ) | const [inline] |
Returns the move order flags.
Definition at line 446 of file DfsSolver.hpp.
References m_move_ordering.
Referenced by DfsCommands::CmdParamSolver().
bool DfsSolver::OrderMoves | ( | bitset_t & | mustplay, | |
DfsSolutionSet & | solution, | |||
std::vector< HexMoveValue > & | moves | |||
) | [private] |
Orders the moves in mustplay using several heuristics.
Aborts move ordering early if it finds a TT win: winning move is put to the front.
Will shrink the mustplay if it encounters TT losses: losing moves are not added to the list of sorted moves.
Returns true if it found a TT win, false otherwise.
The TT/DB checks are done as a single 1-ply sweep prior to any move ordering, since computing the VCs for any solved states is pointless, plus these may resolve the current state immediately.
Definition at line 570 of file DfsSolver.cpp.
References CheckTransposition(), HexPointUtil::colorEdge1(), HexPointUtil::colorEdge2(), HexBoard::Cons(), HexBoard::Const(), benzene_bitset< _Nb >::count(), DfsSolverUtil::DistanceFromCenter(), VCSet::Exists(), DfsBranchStatistics::explored_states, DfsMoveOrderFlags::FROM_CENTER, VCUtils::GetMustplay(), HexBoard::GetPosition(), HandleTerminalNode(), HexAssert, ProofUtil::InitialProofForOpponent(), BitsetUtil::IsSubsetOf(), LogFine(), m_backup_ice_info, m_move_ordering, DfsData::m_numMoves, DfsSolutionSet::m_numMoves, DfsData::m_numStates, m_state, DfsData::m_win, m_workBrd, ProofUtil::MaximumProofSet(), DfsBranchStatistics::minimal_explored, EndgameUtils::MovesToConsider(), PlayMove(), StoneBoard::PlayMove(), DfsSolutionSet::proof, VC::SEMI, benzene_bitset< _Nb >::set(), DfsSolutionSet::SetPV(), DfsSolutionSet::stats, benzene_bitset< _Nb >::test(), DfsBranchStatistics::total_states, UndoMove(), StoneBoard::UndoMove(), DfsMoveOrderFlags::WITH_MUSTPLAY, DfsMoveOrderFlags::WITH_RESIST, and HexBoard::Write().
Referenced by SolveInteriorState().
void DfsSolver::PlayMove | ( | HexPoint | cell | ) | [private] |
Plays the move; updates the board.
Definition at line 544 of file DfsSolver.cpp.
References m_state, m_statistics, m_workBrd, DfsSolver::GlobalStatistics::played, and HexBoard::PlayMove().
Referenced by OrderMoves(), and SolveInteriorState().
int DfsSolver::ProgressDepth | ( | ) | const |
Depth from root in which the current variation is printed.
void DfsSolver::SetBackupIceInfo | ( | bool | enable | ) | [inline] |
See BackupIceInfo().
Definition at line 431 of file DfsSolver.hpp.
References m_backup_ice_info.
Referenced by DfsCommands::CmdParamSolver().
void DfsSolver::SetMoveOrdering | ( | int | flags | ) | [inline] |
See MoveOrdering().
Definition at line 451 of file DfsSolver.hpp.
References m_move_ordering.
Referenced by DfsCommands::CmdParamSolver().
void DfsSolver::SetProgressDepth | ( | int | depth | ) |
See ProgressDepth().
void DfsSolver::SetShrinkProofs | ( | bool | enable | ) | [inline] |
See ShrinkProofs().
Definition at line 421 of file DfsSolver.hpp.
References m_shrink_proofs.
Referenced by DfsCommands::CmdParamSolver().
void DfsSolver::SetUpdateDepth | ( | int | depth | ) | [inline] |
See UpdateDepth().
Definition at line 411 of file DfsSolver.hpp.
References m_update_depth.
Referenced by DfsCommands::CmdParamSolver().
void DfsSolver::SetUseDecompositions | ( | bool | enable | ) | [inline] |
See UseDecompositions().
Definition at line 401 of file DfsSolver.hpp.
References m_use_decompositions.
Referenced by DfsCommands::CmdParamSolver().
void DfsSolver::SetUseGuiFx | ( | bool | enable | ) | [inline] |
See UseGuiFx().
Definition at line 441 of file DfsSolver.hpp.
References m_use_guifx.
Referenced by DfsCommands::CmdParamSolver().
bool DfsSolver::ShrinkProofs | ( | ) | const [inline] |
Whether ICE is used to provably shrink proofs.
Definition at line 416 of file DfsSolver.hpp.
References m_shrink_proofs.
Referenced by DfsCommands::CmdParamSolver().
HexColor DfsSolver::Solve | ( | const HexState & | state, | |
HexBoard & | board, | |||
DfsSolutionSet & | solution, | |||
DfsStates & | positions, | |||
int | depthLimit = -1 , |
|||
double | timeLimit = -1.0 | |||
) |
Solves state using the given previously solved positions.
Returns color of winner or EMPTY if aborted before state was solved.
Definition at line 58 of file DfsSolver.cpp.
References BITSETSIZE, CheckTransposition(), HexBoard::ComputeAll(), EMPTY, ICEngine::FindPermanentlyInferior(), Get(), SolverDBUtil::GetVariation(), HexBoard::ICE(), LogInfo(), m_aborted, m_completed, m_depthLimit, m_end_time, m_histogram, m_last_histogram_dump, DfsData::m_numMoves, DfsSolutionSet::m_numMoves, m_positions, m_start_time, m_state, m_statistics, m_timeLimit, DfsData::m_win, m_workBrd, ProofUtil::MaximumProofSet(), DfsSolutionSet::proof, DfsSolutionSet::pv, SolveState(), and HexState::ToPlay().
Referenced by DfsCommands::CmdSolverFindWinning(), and DfsCommands::CmdSolveState().
bool DfsSolver::SolveDecomposition | ( | PointSequence & | variation, | |
DfsSolutionSet & | solution, | |||
HexPoint | group | |||
) | [private] |
Solves each side of the decompsosition; combines proofs if necessary.
Definition at line 251 of file DfsSolver.cpp.
References GraphUtils::BFS(), HexPointUtil::colorEdge1(), HexPointUtil::colorEdge2(), GraphUtils::ComputeDigraph(), HexBoard::Const(), DfsBranchStatistics::decompositions, DfsBranchStatistics::decompositions_won, DfsBranchStatistics::expanded_states, DfsBranchStatistics::explored_states, ConstBoard::GetCells(), StoneBoard::GetColor(), HexBoard::GetDead(), HexBoard::GetGroups(), HexBoard::GetPosition(), HandleTerminalNode(), DfsData::m_numMoves, DfsSolutionSet::m_numMoves, m_state, DfsData::m_win, m_workBrd, DfsBranchStatistics::minimal_explored, HexBoard::PlayStones(), DfsSolutionSet::proof, DfsSolutionSet::pv, SolveInteriorState(), DfsSolutionSet::stats, DfsBranchStatistics::total_states, HexBoard::UndoMove(), and HexBoard::Write().
Referenced by SolveState().
bool DfsSolver::SolveInteriorState | ( | PointSequence & | variation, | |
DfsSolutionSet & | solution | |||
) | [private] |
Does the recursive mustplay search.
Definition at line 325 of file DfsSolver.cpp.
References InferiorCells::All(), benzene_bitset< _Nb >::any(), BLACK, DfsHistogram::branches, DfsBranchStatistics::branches_to_win, benzene_bitset< _Nb >::count(), DfsBranchStatistics::expanded_states, DfsBranchStatistics::explored_states, HexBoard::GetInferiorCells(), HexBoard::GetPosition(), BoardUtils::GuiDumpOutsideConsiderSet(), InferiorCells::GuiOutput(), HexAssert, ProofUtil::InitialProofForOpponent(), m_completed, m_histogram, DfsSolutionSet::m_numMoves, m_state, m_update_depth, m_use_guifx, m_workBrd, DfsBranchStatistics::minimal_explored, DfsBranchStatistics::moves_to_consider, EndgameUtils::MovesToConsider(), DfsHistogram::mustplay, OrderMoves(), PlayMove(), DfsSolutionSet::proof, DfsBranchStatistics::pruned, DfsSolutionSet::pv, DfsSolutionSet::SetPV(), DfsHistogram::size_of_losing_states, DfsHistogram::size_of_winning_states, SolveState(), DfsHistogram::states, DfsHistogram::states_under_losing, DfsSolutionSet::stats, benzene_bitset< _Nb >::test(), DfsBranchStatistics::total_states, UndoMove(), DfsHistogram::winning, and DfsBranchStatistics::winning_expanded.
Referenced by SolveDecomposition(), and SolveState().
bool DfsSolver::SolveState | ( | PointSequence & | variation, | |
DfsSolutionSet & | solution | |||
) | [private] |
Solves the current state.
Handles decompositions if option is turned on.
Definition at line 199 of file DfsSolver.cpp.
References CheckAbort(), DfsBranchStatistics::explored_states, BoardUtils::FindSplittingDecomposition(), HandleLeafNode(), HandleProof(), LogInfo(), m_histogram, m_last_histogram_dump, DfsData::m_numMoves, DfsSolutionSet::m_numMoves, DfsData::m_numStates, m_state, m_statistics, m_use_decompositions, DfsData::m_win, m_workBrd, DfsBranchStatistics::minimal_explored, DfsSolver::GlobalStatistics::played, DfsSolutionSet::proof, DfsSolutionSet::pv, SolveDecomposition(), SolveInteriorState(), DfsSolutionSet::stats, DfsBranchStatistics::total_states, and DfsHistogram::Write().
Referenced by Solve(), and SolveInteriorState().
Definition at line 113 of file DfsSolver.cpp.
References m_positions, m_state, SolverDBParameters::m_transStones, SolverDBParameters::m_useFlippedStates, SolverDBParameters::m_useProofTranspositions, DfsData::m_win, SolverDB< HASH, DB, DATA >::Parameters(), SolverDB< HASH, DB, DATA >::Put(), ProofUtil::StoreFlippedStates(), and ProofUtil::StoreTranspositions().
Referenced by HandleProof().
void DfsSolver::UndoMove | ( | HexPoint | cell | ) | [private] |
Takes back the move played.
Definition at line 553 of file DfsSolver.cpp.
References m_state, m_workBrd, and HexBoard::UndoMove().
Referenced by OrderMoves(), and SolveInteriorState().
int DfsSolver::UpdateDepth | ( | ) | const [inline] |
Depth at which the current state is dumped to the log.
Definition at line 406 of file DfsSolver.hpp.
References m_update_depth.
Referenced by DfsCommands::CmdParamSolver().
bool DfsSolver::UseDecompositions | ( | ) | const [inline] |
Controls whether gamestates decomposible into separate components have each side solved separately and the proofs combined as necessary.
Definition at line 396 of file DfsSolver.hpp.
References m_use_decompositions.
Referenced by DfsCommands::CmdParamSolver().
bool DfsSolver::UseGuiFx | ( | ) | const [inline] |
Definition at line 436 of file DfsSolver.hpp.
References m_use_guifx.
Referenced by DfsCommands::CmdParamSolver().
bool DfsSolver::m_aborted [private] |
Definition at line 331 of file DfsSolver.hpp.
Referenced by CheckAbort(), HandleProof(), and Solve().
bool DfsSolver::m_backup_ice_info [private] |
See BackupIceInfo().
Definition at line 349 of file DfsSolver.hpp.
Referenced by BackupIceInfo(), OrderMoves(), and SetBackupIceInfo().
std::vector<std::pair<int, int> > DfsSolver::m_completed [private] |
Definition at line 329 of file DfsSolver.hpp.
Referenced by Solve(), and SolveInteriorState().
int DfsSolver::m_depthLimit [private] |
Definition at line 359 of file DfsSolver.hpp.
Referenced by Solve().
double DfsSolver::m_end_time [private] |
Definition at line 327 of file DfsSolver.hpp.
Referenced by DumpStats(), and Solve().
DfsHistogram DfsSolver::m_histogram [mutable, private] |
Definition at line 333 of file DfsSolver.hpp.
Referenced by HandleTerminalNode(), Histogram(), Solve(), SolveInteriorState(), and SolveState().
unsigned DfsSolver::m_last_histogram_dump [private] |
Definition at line 357 of file DfsSolver.hpp.
Referenced by Solve(), and SolveState().
int DfsSolver::m_move_ordering [private] |
See MoveOrdering().
Definition at line 355 of file DfsSolver.hpp.
Referenced by MoveOrdering(), OrderMoves(), and SetMoveOrdering().
DfsStates* DfsSolver::m_positions [private] |
Definition at line 321 of file DfsSolver.hpp.
Referenced by CheckTransposition(), DumpStats(), Solve(), and StoreState().
bool DfsSolver::m_shrink_proofs [private] |
See ShrinkProofs().
Definition at line 346 of file DfsSolver.hpp.
Referenced by HandleProof(), SetShrinkProofs(), and ShrinkProofs().
double DfsSolver::m_start_time [private] |
Definition at line 325 of file DfsSolver.hpp.
Referenced by CheckAbort(), DumpStats(), and Solve().
boost::scoped_ptr<HexState> DfsSolver::m_state [private] |
Definition at line 337 of file DfsSolver.hpp.
Referenced by CheckTransposition(), HandleLeafNode(), HandleProof(), HandleTerminalNode(), OrderMoves(), PlayMove(), Solve(), SolveDecomposition(), SolveInteriorState(), SolveState(), StoreState(), and UndoMove().
GlobalStatistics DfsSolver::m_statistics [mutable, private] |
Definition at line 335 of file DfsSolver.hpp.
Referenced by DumpStats(), PlayMove(), Solve(), and SolveState().
double DfsSolver::m_timeLimit [private] |
Definition at line 361 of file DfsSolver.hpp.
Referenced by CheckAbort(), and Solve().
int DfsSolver::m_update_depth [private] |
See UpdateDepth().
Definition at line 343 of file DfsSolver.hpp.
Referenced by SetUpdateDepth(), SolveInteriorState(), and UpdateDepth().
bool DfsSolver::m_use_decompositions [private] |
See UseDecompositions().
Definition at line 340 of file DfsSolver.hpp.
Referenced by SetUseDecompositions(), SolveState(), and UseDecompositions().
bool DfsSolver::m_use_guifx [private] |
See UseGuiFx().
Definition at line 352 of file DfsSolver.hpp.
Referenced by SetUseGuiFx(), SolveInteriorState(), and UseGuiFx().
HexBoard* DfsSolver::m_workBrd [private] |
Definition at line 323 of file DfsSolver.hpp.
Referenced by HandleLeafNode(), HandleProof(), HandleTerminalNode(), OrderMoves(), PlayMove(), Solve(), SolveDecomposition(), SolveInteriorState(), SolveState(), and UndoMove().