#include <GoUctPatterns.h>
See Modification of UCT with Patterns in Monte-Carlo Go.
The move is always in the center of the pattern or at the middle edge point (lower line) for edge patterns. The patterns are matched for both colors, unless specified otherwise. Notation:
O White x = Black or Empty X = Black o = White or Empty . = Empty B = Black to Play ? = Don't care W = White to Play
Patterns for Hane.
True is returned if any pattern is matched.
X O X X O . X O ? X O O . . . . . . X . . . . . ? ? ? ? . ? ? . ? ? . ? B
Patterns for Cut1.
True is returned if the first pattern is matched, but not the next two.
X O ? X O ? X O ? O . ? O . O O . . ? ? ? ? . ? ? O ?
Pattern for Cut2.
? X ? O . O x x x
Pattern for Edge.
True is returned if any pattern is matched.
X . ? ? X ? ? X O ? X O ? X O O . ? o . O ? . ? B ? . o W O . X W
Definition at line 62 of file GoUctPatterns.h.
Public Member Functions | |
GoUctPatterns (const BOARD &bd) | |
bool | MatchAny (SgPoint p) const |
Match any of the patterns. | |
Private Types | |
typedef SgArray< bool, GOUCT_POWER3_5 > | GoUctEdgePatternTable |
See m_edgeTable. | |
typedef SgArray< bool, GOUCT_POWER3_8 > | GoUctPatternTable |
See m_table. | |
Private Member Functions | |
bool | MatchAnyCenter (SgPoint p) const |
Match any of the center patterns. | |
bool | MatchAnyEdge (SgPoint p) const |
Match any of the edge patterns. | |
Static Private Member Functions | |
static bool | CheckCut1 (const GoBoard &bd, SgPoint p, SgBlackWhite c, int cDir, int otherDir) |
static bool | CheckCut2 (const GoBoard &bd, SgPoint p, const SgBlackWhite c, int cDir, int otherDir) |
static bool | CheckHane1 (const GoBoard &bd, SgPoint p, SgBlackWhite c, SgBlackWhite opp, int cDir, int otherDir) |
static int | CodeOf8Neighbors (const BOARD &bd, SgPoint p) |
static int | CodeOfEdgeNeighbors (const BOARD &bd, SgPoint p) |
static int | EdgeDirection (GoBoard &bd, SgPoint p, int index) |
static int | EBWCodeOfPoint (const BOARD &bd, SgPoint p) |
static int | FindDir (const GoBoard &bd, SgPoint p, SgBlackWhite c) |
Find direction of a neighboring stone in color c. | |
static void | InitCenterPatternTable (SgBWArray< GoUctPatternTable > &table) |
static void | InitEdgePatternTable (SgBWArray< GoUctEdgePatternTable > &edgeTable) |
static bool | MatchCut (const GoBoard &bd, SgPoint p) |
static bool | MatchEdge (const GoBoard &bd, SgPoint p, const int nuBlack, const int nuWhite) |
static bool | MatchHane (const GoBoard &bd, SgPoint p, const int nuBlack, const int nuWhite) |
static bool | MatchAnyPattern (const GoBoard &bd, SgPoint p) |
Procedural matching function - used to initialize the table. | |
static int | OtherDir (int dir) |
static int | SetupCodedEdgePosition (GoBoard &bd, int code) |
static int | SetupCodedPosition (GoBoard &bd, int code) |
Private Attributes | |
const BOARD & | m_bd |
SgBWArray< GoUctPatternTable > | m_table |
lookup table for 8-neighborhood of a move candidate | |
SgBWArray< GoUctEdgePatternTable > | m_edgeTable |
lookup table on the edge of board | |
Static Private Attributes | |
static const int | GOUCT_POWER3_5 = 3 * 3 * 3 * 3 * 3 |
3^5 = size of edge pattern table | |
static const int | GOUCT_POWER3_8 = 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 |
3^8 = size of center pattern table. |
typedef SgArray<bool, GOUCT_POWER3_5> GoUctPatterns< BOARD >::GoUctEdgePatternTable [private] |
typedef SgArray<bool, GOUCT_POWER3_8> GoUctPatterns< BOARD >::GoUctPatternTable [private] |
GoUctPatterns< BOARD >::GoUctPatterns | ( | const BOARD & | bd | ) |
Definition at line 139 of file GoUctPatterns.h.
References GoUctPatterns< BOARD >::InitCenterPatternTable(), GoUctPatterns< BOARD >::InitEdgePatternTable(), GoUctPatterns< BOARD >::m_edgeTable, and GoUctPatterns< BOARD >::m_table.
bool GoUctPatterns< BOARD >::CheckCut1 | ( | const GoBoard & | bd, | |
SgPoint | p, | |||
SgBlackWhite | c, | |||
int | cDir, | |||
int | otherDir | |||
) | [static, private] |
Definition at line 160 of file GoUctPatterns.h.
References GoBoard::IsColor(), SG_ASSERT_BW, and SgOppBW().
Referenced by GoUctPatterns< BOARD >::MatchCut().
bool GoUctPatterns< BOARD >::CheckCut2 | ( | const GoBoard & | bd, | |
SgPoint | p, | |||
const SgBlackWhite | c, | |||
int | cDir, | |||
int | otherDir | |||
) | [static, private] |
Definition at line 169 of file GoUctPatterns.h.
References GoBoard::IsColor(), SG_ASSERT, SG_ASSERT_BW, and SgOppBW().
Referenced by GoUctPatterns< BOARD >::MatchCut().
bool GoUctPatterns< BOARD >::CheckHane1 | ( | const GoBoard & | bd, | |
SgPoint | p, | |||
SgBlackWhite | c, | |||
SgBlackWhite | opp, | |||
int | cDir, | |||
int | otherDir | |||
) | [static, private] |
Definition at line 147 of file GoUctPatterns.h.
References GoBoard::IsColor(), and GoBoard::IsEmpty().
Referenced by GoUctPatterns< BOARD >::MatchHane().
int GoUctPatterns< BOARD >::CodeOf8Neighbors | ( | const BOARD & | bd, | |
SgPoint | p | |||
) | [static, private] |
Definition at line 190 of file GoUctPatterns.h.
References GoUctPatterns< BOARD >::EBWCodeOfPoint(), GoUctPatterns< BOARD >::GOUCT_POWER3_8, SG_ASSERT, SG_NS, and SG_WE.
Referenced by GoUctPatterns< BOARD >::MatchAnyCenter().
int GoUctPatterns< BOARD >::CodeOfEdgeNeighbors | ( | const BOARD & | bd, | |
SgPoint | p | |||
) | [static, private] |
Definition at line 207 of file GoUctPatterns.h.
References GoUctPatterns< BOARD >::EBWCodeOfPoint(), GoUctPatterns< BOARD >::GOUCT_POWER3_5, GoUctPatterns< BOARD >::OtherDir(), and SG_ASSERT.
Referenced by GoUctPatterns< BOARD >::MatchAnyEdge().
int GoUctPatterns< BOARD >::EBWCodeOfPoint | ( | const BOARD & | bd, | |
SgPoint | p | |||
) | [static, private] |
Definition at line 225 of file GoUctPatterns.h.
References BOOST_STATIC_ASSERT(), SG_ASSERT, SG_BLACK, SG_EMPTY, and SG_WHITE.
Referenced by GoUctPatterns< BOARD >::CodeOf8Neighbors(), and GoUctPatterns< BOARD >::CodeOfEdgeNeighbors().
int GoUctPatterns< BOARD >::EdgeDirection | ( | GoBoard & | bd, | |
SgPoint | p, | |||
int | index | |||
) | [static, private] |
Definition at line 235 of file GoUctPatterns.h.
References GoUctPatterns< BOARD >::OtherDir(), SG_ASSERT, and GoBoard::Up().
Referenced by GoUctPatterns< BOARD >::SetupCodedEdgePosition().
int GoUctPatterns< BOARD >::FindDir | ( | const GoBoard & | bd, | |
SgPoint | p, | |||
SgBlackWhite | c | |||
) | [static, private] |
Find direction of a neighboring stone in color c.
Definition at line 256 of file GoUctPatterns.h.
References GoBoard::IsColor(), SG_ASSERT, SG_NS, and SG_WE.
Referenced by GoUctPatterns< BOARD >::MatchHane().
void GoUctPatterns< BOARD >::InitCenterPatternTable | ( | SgBWArray< GoUctPatternTable > & | table | ) | [static, private] |
Definition at line 289 of file GoUctPatterns.h.
References GoUctPatterns< BOARD >::GOUCT_POWER3_8, GoUctPatterns< BOARD >::MatchAnyPattern(), SgPointUtil::Pt(), GoBoard::SetToPlay(), GoUctPatterns< BOARD >::SetupCodedPosition(), and GoBoard::Undo().
Referenced by GoUctPatterns< BOARD >::GoUctPatterns().
void GoUctPatterns< BOARD >::InitEdgePatternTable | ( | SgBWArray< GoUctEdgePatternTable > & | edgeTable | ) | [static, private] |
Definition at line 270 of file GoUctPatterns.h.
References GoUctPatterns< BOARD >::GOUCT_POWER3_5, GoUctPatterns< BOARD >::MatchAnyPattern(), SgPointUtil::Pt(), GoBoard::SetToPlay(), GoUctPatterns< BOARD >::SetupCodedEdgePosition(), and GoBoard::Undo().
Referenced by GoUctPatterns< BOARD >::GoUctPatterns().
bool GoUctPatterns< BOARD >::MatchAny | ( | SgPoint | p | ) | const |
Match any of the patterns.
Definition at line 508 of file GoUctPatterns.h.
References GoUctPatterns< BOARD >::m_bd, GoUctPatterns< BOARD >::MatchAnyCenter(), GoUctPatterns< BOARD >::MatchAnyEdge(), SG_BLACK, and SG_WHITE.
Referenced by GoUctCommands::CmdPatterns().
bool GoUctPatterns< BOARD >::MatchAnyCenter | ( | SgPoint | p | ) | const [private] |
Match any of the center patterns.
Definition at line 496 of file GoUctPatterns.h.
References GoUctPatterns< BOARD >::CodeOf8Neighbors(), GoUctPatterns< BOARD >::m_bd, and GoUctPatterns< BOARD >::m_table.
Referenced by GoUctPatterns< BOARD >::MatchAny().
bool GoUctPatterns< BOARD >::MatchAnyEdge | ( | SgPoint | p | ) | const [private] |
Match any of the edge patterns.
Definition at line 502 of file GoUctPatterns.h.
References GoUctPatterns< BOARD >::CodeOfEdgeNeighbors(), GoUctPatterns< BOARD >::m_bd, and GoUctPatterns< BOARD >::m_edgeTable.
Referenced by GoUctPatterns< BOARD >::MatchAny().
bool GoUctPatterns< BOARD >::MatchAnyPattern | ( | const GoBoard & | bd, | |
SgPoint | p | |||
) | [static, private] |
Procedural matching function - used to initialize the table.
Definition at line 526 of file GoUctPatterns.h.
References GoBoard::IsEmpty(), GoBoard::Line(), GoUctPatterns< BOARD >::MatchCut(), GoUctPatterns< BOARD >::MatchEdge(), GoUctPatterns< BOARD >::MatchHane(), GoBoard::NumNeighbors(), GoBoard::Pos(), SG_ASSERT, SG_BLACK, and SG_WHITE.
Referenced by GoUctPatterns< BOARD >::InitCenterPatternTable(), and GoUctPatterns< BOARD >::InitEdgePatternTable().
bool GoUctPatterns< BOARD >::MatchCut | ( | const GoBoard & | bd, | |
SgPoint | p | |||
) | [static, private] |
Definition at line 308 of file GoUctPatterns.h.
References GoUctPatterns< BOARD >::CheckCut1(), GoUctPatterns< BOARD >::CheckCut2(), GoBoard::GetColor(), GoBoard::Num8EmptyNeighbors(), GoBoard::NumDiagonals(), GoBoard::NumEmptyNeighbors(), GoBoard::NumNeighbors(), SG_EMPTY, SG_NS, SG_WE, and SgOppBW().
Referenced by GoUctPatterns< BOARD >::MatchAnyPattern().
bool GoUctPatterns< BOARD >::MatchEdge | ( | const GoBoard & | bd, | |
SgPoint | p, | |||
const int | nuBlack, | |||
const int | nuWhite | |||
) | [static, private] |
Definition at line 353 of file GoUctPatterns.h.
References GoBoard::GetColor(), GoBoard::NumDiagonals(), GoBoard::NumEmptyNeighbors(), GoBoard::NumNeighbors(), GoUctPatterns< BOARD >::OtherDir(), SG_BLACK, SG_EMPTY, SG_WHITE, SgOppBW(), GoBoard::ToPlay(), and GoBoard::Up().
Referenced by GoUctPatterns< BOARD >::MatchAnyPattern().
bool GoUctPatterns< BOARD >::MatchHane | ( | const GoBoard & | bd, | |
SgPoint | p, | |||
const int | nuBlack, | |||
const int | nuWhite | |||
) | [static, private] |
Definition at line 423 of file GoUctPatterns.h.
References GoUctPatterns< BOARD >::CheckHane1(), GoUctPatterns< BOARD >::FindDir(), GoBoard::GetColor(), GoBoard::IsColor(), GoBoard::IsEmpty(), GoBoard::NumDiagonals(), GoBoard::NumEmptyNeighbors(), GoUctPatterns< BOARD >::OtherDir(), SG_ASSERT, SG_BLACK, SG_EMPTY, SG_NS, SG_WE, SG_WHITE, SgOppBW(), and GoBoard::ToPlay().
Referenced by GoUctPatterns< BOARD >::MatchAnyPattern().
int GoUctPatterns< BOARD >::OtherDir | ( | int | dir | ) | [static, private] |
Definition at line 548 of file GoUctPatterns.h.
Referenced by GoUctPatterns< BOARD >::CodeOfEdgeNeighbors(), GoUctPatterns< BOARD >::EdgeDirection(), GoUctPatterns< BOARD >::MatchEdge(), and GoUctPatterns< BOARD >::MatchHane().
int GoUctPatterns< BOARD >::SetupCodedEdgePosition | ( | GoBoard & | bd, | |
int | code | |||
) | [static, private] |
Definition at line 556 of file GoUctPatterns.h.
References GoUctPatterns< BOARD >::EdgeDirection(), GoBoard::Play(), SgPointUtil::Pt(), and SG_EMPTY.
Referenced by GoUctPatterns< BOARD >::InitEdgePatternTable().
int GoUctPatterns< BOARD >::SetupCodedPosition | ( | GoBoard & | bd, | |
int | code | |||
) | [static, private] |
Definition at line 575 of file GoUctPatterns.h.
References SgNb8Iterator::Direction(), GoBoard::Play(), SgPointUtil::Pt(), and SG_EMPTY.
Referenced by GoUctPatterns< BOARD >::InitCenterPatternTable().
const int GoUctPatterns< BOARD >::GOUCT_POWER3_5 = 3 * 3 * 3 * 3 * 3 [static, private] |
3^5 = size of edge pattern table
Definition at line 72 of file GoUctPatterns.h.
Referenced by GoUctPatterns< BOARD >::CodeOfEdgeNeighbors(), and GoUctPatterns< BOARD >::InitEdgePatternTable().
const int GoUctPatterns< BOARD >::GOUCT_POWER3_8 = 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 [static, private] |
3^8 = size of center pattern table.
Definition at line 75 of file GoUctPatterns.h.
Referenced by GoUctPatterns< BOARD >::CodeOf8Neighbors(), and GoUctPatterns< BOARD >::InitCenterPatternTable().
const BOARD& GoUctPatterns< BOARD >::m_bd [private] |
Definition at line 83 of file GoUctPatterns.h.
Referenced by GoUctPatterns< BOARD >::MatchAny(), GoUctPatterns< BOARD >::MatchAnyCenter(), and GoUctPatterns< BOARD >::MatchAnyEdge().
SgBWArray<GoUctEdgePatternTable> GoUctPatterns< BOARD >::m_edgeTable [private] |
lookup table on the edge of board
Definition at line 89 of file GoUctPatterns.h.
Referenced by GoUctPatterns< BOARD >::GoUctPatterns(), and GoUctPatterns< BOARD >::MatchAnyEdge().
SgBWArray<GoUctPatternTable> GoUctPatterns< BOARD >::m_table [private] |
lookup table for 8-neighborhood of a move candidate
Definition at line 86 of file GoUctPatterns.h.
Referenced by GoUctPatterns< BOARD >::GoUctPatterns(), and GoUctPatterns< BOARD >::MatchAnyCenter().