Tracks pattern state info on a board. More...
#include <PatternState.hpp>
Classes | |
struct | Statistics |
Pattern checking statistics. More... | |
Public Types | |
enum | MatchMode { STOP_AT_FIRST_HIT, MATCH_ALL } |
Options controlling pattern matching behavoir at a cell. More... | |
Public Member Functions | |
PatternState (StoneBoard &brd) | |
Track the pattern state on the given board. | |
~PatternState () | |
const StoneBoard & | Board () const |
Returns board state is tracking. | |
StoneBoard & | Board () |
Returns board state is tracking. | |
int | UpdateRadius () const |
Sets the distance to which we update pattern info from the last played cell; used in Update(cell). | |
void | SetUpdateRadius (int radius) |
See SetUpdateRadius(). | |
void | Update () |
Computes the pattern checking information for this board state. | |
void | Update (HexPoint cell) |
Updates the pattern checking information only for the given move. | |
void | Update (const bitset_t &changed) |
Calls update(cell) for each move in changed, each of which must correspond to an occupied cell. | |
void | UpdateRingGodel (HexPoint cell) |
Update only the ring godels of the neighbours of cell. | |
void | CopyState (const PatternState &other) |
Copies state from other. | |
void | MatchOnCell (const HashedPatternSet &patset, HexPoint cell, MatchMode mode, PatternHits &hits) const |
Matches the hashed patterns at the specified cell, storing hit information in hits, using the given matching mode. | |
bitset_t | MatchOnBoard (const bitset_t &consider, const HashedPatternSet &patset, MatchMode mode, std::vector< PatternHits > &hits) const |
Matches the hashed patterns on the consider set, returning a set of cells where at least one pattern matched. | |
bitset_t | MatchOnBoard (const bitset_t &consider, const HashedPatternSet &patset) const |
Matches the hashed patterns on the given consider set, returning a set of cells where at least one pattern matched. | |
void | ClearPatternCheckStats () |
Reset the pattern checking statistics. | |
std::string | DumpPatternCheckStats () const |
Return a string containing the pattern checking statistics. | |
Private Member Functions | |
void | operator= (const PatternState &other) |
Non-assignable. | |
PatternState (const PatternState &other) | |
Non-copyable. | |
void | ClearGodels () |
bool | CheckRotatedSlices (HexPoint cell, const Pattern &pat, int angle) const |
Returns true if pattern's slices rotated by angle match the board when pattern is centered at cell. | |
bool | CheckRotatedSlices (HexPoint cell, const RotatedPattern &rotpat) const |
Convenience method. | |
bool | CheckRingGodel (HexPoint cell, const Pattern &pattern, int angle) const |
Returns true if the pattern's ring godel matches the board. | |
bool | CheckRingGodel (HexPoint cell, const RotatedPattern &rotpat) const |
Returns true if the pattern's ring godel matches the board. | |
bool | CheckRotatedPattern (HexPoint cell, const RotatedPattern &rotpat, std::vector< HexPoint > &moves1, std::vector< HexPoint > &moves2) const |
Checks the pre-rotated pattern against the board. | |
Private Attributes | |
StoneBoard & | m_brd |
const PatternMatcherData * | m_data |
int | m_update_radius |
See UpdateRadius(). | |
int | m_slice_godel [BITSETSIZE][BLACK_AND_WHITE][Pattern::NUM_SLICES] |
RingGodel | m_ring_godel [BITSETSIZE] |
Statistics | m_statistics |
Tracks pattern state info on a board.
Definition at line 135 of file PatternState.hpp.
Options controlling pattern matching behavoir at a cell.
STOP_AT_FIRST_HIT |
Stops the search after first hit. |
MATCH_ALL |
Continues search after first hit, storing all results. |
Definition at line 185 of file PatternState.hpp.
PatternState::PatternState | ( | StoneBoard & | brd | ) | [explicit] |
Track the pattern state on the given board.
Definition at line 125 of file PatternState.cpp.
References ClearGodels().
PatternState::~PatternState | ( | ) |
Definition at line 133 of file PatternState.cpp.
PatternState::PatternState | ( | const PatternState & | other | ) | [private] |
Non-copyable.
StoneBoard & PatternState::Board | ( | ) | [inline] |
const StoneBoard & PatternState::Board | ( | ) | const [inline] |
Returns board state is tracking.
Definition at line 297 of file PatternState.hpp.
References m_brd.
Referenced by ICEngine::ComputeInferiorCells(), ICEngine::FindDominated(), HexUctPolicy::GenerateMove(), and MatchOnBoard().
bool PatternState::CheckRingGodel | ( | HexPoint | cell, | |
const RotatedPattern & | rotpat | |||
) | const [private] |
Returns true if the pattern's ring godel matches the board.
Definition at line 390 of file PatternState.cpp.
References RotatedPattern::angle(), CheckRingGodel(), and RotatedPattern::pattern().
bool PatternState::CheckRingGodel | ( | HexPoint | cell, | |
const Pattern & | pattern, | |||
int | angle | |||
) | const [private] |
Returns true if the pattern's ring godel matches the board.
Definition at line 397 of file PatternState.cpp.
References m_ring_godel, m_statistics, PatternRingGodel::MatchesGodel(), PatternState::Statistics::ring_checks, and Pattern::RingGodel().
Referenced by CheckRingGodel(), and CheckRotatedPattern().
bool PatternState::CheckRotatedPattern | ( | HexPoint | cell, | |
const RotatedPattern & | rotpat, | |||
std::vector< HexPoint > & | moves1, | |||
std::vector< HexPoint > & | moves2 | |||
) | const [private] |
Checks the pre-rotated pattern against the board.
Returns true if it matches. Pattern encoded moves are stored in moves.
Definition at line 296 of file PatternState.cpp.
References RotatedPattern::angle(), CheckRingGodel(), CheckRotatedSlices(), StoneBoard::Const(), Pattern::extension(), Pattern::getFlags(), Pattern::getMoves1(), Pattern::getMoves2(), PatternMatcherData::GetRotatedMove(), Pattern::HAS_MOVES1, Pattern::HAS_MOVES2, HexAssert, ConstBoard::IsCell(), m_brd, m_data, m_statistics, RotatedPattern::pattern(), and PatternState::Statistics::pattern_checks.
Referenced by MatchOnCell().
bool PatternState::CheckRotatedSlices | ( | HexPoint | cell, | |
const RotatedPattern & | rotpat | |||
) | const [private] |
Convenience method.
Definition at line 340 of file PatternState.cpp.
References RotatedPattern::angle(), CheckRotatedSlices(), and RotatedPattern::pattern().
bool PatternState::CheckRotatedSlices | ( | HexPoint | cell, | |
const Pattern & | pattern, | |||
int | angle | |||
) | const [private] |
Returns true if pattern's slices rotated by angle match the board when pattern is centered at cell.
Definition at line 348 of file PatternState.cpp.
References BLACK, Pattern::FEATURE_BLACK, Pattern::FEATURE_CELLS, Pattern::FEATURE_WHITE, Pattern::getData(), m_slice_godel, m_statistics, Pattern::NUM_SLICES, PatternState::Statistics::slice_checks, and WHITE.
Referenced by CheckRotatedPattern(), and CheckRotatedSlices().
void PatternState::ClearGodels | ( | ) | [private] |
Definition at line 225 of file PatternState.cpp.
References StoneBoard::Const(), ConstBoard::Interior(), m_brd, m_ring_godel, and m_slice_godel.
Referenced by PatternState(), and Update().
void PatternState::ClearPatternCheckStats | ( | ) |
Reset the pattern checking statistics.
Definition at line 406 of file PatternState.cpp.
References m_statistics, PatternState::Statistics::pattern_checks, PatternState::Statistics::ring_checks, and PatternState::Statistics::slice_checks.
Referenced by MoHexPlayer::Search().
void PatternState::CopyState | ( | const PatternState & | other | ) |
Copies state from other.
Definition at line 232 of file PatternState.cpp.
References StoneBoard::Const(), HexAssert, m_brd, m_ring_godel, m_slice_godel, and m_update_radius.
Referenced by ICEngine::BackupOpponentDead(), and HexBoard::HexBoard().
std::string PatternState::DumpPatternCheckStats | ( | ) | const |
Return a string containing the pattern checking statistics.
Definition at line 413 of file PatternState.cpp.
References m_statistics, PatternState::Statistics::pattern_checks, PatternState::Statistics::ring_checks, and PatternState::Statistics::slice_checks.
bitset_t PatternState::MatchOnBoard | ( | const bitset_t & | consider, | |
const HashedPatternSet & | patset | |||
) | const |
Matches the hashed patterns on the given consider set, returning a set of cells where at least one pattern matched.
For each cell, the search is aborted after the first match. No information on the hits is returned. This is a convience method.
Definition at line 277 of file PatternState.cpp.
References Board(), StoneBoard::Const(), ConstBoard::GetCells(), MatchOnCell(), benzene_bitset< _Nb >::set(), and STOP_AT_FIRST_HIT.
bitset_t PatternState::MatchOnBoard | ( | const bitset_t & | consider, | |
const HashedPatternSet & | patset, | |||
MatchMode | mode, | |||
std::vector< PatternHits > & | hits | |||
) | const |
Matches the hashed patterns on the consider set, returning a set of cells where at least one pattern matched.
Note that hits must be large enough that it can be indexed by each cell in consider. Matching mode refers to a single cell, not the search as a whole; that is, a hit on cell A does not abort the entire search, it only moves the search on to the remaining cells.
Definition at line 261 of file PatternState.cpp.
References Board(), StoneBoard::Const(), ConstBoard::GetCells(), MatchOnCell(), and benzene_bitset< _Nb >::set().
Referenced by ICEngine::FindDead(), ICEngine::FindDominated(), ICEngine::FindPermanentlyInferior(), ICEngine::FindReversible(), and ICEngine::FindVulnerable().
void PatternState::MatchOnCell | ( | const HashedPatternSet & | patset, | |
HexPoint | cell, | |||
MatchMode | mode, | |||
PatternHits & | hits | |||
) | const |
Matches the hashed patterns at the specified cell, storing hit information in hits, using the given matching mode.
Definition at line 242 of file PatternState.cpp.
References CheckRotatedPattern(), HashedPatternSet::ListForGodel(), m_ring_godel, and STOP_AT_FIRST_HIT.
Referenced by VCBuilder::ComputeCapturedSets(), ICEngine::FindCaptured(), ICEngine::FindDominatedOnCell(), ICEngine::FindMutualFillin(), MatchOnBoard(), and HexUctPolicy::PickRandomPatternMove().
void PatternState::operator= | ( | const PatternState & | other | ) | [private] |
Non-assignable.
void PatternState::SetUpdateRadius | ( | int | radius | ) | [inline] |
See SetUpdateRadius().
Definition at line 307 of file PatternState.hpp.
References HexAssert, m_update_radius, and Pattern::MAX_EXTENSION.
Referenced by MoHexPlayer::Search().
void PatternState::Update | ( | const bitset_t & | changed | ) |
Calls update(cell) for each move in changed, each of which must correspond to an occupied cell.
Definition at line 209 of file PatternState.cpp.
References HexAssert, StoneBoard::IsOccupied(), m_brd, and Update().
void PatternState::Update | ( | HexPoint | cell | ) |
Updates the pattern checking information only for the given move.
Sweeps over all cells updateRadius() distance from cell.
Definition at line 158 of file PatternState.cpp.
References RingGodel::AddColorToSlice(), StoneBoard::Const(), EMPTY, FIRST_EDGE, StoneBoard::GetColor(), HexAssert, HexColorUtil::isBlackWhite(), HexPointUtil::isEdge(), ConstBoard::IsLocation(), HexPointUtil::isSwap(), m_brd, m_data, m_ring_godel, m_slice_godel, m_update_radius, ConstBoard::Nbs(), Pattern::NUM_SLICES, PatternMatcherData::played_in_edge, PatternMatcherData::played_in_godel, PatternMatcherData::played_in_slice, and RingGodel::RemoveColorFromSlice().
void PatternState::Update | ( | ) |
Computes the pattern checking information for this board state.
Calls update(cell) for each occupied cell.
Definition at line 218 of file PatternState.cpp.
References ClearGodels(), StoneBoard::GetBlack(), StoneBoard::GetWhite(), and m_brd.
Referenced by HexBoard::AddStones(), ICEngine::BackupOpponentDead(), ICEngine::CliqueCutsetDead(), BenzeneHtpEngine::CmdComputeDominated(), BenzeneHtpEngine::CmdComputeDominatedOnCell(), BenzeneHtpEngine::CmdComputeFillin(), BenzeneHtpEngine::CmdComputeInferior(), BenzeneHtpEngine::CmdComputeReversible(), BenzeneHtpEngine::CmdComputeVulnerable(), HexBoard::ComputeAll(), ICEngine::ComputeDeadCaptured(), ICEngine::FillInMutualFillin(), ICEngine::FillinPermanentlyInferior(), ICEngine::FillInVulnerable(), HexBoard::PlayMove(), HexBoard::PlayStones(), HexBoard::UndoMove(), and Update().
int PatternState::UpdateRadius | ( | ) | const [inline] |
Sets the distance to which we update pattern info from the last played cell; used in Update(cell).
Default is Pattern::MAX_EXTENSION.
Definition at line 314 of file PatternState.hpp.
References m_update_radius.
Referenced by MoHexPlayer::Search().
void PatternState::UpdateRingGodel | ( | HexPoint | cell | ) |
Update only the ring godels of the neighbours of cell.
Definition at line 139 of file PatternState.cpp.
References RingGodel::AddColorToSlice(), StoneBoard::Const(), EMPTY, StoneBoard::GetColor(), HexAssert, PatternMatcherData::inverse_slice_godel, HexColorUtil::isBlackWhite(), ConstBoard::IsCell(), m_brd, m_data, m_ring_godel, Pattern::NUM_SLICES, and RingGodel::RemoveColorFromSlice().
StoneBoard& PatternState::m_brd [private] |
Definition at line 254 of file PatternState.hpp.
Referenced by Board(), CheckRotatedPattern(), ClearGodels(), CopyState(), Update(), and UpdateRingGodel().
const PatternMatcherData* PatternState::m_data [private] |
Definition at line 256 of file PatternState.hpp.
Referenced by CheckRotatedPattern(), Update(), and UpdateRingGodel().
RingGodel PatternState::m_ring_godel[BITSETSIZE] [private] |
Definition at line 263 of file PatternState.hpp.
Referenced by CheckRingGodel(), ClearGodels(), CopyState(), MatchOnCell(), Update(), and UpdateRingGodel().
int PatternState::m_slice_godel[BITSETSIZE][BLACK_AND_WHITE][Pattern::NUM_SLICES] [private] |
Definition at line 261 of file PatternState.hpp.
Referenced by CheckRotatedSlices(), ClearGodels(), CopyState(), and Update().
Statistics PatternState::m_statistics [mutable, private] |
Definition at line 265 of file PatternState.hpp.
Referenced by CheckRingGodel(), CheckRotatedPattern(), CheckRotatedSlices(), ClearPatternCheckStats(), and DumpPatternCheckStats().
int PatternState::m_update_radius [private] |
See UpdateRadius().
Definition at line 259 of file PatternState.hpp.
Referenced by CopyState(), SetUpdateRadius(), Update(), and UpdateRadius().