Patterns on a Hex board. More...
#include <Pattern.hpp>
Public Types | |
typedef int | slice_t [NUM_FEATURES] |
A slice is simply an array of features. | |
Public Member Functions | |
Pattern () | |
Creates an empty pattern. | |
std::string | serialize () const |
Returns a string of the pattern in encoded form. | |
bool | unserialize (std::string code) |
Parses a pattern from an encoded string. | |
int | getFlags () const |
Returns the pattern's flags. | |
std::string | getName () const |
Returns the pattern's name. | |
void | setName (const std::string &s) |
Sets the name of this pattern. | |
char | getType () const |
Returns the pattern's type. | |
const std::vector< std::pair < int, int > > & | getMoves1 () const |
Returns the list of (slice, bit) pairs for moves defined in the marked field (f = 0 or 1). | |
const std::vector< std::pair < int, int > > & | getMoves2 () const |
int | getWeight () const |
Gets the weight for this pattern. | |
int | extension () const |
Gets the extension radius of this pattern. | |
const slice_t * | getData () const |
Returns pointer to pattern's slice data. | |
const PatternRingGodel & | RingGodel (int angle) const |
Returns the ring godel of this pattern rotated by angle slices. | |
void | flipColors () |
Flip the pattern's colors. | |
void | mirror () |
Mirrors pattern along x/y diagonal. | |
Static Public Member Functions | |
static void | LoadPatternsFromStream (std::istream &f, std::vector< Pattern > &out) |
Parses patterns from a given stream. | |
static void | LoadPatternsFromFile (const char *filename, std::vector< Pattern > &out) |
Load patterns from a file. | |
Static Public Attributes | |
static const int | MAX_EXTENSION = 3 |
This sets how far out patterns are allowed to extend. | |
static const int | HAS_MOVES1 = 0x01 |
Pattern encodes a move. | |
static const int | HAS_MOVES2 = 0x02 |
static const int | HAS_WEIGHT = 0x04 |
Pattern has a weight (used by MOHEX patterns). | |
static const int | NUM_SLICES = 6 |
Number of triangular slices. | |
static const int | FEATURE_CELLS = 0 |
Info stored in each slice. | |
static const int | FEATURE_BLACK = 1 |
static const int | FEATURE_WHITE = 2 |
static const int | FEATURE_MARKED1 = 3 |
static const int | FEATURE_MARKED2 = 4 |
static const int | NUM_FEATURES = 5 |
Pattern Types. | |
static const char | UNKNOWN = ' ' |
Unknown type. | |
static const char | DEAD = 'd' |
Marks that the cell the pattern is centered on is dead. | |
static const char | CAPTURED = 'c' |
Marks that the cell the pattern is centered on is captured. | |
static const char | PERMANENTLY_INFERIOR = 'p' |
Marks a permanently inferior cell. | |
static const char | MUTUAL_FILLIN = 'u' |
Mutual fillin. | |
static const char | VULNERABLE = 'v' |
Marks a vulnerable cell. | |
static const char | REVERSIBLE = 'r' |
Marks a reversible cell. | |
static const char | DOMINATED = '!' |
Marks a dominated cell. | |
static const char | MOHEX = 'm' |
A mohex pattern. | |
static const char | SHIFT = 's' |
A mohex pattern. | |
Private Member Functions | |
void | compute_ring_godel () |
Compute the ring godel codes. | |
Private Attributes | |
char | m_type |
Pattern type. | |
std::string | m_name |
Name of the pattern. | |
int | m_flags |
Flags. | |
std::vector< std::pair< int, int > > | m_moves1 |
(slice, bit) pairs of cells in FEATURE_MARKED1. | |
std::vector< std::pair< int, int > > | m_moves2 |
(slice, bit) pairs of cells in FEATURE_MARKED2. | |
int | m_weight |
MoHex pattern weight. | |
slice_t | m_slice [NUM_SLICES] |
Data for each slice. | |
int | m_extension |
How far out the pattern extends. | |
PatternRingGodel | m_ring_godel [NUM_SLICES] |
One RingGodel for each rotation of the pattern. |
Patterns on a Hex board.
Patterns are centered around a cell, and are encoded such that they can be rotated with minimal computation.
These patterns can only be detected on a PatternBoard.
Used by:
Definition at line 91 of file Pattern.hpp.
typedef int Pattern::slice_t[NUM_FEATURES] |
A slice is simply an array of features.
Definition at line 174 of file Pattern.hpp.
Pattern::Pattern | ( | ) |
Creates an empty pattern.
Type is set to UNKNOWN.
Definition at line 12 of file Pattern.cpp.
References m_slice.
void Pattern::compute_ring_godel | ( | ) | [private] |
Compute the ring godel codes.
Definition at line 202 of file Pattern.cpp.
References PatternRingGodel::AddSliceToMask(), BLACK, EMPTY, FEATURE_BLACK, FEATURE_CELLS, FEATURE_WHITE, m_ring_godel, m_slice, NUM_SLICES, PatternRingGodel::SetEmpty(), RingGodel::SetSliceToColor(), and WHITE.
Referenced by flipColors(), mirror(), and unserialize().
int Pattern::extension | ( | ) | const [inline] |
Gets the extension radius of this pattern.
Definition at line 366 of file Pattern.hpp.
References m_extension.
Referenced by PatternState::CheckRotatedPattern().
void Pattern::flipColors | ( | ) |
Flip the pattern's colors.
Definition at line 124 of file Pattern.cpp.
References compute_ring_godel(), FEATURE_BLACK, FEATURE_WHITE, m_slice, and NUM_SLICES.
Referenced by IcePatternSet::LoadPatterns(), and HexUctSharedPolicy::LoadPlayPatterns().
const Pattern::slice_t * Pattern::getData | ( | ) | const [inline] |
Returns pointer to pattern's slice data.
Definition at line 338 of file Pattern.hpp.
References m_slice.
Referenced by PatternState::CheckRotatedSlices().
int Pattern::getFlags | ( | ) | const [inline] |
Returns the pattern's flags.
Definition at line 328 of file Pattern.hpp.
References m_flags.
Referenced by PatternState::CheckRotatedPattern().
const std::vector< std::pair< int, int > > & Pattern::getMoves1 | ( | ) | const [inline] |
Returns the list of (slice, bit) pairs for moves defined in the marked field (f = 0 or 1).
Definition at line 348 of file Pattern.hpp.
References HAS_MOVES1, HexAssert, m_flags, and m_moves1.
Referenced by PatternState::CheckRotatedPattern().
const std::vector< std::pair< int, int > > & Pattern::getMoves2 | ( | ) | const [inline] |
Definition at line 354 of file Pattern.hpp.
References HAS_MOVES2, HexAssert, m_flags, and m_moves2.
Referenced by PatternState::CheckRotatedPattern().
std::string Pattern::getName | ( | ) | const [inline] |
char Pattern::getType | ( | ) | const [inline] |
Returns the pattern's type.
Definition at line 333 of file Pattern.hpp.
References m_type.
Referenced by IcePatternSet::LoadPatterns(), and HexUctSharedPolicy::LoadPlayPatterns().
int Pattern::getWeight | ( | ) | const [inline] |
Gets the weight for this pattern.
Definition at line 360 of file Pattern.hpp.
References HAS_WEIGHT, HexAssert, m_flags, and m_weight.
void Pattern::LoadPatternsFromFile | ( | const char * | filename, | |
std::vector< Pattern > & | out | |||
) | [static] |
Load patterns from a file.
Definition at line 277 of file Pattern.cpp.
References LoadPatternsFromStream(), and LogWarning().
Referenced by VCBuilder::LoadCapturedSetPatterns(), IcePatternSet::LoadPatterns(), and HexUctSharedPolicy::LoadPlayPatterns().
void Pattern::LoadPatternsFromStream | ( | std::istream & | f, | |
std::vector< Pattern > & | out | |||
) | [static] |
Parses patterns from a given stream.
Pattern names are assumed to come before the encoding and are between '[' and '/' characters (this comes from Jack's pattern file format).
A mirrored copy of a pattern is stored if two names are encountered before the pattern string. No checking is done to determine if a mirror is really necessary.
The pattern encoding is detected by any character in the first column and is assumed to occupy exactly a single line.
So, to create your own pattern file, use something like this:
| ... | | [name1/] | [name2/] | pattern encoding; | | ...
Notice the names are between [ and / symbols and do not start in the first column. The pattern encoding, however, does start in the first column (and is the ONLY thing starting in the first column).
This is temporary. :-)
If you want, you can add a picture of the pattern. Here is an example pattern from our pattern file:
| | B B | B * ! [31/0] | | B * ! | B B [31m/0] | |!:1,0,0,1;1,1,0,0;1,1,0,0;1,1,0,0;0,0,0,0;0,0,0,0; |
This defines a pattern with name "31" and its mirror "31m".
Definition at line 227 of file Pattern.cpp.
References CAPTURED, DEAD, DOMINATED, mirror(), MOHEX, MUTUAL_FILLIN, PERMANENTLY_INFERIOR, REVERSIBLE, setName(), SHIFT, unserialize(), and VULNERABLE.
Referenced by LoadPatternsFromFile().
void Pattern::mirror | ( | ) |
Mirrors pattern along x/y diagonal.
Definition at line 135 of file Pattern.cpp.
References compute_ring_godel(), HexPointUtil::DeltaX(), HexPointUtil::DeltaY(), FEATURE_MARKED1, FEATURE_MARKED2, m_moves1, m_moves2, m_slice, MAX_EXTENSION, NUM_DIRECTIONS, NUM_FEATURES, and NUM_SLICES.
Referenced by LoadPatternsFromStream().
const PatternRingGodel & Pattern::RingGodel | ( | int | angle | ) | const [inline] |
Returns the ring godel of this pattern rotated by angle slices.
Definition at line 371 of file Pattern.hpp.
References m_ring_godel.
Referenced by PatternState::CheckRingGodel(), and HashedPatternSet::hash().
std::string Pattern::serialize | ( | ) | const |
Returns a string of the pattern in encoded form.
Definition at line 23 of file Pattern.cpp.
References m_slice, m_type, NUM_FEATURES, and NUM_SLICES.
Referenced by operator<<().
void Pattern::setName | ( | const std::string & | s | ) | [inline] |
Sets the name of this pattern.
Definition at line 343 of file Pattern.hpp.
References m_name.
Referenced by LoadPatternsFromStream().
bool Pattern::unserialize | ( | std::string | code | ) |
Parses a pattern from an encoded string.
Definition at line 37 of file Pattern.cpp.
References compute_ring_godel(), FEATURE_BLACK, FEATURE_CELLS, FEATURE_MARKED1, FEATURE_MARKED2, FEATURE_WHITE, PatternUtil::GetExtensionFromGodel(), HAS_MOVES1, HAS_MOVES2, HAS_WEIGHT, HexAssert, BitsetUtil::IsSubsetOf(), m_extension, m_flags, m_moves1, m_moves2, m_slice, m_type, m_weight, MAX_EXTENSION, MOHEX, NUM_FEATURES, NUM_SLICES, and SHIFT.
Referenced by LoadPatternsFromStream().
const char Pattern::CAPTURED = 'c' [static] |
Marks that the cell the pattern is centered on is captured.
Captured patterns denote a strategy to make this cell and any cells in MARKED2 as captured.
Definition at line 128 of file Pattern.hpp.
Referenced by IcePatternSet::LoadPatterns(), and LoadPatternsFromStream().
const char Pattern::DEAD = 'd' [static] |
Marks that the cell the pattern is centered on is dead.
Definition at line 122 of file Pattern.hpp.
Referenced by IcePatternSet::LoadPatterns(), and LoadPatternsFromStream().
const char Pattern::DOMINATED = '!' [static] |
Marks a dominated cell.
MARKED1 holds its killer.
Definition at line 146 of file Pattern.hpp.
Referenced by IcePatternSet::LoadPatterns(), and LoadPatternsFromStream().
const int Pattern::FEATURE_BLACK = 1 [static] |
Definition at line 167 of file Pattern.hpp.
Referenced by PatternState::CheckRotatedSlices(), compute_ring_godel(), flipColors(), and unserialize().
const int Pattern::FEATURE_CELLS = 0 [static] |
Info stored in each slice.
Definition at line 166 of file Pattern.hpp.
Referenced by PatternState::CheckRotatedSlices(), compute_ring_godel(), and unserialize().
const int Pattern::FEATURE_MARKED1 = 3 [static] |
Definition at line 169 of file Pattern.hpp.
Referenced by mirror(), and unserialize().
const int Pattern::FEATURE_MARKED2 = 4 [static] |
Definition at line 170 of file Pattern.hpp.
Referenced by mirror(), and unserialize().
const int Pattern::FEATURE_WHITE = 2 [static] |
Definition at line 168 of file Pattern.hpp.
Referenced by PatternState::CheckRotatedSlices(), compute_ring_godel(), flipColors(), and unserialize().
const int Pattern::HAS_MOVES1 = 0x01 [static] |
Pattern encodes a move.
Definition at line 102 of file Pattern.hpp.
Referenced by PatternState::CheckRotatedPattern(), getMoves1(), and unserialize().
const int Pattern::HAS_MOVES2 = 0x02 [static] |
Definition at line 103 of file Pattern.hpp.
Referenced by PatternState::CheckRotatedPattern(), getMoves2(), and unserialize().
const int Pattern::HAS_WEIGHT = 0x04 [static] |
Pattern has a weight (used by MOHEX patterns).
Definition at line 106 of file Pattern.hpp.
Referenced by getWeight(), and unserialize().
int Pattern::m_extension [private] |
How far out the pattern extends.
Definition at line 310 of file Pattern.hpp.
Referenced by extension(), and unserialize().
int Pattern::m_flags [private] |
Flags.
Definition at line 295 of file Pattern.hpp.
Referenced by getFlags(), getMoves1(), getMoves2(), getWeight(), and unserialize().
std::vector<std::pair<int, int> > Pattern::m_moves1 [private] |
(slice, bit) pairs of cells in FEATURE_MARKED1.
Definition at line 298 of file Pattern.hpp.
Referenced by getMoves1(), mirror(), and unserialize().
std::vector<std::pair<int, int> > Pattern::m_moves2 [private] |
(slice, bit) pairs of cells in FEATURE_MARKED2.
Definition at line 301 of file Pattern.hpp.
Referenced by getMoves2(), mirror(), and unserialize().
std::string Pattern::m_name [private] |
Name of the pattern.
Definition at line 292 of file Pattern.hpp.
PatternRingGodel Pattern::m_ring_godel[NUM_SLICES] [private] |
One RingGodel for each rotation of the pattern.
Definition at line 313 of file Pattern.hpp.
Referenced by compute_ring_godel(), and RingGodel().
slice_t Pattern::m_slice[NUM_SLICES] [private] |
Data for each slice.
Definition at line 307 of file Pattern.hpp.
Referenced by compute_ring_godel(), flipColors(), getData(), mirror(), Pattern(), serialize(), and unserialize().
char Pattern::m_type [private] |
Pattern type.
Definition at line 289 of file Pattern.hpp.
Referenced by getType(), serialize(), and unserialize().
int Pattern::m_weight [private] |
MoHex pattern weight.
Definition at line 304 of file Pattern.hpp.
Referenced by getWeight(), and unserialize().
const int Pattern::MAX_EXTENSION = 3 [static] |
This sets how far out patterns are allowed to extend.
Value must be >= 1 and <= 7.
Definition at line 97 of file Pattern.hpp.
Referenced by BenzeneHtpEngine::CmdEncodePattern(), ConstBoard::ComputeNeighbours(), PatternUtil::GetExtensionFromGodel(), PatternMatcherData::Initialize(), mirror(), ConstBoard::Nbs(), PatternState::SetUpdateRadius(), and unserialize().
const char Pattern::MOHEX = 'm' [static] |
A mohex pattern.
These patterns are used during the random playout phase of an UCT search.
Definition at line 150 of file Pattern.hpp.
Referenced by LoadPatternsFromStream(), HexUctSharedPolicy::LoadPlayPatterns(), and unserialize().
const char Pattern::MUTUAL_FILLIN = 'u' [static] |
Mutual fillin.
MARKED1 is fillin for one player, MARKED2 is fillin for other, and cell itself can be assigned to either.
Definition at line 136 of file Pattern.hpp.
Referenced by IcePatternSet::LoadPatterns(), and LoadPatternsFromStream().
const int Pattern::NUM_FEATURES = 5 [static] |
Definition at line 171 of file Pattern.hpp.
Referenced by mirror(), serialize(), and unserialize().
const int Pattern::NUM_SLICES = 6 [static] |
Number of triangular slices.
Each slice is rooted at a neighbour of the center cell. Should be 6 (one for each direction in HexDirection).
Definition at line 163 of file Pattern.hpp.
Referenced by PatternState::CheckRotatedSlices(), BenzeneHtpEngine::CmdEncodePattern(), compute_ring_godel(), flipColors(), PatternMatcherData::GetRotatedMove(), RingGodel::GlobalData::GlobalData(), HashedPatternSet::hash(), PatternMatcherData::Initialize(), mirror(), serialize(), unserialize(), PatternState::Update(), PatternState::UpdateRingGodel(), and RingGodel::ValidGodelData::ValidGodelData().
const char Pattern::PERMANENTLY_INFERIOR = 'p' [static] |
Marks a permanently inferior cell.
MARKED2 holds its carrier.
Definition at line 132 of file Pattern.hpp.
Referenced by IcePatternSet::LoadPatterns(), and LoadPatternsFromStream().
const char Pattern::REVERSIBLE = 'r' [static] |
Marks a reversible cell.
MARKED1 holds its reverser.
Definition at line 143 of file Pattern.hpp.
Referenced by IcePatternSet::LoadPatterns(), and LoadPatternsFromStream().
const char Pattern::SHIFT = 's' [static] |
A mohex pattern.
These patterns are used during the random playout phase of an UCT search.
Definition at line 154 of file Pattern.hpp.
Referenced by LoadPatternsFromStream(), and unserialize().
const char Pattern::UNKNOWN = ' ' [static] |
Unknown type.
Set in Pattern(), but should not appear in a defined pattern.
Definition at line 119 of file Pattern.hpp.
const char Pattern::VULNERABLE = 'v' [static] |
Marks a vulnerable cell.
MARKED1 holds its killer, and MARKED2 holds its carrier.
Definition at line 140 of file Pattern.hpp.
Referenced by IcePatternSet::LoadPatterns(), and LoadPatternsFromStream().