Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

PatternState Class Reference

Tracks pattern state info on a board. More...

#include <PatternState.hpp>

List of all members.

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 StoneBoardBoard () const
 Returns board state is tracking.
StoneBoardBoard ()
 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

StoneBoardm_brd
const PatternMatcherDatam_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

Detailed Description

Tracks pattern state info on a board.

Definition at line 135 of file PatternState.hpp.


Member Enumeration Documentation

Options controlling pattern matching behavoir at a cell.

Enumerator:
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.


Constructor & Destructor Documentation

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.


Member Function Documentation

StoneBoard & PatternState::Board (  )  [inline]

Returns board state is tracking.

Definition at line 302 of file PatternState.hpp.

References m_brd.

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]
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 (  ) 
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.

Todo:
Can we switch hits to be a map instead of a vector? Will a map be too slow?

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  ) 
void PatternState::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.

Note:
if Pattern::NUM_SLICES != 6, this won't work!! This also relies on the fact that slice 3 is opposite 0, 4 opposite 1, etc.

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().


Member Data Documentation

Definition at line 256 of file PatternState.hpp.

Referenced by CheckRotatedPattern(), Update(), and UpdateRingGodel().

Definition at line 261 of file PatternState.hpp.

Referenced by CheckRotatedSlices(), ClearGodels(), CopyState(), and Update().

See UpdateRadius().

Definition at line 259 of file PatternState.hpp.

Referenced by CopyState(), SetUpdateRadius(), Update(), and UpdateRadius().


The documentation for this class was generated from the following files:


6 Jan 2011 Doxygen 1.6.3