Some of the functions that the board class as a template argument, such that they can be used with specialized variants of GoBoard that share only a sub-functionality.
Functions | |
void | AddNeighborBlocksOfColor (const GoBoard &bd, SgPoint p, SgBlackWhite color, SgVector< SgPoint > &neighbors) |
Add anchors of neighbor blocks to list. | |
void | AddWall (GoBoard &bd, SgBlackWhite color, SgPoint start, int length, int direction) |
Add wall of stones in color to the board. | |
GoPointList | AdjacentStones (const GoBoard &bd, SgPoint point) |
Get list of stones adjacent to a block. | |
void | AdjacentBlocks (const GoBoard &bd, SgPoint p, int maxLib, SgVector< SgPoint > *blocks) |
SgVector version of GoBoard::AdjacentBlocks. | |
void | BlocksAdjacentToPoints (const GoBoard &bd, const SgVector< SgPoint > &points, SgBlackWhite c, SgVector< SgPoint > *blocks) |
void | BlocksAdjacentToPoints (const GoBoard &bd, const SgPointSet &points, SgBlackWhite c, SgVector< SgPoint > *anchors) |
List the anchors of all blocks of color 'c' adjacent to the region consisting of 'points'. | |
bool | BlockIsAdjacentTo (const GoBoard &bd, SgPoint block, const SgPointSet &walls) |
SgPointArray< int > | CfgDistance (const GoBoard &bd, SgPoint p, int maxDist=std::numeric_limits< int >::max()) |
Compute the common fate graph distance from all points to a given point. | |
void | DumpBoard (const GoBoard &bd, std::ostream &out=SgDebug()) |
Write board including move history to stream. | |
void | ExpandToBlocks (const GoBoard &board, SgPointSet &pointSet) |
Add other stones of blocks to SgPointSet if one is in set. | |
void | DiagonalsOfColor (const GoBoard &bd, SgPoint p, int c, SgVector< SgPoint > *diagonals) |
Get diagonal points with a color. | |
bool | EndOfGame (const GoBoard &bd) |
Return whether the game is finished. | |
bool | GenerateIfLegal (const GoBoard &bd, SgPoint move, SgVector< SgPoint > *moves) |
Include move in list if it is legal. | |
void | GetCoordString (SgMove move, std::string *s, int boardSize) |
Convert the given move to human-readable coordinates. | |
bool | HasAdjacentBlocks (const GoBoard &bd, SgPoint p, int maxLib) |
Return whether block has at least one adjacent opponent block with at most maxLib liberties. | |
bool | IsHandicapPoint (SgGrid size, SgGrid col, SgGrid row) |
bool | IsSimpleEyeOfBlock (const GoBoard &bd, SgPoint lib, SgPoint blockAnchor, const SgVector< SgPoint > &eyes) |
Is lib a simple eye of block? Eyes is a list of other eye points, that do not need to be occupied for lib to be an eye. | |
bool | IsSnapback (const GoBoard &bd, SgPoint p) |
Check if the move just played on p was a snapback. | |
bool | ManySecondaryLibs (const GoBoard &bd, SgPoint block) |
SgSList< SgPoint, 4 > | NeighborsOfColor (const GoBoard &bd, SgPoint p, int c) |
Get adjacent points with a color. | |
void | NeighborsOfColor (const GoBoard &bd, SgPoint p, int c, SgVector< SgPoint > *neighbors) |
Get adjacent points with a color (SgVector version). | |
bool | PassWins (const GoBoard &bd, SgBlackWhite toPlay) |
Check if Tromp-Taylor rules and pass wins. | |
bool | PlayIfLegal (GoBoard &bd, SgPoint p, SgBlackWhite player) |
Play a move if legal. | |
void | ReduceToAnchors (const GoBoard &bd, SgVector< SgPoint > *stones) |
Keep only the anchor of each block in the list. | |
void | ReduceToAnchors (const GoBoard &bd, const SgVector< SgPoint > &stones, SgSList< SgPoint, SG_MAXPOINT > &anchors) |
Keep only the anchor of each block in the list. | |
void | RegionCode (const GoBoard &bd, const SgVector< SgPoint > ®ion, SgHashCode *c) |
Compute the hash code for region of this board position. | |
bool | RemainingChineseHandicap (const GoBoard &bd) |
Returns true iff during the first N moves of a Chinese handicap game. | |
float | ScoreSimpleEndPosition (const GoBoard &bd, float komi, bool noCheck=false) |
Score position with all stones safe and only simple eyes. | |
void | SharedLiberties (const GoBoard &bd, SgPoint block1, SgPoint block2, SgVector< SgPoint > *sharedLibs) |
Return all points that are liberties of both 'block1' and 'block2'. | |
void | SharedLibertyBlocks (const GoBoard &bd, SgPoint anchor, int maxLib, SgVector< SgPoint > *blocks) |
void | UndoAll (GoBoard &bd) |
Undo all moves or setup stones. | |
bool | AtLeastTwoSharedLibs (const GoBoard &bd, SgPoint block1, SgPoint block2) |
Return whether 'block1' and 'block2' have at least two shared liberties. | |
void | TestForChain (GoBoard &bd, SgPoint block, SgPoint block2, SgPoint lib, SgVector< SgPoint > *extended) |
bool | HasStonesOfBothColors (const GoBoard &bd, const SgVector< SgPoint > &stones) |
bool | MoveNotLegalOrAtari (GoBoard &bd, SgPoint move) |
Either move is not legal, or the block at move is in atari after the move. | |
bool | MoveLegalAndNotAtari (GoBoard &bd, SgPoint move) |
Move is legal and the block at move is not in atari after the move. | |
bool | ScorePosition (const GoBoard &bd, const SgPointSet &deadStones, float &score) |
Count score given the set of dead stones. | |
int | Stones (const GoBoard &bd, SgPoint p, SgPoint stones[]) |
Fill stones in an array. | |
bool | TwoPasses (const GoBoard &bd) |
Check if the last two moves were two passes in a row, the first pass by the current color to play, the second by the opponent. | |
SgPointSet | Lines (const GoBoard &bd, SgGrid from, SgGrid to) |
all points on lines [from. | |
SgRect | GetDirtyRegion (const GoBoard &bd, SgMove move, SgBlackWhite color, bool checklibs=false, bool premove=false) |
Which intersections were modified with the last move. | |
int | Approx2Libs (const GoBoard &board, SgPoint block, SgPoint p, SgBlackWhite color) |
Estimate second order liberties of point p for given block This is fast and approximate, may double count libs. | |
bool | ContainsAnchor (const SgPoint anchor[], const SgPoint p) |
Is p contained in anchor[] ? anchor[] must be terminated by END_POINT. | |
template<class BOARD> | |
SgPoint | FindNeighbor (const BOARD &bd, SgPoint p, SgEmptyBlackWhite c) |
Find a neighboring point in color c. | |
void | GetCoordString (const GoBoard &board, SgMove move, std::string *s) |
Convert the given move to human-readable coordinates. | |
template<class BOARD> | |
bool | IsCompletelySurrounded (const BOARD &bd, SgPoint p) |
Return if point is surrounded by one color and no adjacent block is in atari. | |
template<class BOARD> | |
bool | IsNeighborOfSome (const BOARD &bd, SgPoint p, SgPoint anchors[], SgBlackWhite toPlay) |
template<class BOARD> | |
bool | IsSimpleChain (const BOARD &bd, SgPoint block, SgPoint &other) |
Does block have two shared liberties with some other block? WARNING: for efficiency this checks only the first two liberties of the block. | |
bool | PlayIfLegal (GoBoard &bd, SgPoint p) |
Play a move for the current player if legal. | |
template<class BOARD> | |
bool | SelfAtari (const BOARD &bd, SgPoint p) |
Check if move would be self-atari. | |
template<class BOARD> | |
bool | SelfAtari (const BOARD &bd, SgPoint p, int &numStones) |
Same as above, but also compute number of stones put into selfatari. | |
template<class BOARD> | |
bool | SelfAtariForColor (const BOARD &bd, SgPoint p, SgBlackWhite toPlay) |
Check if move would be self-atari for given color. | |
template<class BOARD> | |
SgEmptyBlackWhite | ScorePoint (const BOARD &bd, SgPoint p, bool noCheck) |
Helper function used in ScoreSimpleEndPosition. | |
template<class BOARD> | |
float | ScoreSimpleEndPosition (const BOARD &bd, float komi, const SgBWSet &safe, bool noCheck, SgPointArray< SgEmptyBlackWhite > *scoreBoard) |
Score position with given safe stones and only simple eyes. | |
template<class BOARD> | |
float | TrompTaylorScore (const BOARD &bd, float komi, SgPointArray< SgEmptyBlackWhite > *scoreBoard=0) |
Compute the Tromp-Taylor-score for the current positions. | |
bool | ContainsAnchor (const SgPoint anchor[], const SgPoint p) |
Is p contained in anchor[] ? anchor[] must be terminated by END_POINT. | |
template<class BOARD> | |
SgPoint | FindNeighbor (const BOARD &bd, SgPoint p, SgEmptyBlackWhite c) |
Find a neighboring point in color c. | |
void | GetCoordString (const GoBoard &board, SgMove move, std::string *s) |
Convert the given move to human-readable coordinates. | |
template<class BOARD> | |
bool | IsCompletelySurrounded (const BOARD &bd, SgPoint p) |
Return if point is surrounded by one color and no adjacent block is in atari. | |
template<class BOARD> | |
bool | IsNeighborOfSome (const BOARD &bd, SgPoint p, SgPoint anchors[], SgBlackWhite toPlay) |
template<class BOARD> | |
bool | IsSimpleChain (const BOARD &bd, SgPoint block, SgPoint &other) |
Does block have two shared liberties with some other block? WARNING: for efficiency this checks only the first two liberties of the block. | |
bool | PlayIfLegal (GoBoard &bd, SgPoint p) |
Play a move for the current player if legal. | |
template<class BOARD> | |
SgEmptyBlackWhite | ScorePoint (const BOARD &bd, SgPoint p, bool noCheck) |
Helper function used in ScoreSimpleEndPosition. | |
template<class BOARD> | |
float | ScoreSimpleEndPosition (const BOARD &bd, float komi, const SgBWSet &safe, bool noCheck, SgPointArray< SgEmptyBlackWhite > *scoreBoard) |
Score position with given safe stones and only simple eyes. | |
template<class BOARD> | |
bool | SelfAtari (const BOARD &bd, SgPoint p) |
Check if move would be self-atari. | |
template<class BOARD> | |
bool | SelfAtariForColor (const BOARD &bd, SgPoint p, SgBlackWhite toPlay) |
Check if move would be self-atari for given color. | |
template<class BOARD> | |
bool | SelfAtari (const BOARD &bd, SgPoint p, int &numStones) |
Same as above, but also compute number of stones put into selfatari. | |
template<class BOARD> | |
float | TrompTaylorScore (const BOARD &bd, float komi, SgPointArray< SgEmptyBlackWhite > *scoreBoard) |
Compute the Tromp-Taylor-score for the current positions. |
void GoBoardUtil::AddNeighborBlocksOfColor | ( | const GoBoard & | bd, | |
SgPoint | p, | |||
SgBlackWhite | c, | |||
SgVector< SgPoint > & | neighbors | |||
) |
Add anchors of neighbor blocks to list.
Definition at line 83 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), SgVector< T >::Include(), GoBoard::IsColor(), SG_NS, and SG_WE.
void GoBoardUtil::AddWall | ( | GoBoard & | bd, | |
SgBlackWhite | color, | |||
SgPoint | start, | |||
int | length, | |||
int | direction | |||
) |
Add wall of stones in color to the board.
bd | ||
color | color of the wall. | |
start | Starting point for the wall. | |
length | number of stones in wall | |
direction | offset from one stone to next. e.g. direction = NS builds a North-South wall. can also build diagonal walls, e.g. by using direction = NS + WE, or even jumps. Precondition: all these squares must be empty, and playing on them must be legal. |
Definition at line 97 of file GoBoardUtil.cpp.
References GoBoard::Play().
GoPointList GoBoardUtil::AdjacentStones | ( | const GoBoard & | bd, | |
SgPoint | point | |||
) |
Get list of stones adjacent to a block.
Definition at line 110 of file GoBoardUtil.cpp.
References SgMarker::Clear(), GoBoard::GetStone(), GoBoard::IsValidPoint(), GoBoard::m_userMarker, SgMarker::NewMark(), GoBoard::Occupied(), SG_ASSERT, SG_NS, SG_UNUSED(), SG_WE, and SgOppBW().
Referenced by GoLadder::Ladder(), and GoLadder::PlayPreyMove().
void GoBoardUtil::AdjacentBlocks | ( | const GoBoard & | bd, | |
SgPoint | p, | |||
int | maxLib, | |||
SgVector< SgPoint > * | blocks | |||
) |
SgVector version of GoBoard::AdjacentBlocks.
Definition at line 138 of file GoBoardUtil.cpp.
References GoBoard::AdjacentBlocks(), SgVector< T >::SetTo(), SG_ASSERT, and SG_MAXPOINT.
Referenced by GoGtpEngine::CmdPointInfo().
void GoBoardUtil::BlocksAdjacentToPoints | ( | const GoBoard & | bd, | |
const SgVector< SgPoint > & | points, | |||
SgBlackWhite | c, | |||
SgVector< SgPoint > * | blocks | |||
) |
Definition at line 147 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), SgMarker::Clear(), SgMarker::Include(), GoBoard::IsColor(), GoBoard::m_userMarker, SgMarker::NewMark(), GoBoard::NumNeighbors(), SgVector< T >::SetTo(), SG_MAXPOINT, SG_NS, SG_UNUSED(), and SG_WE.
Referenced by GoRegionUtil::StaticIs1VitalAndConnected().
void GoBoardUtil::BlocksAdjacentToPoints | ( | const GoBoard & | bd, | |
const SgPointSet & | points, | |||
SgBlackWhite | c, | |||
SgVector< SgPoint > * | blocks | |||
) |
List the anchors of all blocks of color 'c' adjacent to the region consisting of 'points'.
Definition at line 184 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), SgMarker::Clear(), SgMarker::Include(), GoBoard::IsColor(), GoBoard::m_userMarker, SgMarker::NewMark(), GoBoard::NumNeighbors(), SgVector< T >::SetTo(), SG_ASSERT, SG_MAXPOINT, SG_NS, SG_UNUSED(), and SG_WE.
bool GoBoardUtil::BlockIsAdjacentTo | ( | const GoBoard & | bd, | |
SgPoint | block, | |||
const SgPointSet & | walls | |||
) |
Definition at line 223 of file GoBoardUtil.cpp.
References SgPointSet::Contains(), SG_NS, and SG_WE.
SgPointArray< int > GoBoardUtil::CfgDistance | ( | const GoBoard & | bd, | |
SgPoint | p, | |||
int | maxDist = std::numeric_limits< int >::max() | |||
) |
Compute the common fate graph distance from all points to a given point.
The common fate graph distance ist the shortest path between points with an edge cost of 0 for edges between stones of the same block, and an edge cost of 1 otherwise.
bd | ||
p | ||
maxDist | The maximum distance to search (points with a distance > maxDist will get the value numeric_limits<int>::max()) |
Definition at line 238 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), CfgDistanceCheck(), SgSList< T, SIZE >::Length(), GoBoard::Occupied(), SgSList< T, SIZE >::PushBack(), SG_NS, and SG_WE.
Referenced by GoGtpExtraCommands::CmdCfgDistance().
Write board including move history to stream.
This function is intended for printing the current board state for debugging or after a crash. The move history is written in SGF format.
Definition at line 280 of file GoBoardUtil.cpp.
References GoSetup::IsEmpty(), GoSetup::m_player, GoSetup::m_stones, PointToSgfString(), GoBoard::Setup(), SG_BLACK, SG_PROPPOINTFMT_GO, and GoBoard::Size().
Referenced by GoGtpEngine::DumpState().
void GoBoardUtil::ExpandToBlocks | ( | const GoBoard & | board, | |
SgPointSet & | pointSet | |||
) |
Add other stones of blocks to SgPointSet if one is in set.
Definition at line 323 of file GoBoardUtil.cpp.
References GoBoard::All(), GoBoard::Occupied(), SG_ASSERT, SG_BLACK, SG_WHITE, GoBoard::Size(), and SgPointSet::SubsetOf().
Referenced by GoSafetyUtil::AddToSafe().
void GoBoardUtil::DiagonalsOfColor | ( | const GoBoard & | bd, | |
SgPoint | p, | |||
int | c, | |||
SgVector< SgPoint > * | diagonals | |||
) |
Get diagonal points with a color.
bd | The board. | |
p | The point. | |
c | The color. | |
diagonals | Resulting point list. Will be cleared before adding the points. |
Definition at line 346 of file GoBoardUtil.cpp.
References SgVector< T >::Clear(), GoBoard::IsColor(), SgVector< T >::PushBack(), SG_NS, and SG_WE.
bool GoBoardUtil::EndOfGame | ( | const GoBoard & | bd | ) |
Return whether the game is finished.
(two or three consecutive pass moves). For the choice of two or three:
Definition at line 360 of file GoBoardUtil.cpp.
References GoBoard::Move(), GoBoard::MoveNumber(), GoBoard::Rules(), SG_PASS, SgOppBW(), GoBoard::ToPlay(), and GoRules::TwoPassesEndGame().
Referenced by GoGameRecord::EndOfGame().
Include move in list if it is legal.
Definition at line 382 of file GoBoardUtil.cpp.
References GoBoard::IsLegal().
void GoBoardUtil::GetCoordString | ( | SgMove | move, | |
std::string * | s, | |||
int | boardSize | |||
) |
Convert the given move to human-readable coordinates.
(lower left A1 to upper right T19, leaving out column I).
Definition at line 394 of file GoBoardUtil.cpp.
References SgPointUtil::Col(), SgPointUtil::Row(), SG_ASSERT, SG_COUPONMOVE, SG_NULLMOVE, and SG_PASS.
Referenced by GetCoordString().
Return whether block has at least one adjacent opponent block with at most maxLib liberties.
Definition at line 414 of file GoBoardUtil.cpp.
References GoBoard::GetStone(), GoBoard::Occupied(), SG_ASSERT, and SgOppBW().
bool GoBoardUtil::IsSimpleEyeOfBlock | ( | const GoBoard & | bd, | |
SgPoint | lib, | |||
SgPoint | blockAnchor, | |||
const SgVector< SgPoint > & | eyes | |||
) |
Is lib a simple eye of block? Eyes is a list of other eye points, that do not need to be occupied for lib to be an eye.
Precondition (not tested): lib is surrounded by stones of color.
Definition at line 453 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), SgVector< T >::Contains(), GoBoard::GetStone(), GoBoard::IsBorder(), GoBoard::IsColor(), GoBoard::Line(), SG_NS, and SG_WE.
Check if the move just played on p was a snapback.
A snapback is a single stone in atari which can be captured by a legal move, if the move creates a block with more than one stone in atari.
Definition at line 484 of file GoBoardUtil.cpp.
References GoModBoard::Board(), GoBoard::GetStone(), GoBoard::InAtari(), GoBoard::IsSingleStone(), GoBoard::IsValidPoint(), GoBoard::Occupied(), PlayIfLegal(), SG_ASSERT, SgOppBW(), GoBoard::TheLiberty(), and GoBoard::Undo().
Definition at line 508 of file GoBoardUtil.cpp.
References SgMarker::Clear(), and SgMarker::NewMark().
Get adjacent points with a color.
bd | The board. | |
p | The point. | |
c | The color. |
Definition at line 534 of file GoBoardUtil.cpp.
References GoBoard::IsColor(), SgSList< T, SIZE >::PushBack(), SG_NS, and SG_WE.
Referenced by GoLadder::Ladder(), and GoLadder::PlayPreyMove().
void GoBoardUtil::NeighborsOfColor | ( | const GoBoard & | bd, | |
SgPoint | p, | |||
int | c, | |||
SgVector< SgPoint > * | neighbors | |||
) |
Get adjacent points with a color (SgVector version).
bd | The board. | |
p | The point. | |
c | The color. | |
neighbors | Resulting point list. Will be cleared before adding the points. |
Definition at line 549 of file GoBoardUtil.cpp.
References SgVector< T >::Clear(), GoBoard::IsColor(), SgVector< T >::PushBack(), SG_NS, and SG_WE.
bool GoBoardUtil::PassWins | ( | const GoBoard & | bd, | |
SgBlackWhite | toPlay | |||
) |
Check if Tromp-Taylor rules and pass wins.
Definition at line 563 of file GoBoardUtil.cpp.
References GoRules::CaptureDead(), GoBoard::GetLastMove(), GoRules::JapaneseScoring(), GoRules::Komi(), GoBoard::Rules(), SG_BLACK, SG_PASS, SG_WHITE, GoKomi::ToFloat(), GoBoard::ToPlay(), and TrompTaylorScore().
bool GoBoardUtil::PlayIfLegal | ( | GoBoard & | bd, | |
SgPoint | p, | |||
SgBlackWhite | player | |||
) |
Play a move if legal.
bd | The board. | |
p | Move to play; SG_PASS or on-board point. | |
player | Color to play. |
Definition at line 580 of file GoBoardUtil.cpp.
References GoRules::AllowSuicide(), GO_MOVEFLAG_ILLEGAL, GoBoard::IsEmpty(), GoBoard::IsSuicide(), GoBoard::LastMoveInfo(), GoBoard::Play(), GoBoard::Rules(), SG_COUPONMOVE, SG_PASS, and GoBoard::Undo().
Referenced by GoSearch::Execute(), GoMoveExecutor::GoMoveExecutor(), GoLadderUtil::IsProtectedLiberty(), GoLadder::IsSnapback(), IsSnapback(), GoLadder::Ladder(), GoLadder::PlayHunterMove(), PlayIfLegal(), and GoLadder::PlayPreyMove().
Keep only the anchor of each block in the list.
Points not occupied are removed from the list. The initial list may contain duplicate stones; these will be thrown out. The returned list will be sorted by anchors.
Definition at line 598 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), SgVector< T >::Insert(), GoBoard::Occupied(), and SG_ASSERT.
void GoBoardUtil::ReduceToAnchors | ( | const GoBoard & | bd, | |
const SgVector< SgPoint > & | stones, | |||
SgSList< SgPoint, SG_MAXPOINT > & | anchors | |||
) |
Keep only the anchor of each block in the list.
Points not occupied are removed from the list. The initial list may contain duplicate stones; these will be thrown out. The returned list will not be sorted by anchors.
Definition at line 609 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), SgSList< T, SIZE >::Clear(), SgSList< T, SIZE >::Include(), and GoBoard::Occupied().
void GoBoardUtil::RegionCode | ( | const GoBoard & | bd, | |
const SgVector< SgPoint > & | region, | |||
SgHashCode * | c | |||
) |
Compute the hash code for region of this board position.
Definition at line 619 of file GoBoardUtil.cpp.
References BOOST_STATIC_ASSERT(), SgHash< N >::Clear(), GoBoard::GetStone(), GoBoard::Occupied(), SG_BLACK, SG_MAXPOINT, SG_WHITE, and SgHashUtil::XorZobrist().
bool GoBoardUtil::RemainingChineseHandicap | ( | const GoBoard & | bd | ) |
Returns true iff during the first N moves of a Chinese handicap game.
Definition at line 635 of file GoBoardUtil.cpp.
References GoRules::Handicap(), GoRules::JapaneseHandicap(), GoBoard::Rules(), SG_BLACK, and GoBoard::TotalNumStones().
Referenced by GoGameRecord::GoToNode().
float GoBoardUtil::ScoreSimpleEndPosition | ( | const GoBoard & | bd, | |
float | komi, | |||
bool | noCheck = false | |||
) |
Score position with all stones safe and only simple eyes.
This is a fast scoring function (e.g. suitable for Monte-Carlo), that can be used if playing continues as long as there are legal moves which do not fill the player's single point eyes. All stones are considered safe, all empty points must be single empty points surrounded by one color. The score is counted using 1 point for all black stones or empty points with only black stones adjacent, and -1 point for white stones or empty points with only white stones adjacent. Komi of board is taken into account.
bd | The board with the position | |
komi | Komi (bd.Rules().Komi() is not used to avoid multiple conversions of komi to float) | |
noCheck | Don't throw an exception if not all empty points are single empty points (there are cases, where this score function is useful even if it is sometimes wrong) |
SgException | If there are empty points, which are not single empty points or with stones of both colors adjacent. |
Definition at line 642 of file GoBoardUtil.cpp.
References ScorePoint().
void GoBoardUtil::SharedLiberties | ( | const GoBoard & | bd, | |
SgPoint | block1, | |||
SgPoint | block2, | |||
SgVector< SgPoint > * | sharedLibs | |||
) |
Return all points that are liberties of both 'block1' and 'block2'.
Not defined for empty or border points.
Definition at line 651 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), SgVector< T >::Clear(), GoBoard::Occupied(), SgVector< T >::PushBack(), and SG_ASSERT.
void GoBoardUtil::SharedLibertyBlocks | ( | const GoBoard & | bd, | |
SgPoint | anchor, | |||
int | maxLib, | |||
SgVector< SgPoint > * | blocks | |||
) |
Definition at line 670 of file GoBoardUtil.cpp.
References SgMarker::Clear(), SgMarker::Include(), GoBoard::m_userMarker, SgMarker::NewMark(), SG_ASSERT, SG_NS, SG_UNUSED(), and SG_WE.
void GoBoardUtil::UndoAll | ( | GoBoard & | bd | ) |
Undo all moves or setup stones.
Definition at line 710 of file GoBoardUtil.cpp.
References GoBoard::CanUndo(), and GoBoard::Undo().
Referenced by GoBook::Entry::ApplyTo(), GoBook::InsertEntry(), and GoBoardRestorer::~GoBoardRestorer().
Return whether 'block1' and 'block2' have at least two shared liberties.
Not defined for empty or border points.
Definition at line 716 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), GoBoard::Occupied(), and SG_ASSERT.
Referenced by TestForChain().
void GoBoardUtil::TestForChain | ( | GoBoard & | bd, | |
SgPoint | block, | |||
SgPoint | block2, | |||
SgPoint | lib, | |||
SgVector< SgPoint > * | extended | |||
) |
Definition at line 736 of file GoBoardUtil.cpp.
References AtLeastTwoSharedLibs(), GoBoard::GetStone(), MoveNotLegalOrAtari(), SgVector< T >::PushBack(), GoBoard::SetToPlay(), and SgOppBW().
Definition at line 750 of file GoBoardUtil.cpp.
References GoBoard::GetStone(), GoBoard::Occupied(), and SgOppBW().
Either move is not legal, or the block at move is in atari after the move.
Definition at line 767 of file GoBoardUtil.cpp.
References GoBoard::InAtari(), and GoMoveExecutor::IsLegal().
Referenced by TestForChain().
Move is legal and the block at move is not in atari after the move.
Definition at line 773 of file GoBoardUtil.cpp.
References GoBoard::InAtari(), and GoMoveExecutor::IsLegal().
bool GoBoardUtil::ScorePosition | ( | const GoBoard & | bd, | |
const SgPointSet & | deadStones, | |||
float & | score | |||
) |
Count score given the set of dead stones.
Checks all regions that are surrounded by stones that are not dead, and counts the score according to the board rules (Chinese/Japanese) and komi. Black points are counted positive. Cannot handle neutral eye points that can occur in seki with Japanese rules.
bd | ||
deadStones | ||
[out] | score |
false
if position cannot be scored, because the dead stones information is not consistent (a region with dead stones of both colors exists or dead stones of a color in a region of that color). Definition at line 779 of file GoBoardUtil.cpp.
References SgMarker::Contains(), SgPointSet::Contains(), ScorePositionRecurse(), SG_BLACK, and SG_WHITE.
Fill stones in an array.
Kishi: I added this code to store stones to an array, because the list version first copies stones to an array, then copies an array to a list. For me, it's not necessary because I use arrays.
Definition at line 826 of file GoBoardUtil.cpp.
References GoBoard::IsSingleStone(), GoBoard::IsValidPoint(), GoBoard::Occupied(), and SG_ASSERT.
bool GoBoardUtil::TwoPasses | ( | const GoBoard & | bd | ) |
Check if the last two moves were two passes in a row, the first pass by the current color to play, the second by the opponent.
Definition at line 844 of file GoBoardUtil.cpp.
References GoBoard::Move(), GoBoard::MoveNumber(), SG_PASS, SgOppBW(), and GoBoard::ToPlay().
SgPointSet GoBoardUtil::Lines | ( | const GoBoard & | bd, | |
SgGrid | from, | |||
SgGrid | to | |||
) |
all points on lines [from.
.to]
Definition at line 856 of file GoBoardUtil.cpp.
References GoBoard::LineSet(), SG_ASSERT, and GoBoard::Size().
SgRect GoBoardUtil::GetDirtyRegion | ( | const GoBoard & | bd, | |
SgMove | move, | |||
SgBlackWhite | color, | |||
bool | checklibs = false , |
|||
bool | premove = false | |||
) |
Which intersections were modified with the last move.
Can check either before or after move is played (set premove)
Definition at line 867 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), GoBoard::CapturedStones(), GoBoard::CapturingMove(), SgPointSet::Include(), SgRect::Include(), GoBoard::IsColor(), SgSList< T, SIZE >::Iterator, GoBoard::NumLiberties(), GoBoard::Occupied(), SG_PASS, and SgOppBW().
int GoBoardUtil::Approx2Libs | ( | const GoBoard & | board, | |
SgPoint | block, | |||
SgPoint | p, | |||
SgBlackWhite | color | |||
) |
Estimate second order liberties of point p for given block This is fast and approximate, may double count libs.
Definition at line 945 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), GoBoard::IsColor(), GoBoard::IsEmpty(), and GoBoard::NumLiberties().
Is p contained in anchor[] ? anchor[] must be terminated by END_POINT.
Definition at line 411 of file GoBoardUtil.h.
References SG_ENDPOINT.
Referenced by AreSameBlocks(), and IsSimpleChain().
SgPoint GoBoardUtil::FindNeighbor | ( | const BOARD & | bd, | |
SgPoint | p, | |||
SgEmptyBlackWhite | c | |||
) |
Find a neighboring point in color c.
Precondition: Call only if such a point exists.
Definition at line 421 of file GoBoardUtil.h.
References SG_ASSERT, SG_NS, and SG_WE.
Referenced by GoEyeUtil::IsTwoPointEye().
Convert the given move to human-readable coordinates.
(lower left A1 to upper right T19, leaving out column I).
Definition at line 434 of file GoBoardUtil.h.
References GetCoordString(), and GoBoard::Size().
bool GoBoardUtil::IsCompletelySurrounded | ( | const BOARD & | bd, | |
SgPoint | p | |||
) |
Return if point is surrounded by one color and no adjacent block is in atari.
Good criterion for move generation in Monte-Carlo. See: Remi Coulom: Efficient selectivity and backup operators in Monte-Carlo tree search, CG2006, Appendix A.1, http://remi.coulom.free.fr/CG2006/
Definition at line 441 of file GoBoardUtil.h.
bool GoBoardUtil::IsNeighborOfSome | ( | const BOARD & | bd, | |
SgPoint | p, | |||
SgPoint | anchors[], | |||
SgBlackWhite | toPlay | |||
) |
Definition at line 460 of file GoBoardUtil.h.
References SG_ENDPOINT.
Referenced by SelfAtari(), and SelfAtariForColor().
bool GoBoardUtil::IsSimpleChain | ( | const BOARD & | bd, | |
SgPoint | block, | |||
SgPoint & | other | |||
) |
Does block have two shared liberties with some other block? WARNING: for efficiency this checks only the first two liberties of the block.
So it is accurate for two-liberty blocks, and a heuristic for blocks with more liberties.
Definition at line 479 of file GoBoardUtil.h.
References ContainsAnchor(), and SG_ENDPOINT.
Play a move for the current player if legal.
bd | The board. | |
p | Move to play; SG_PASS or on-board point. |
Definition at line 509 of file GoBoardUtil.h.
References PlayIfLegal(), and GoBoard::ToPlay().
bool GoBoardUtil::SelfAtari | ( | const BOARD & | bd, | |
SgPoint | p | |||
) |
Check if move would be self-atari.
Faster than Executing the move, then calling InAtari().
Definition at line 576 of file GoBoardUtil.h.
Referenced by ScorePoint().
bool GoBoardUtil::SelfAtari | ( | const BOARD & | bd, | |
SgPoint | p, | |||
int & | numStones | |||
) |
Same as above, but also compute number of stones put into selfatari.
numStones is set only if the return value is 'true'.
Definition at line 663 of file GoBoardUtil.h.
References IsNeighborOfSome(), SG_ASSERT, SG_EMPTY, SG_ENDPOINT, SG_NULLPOINT, and SgOppBW().
bool GoBoardUtil::SelfAtariForColor | ( | const BOARD & | bd, | |
SgPoint | p, | |||
SgBlackWhite | toPlay | |||
) |
Check if move would be self-atari for given color.
That color may be different from bd.ToPlay().
Definition at line 582 of file GoBoardUtil.h.
References IsNeighborOfSome(), SG_ASSERT, SG_EMPTY, SG_NULLPOINT, and SgOppBW().
Referenced by SelfAtari().
SgEmptyBlackWhite GoBoardUtil::ScorePoint | ( | const BOARD & | bd, | |
SgPoint | p, | |||
bool | noCheck | |||
) |
Helper function used in ScoreSimpleEndPosition.
Definition at line 515 of file GoBoardUtil.h.
References SelfAtari(), SG_ASSERT, SG_BLACK, SG_DEBUG_ONLY, SG_EMPTY, and SG_WHITE.
Referenced by ScoreSimpleEndPosition().
float GoBoardUtil::ScoreSimpleEndPosition | ( | const BOARD & | bd, | |
float | komi, | |||
const SgBWSet & | safe, | |||
bool | noCheck, | |||
SgPointArray< SgEmptyBlackWhite > * | scoreBoard | |||
) |
Score position with given safe stones and only simple eyes.
This is a fast scoring function (e.g. suitable for Monte-Carlo), that can be used if playing continues as long as there are legal moves which do not fill the player's single point eyes. Precomputed safety status of points is used, all other empty points must be single empty points surrounded by one color. The score is counted using 1 point for all black stones or empty points with only black stones adjacent, and -1 point for white stones or empty points with only white stones adjacent. Komi of board is taken into account.
bd | ||
komi | Komi (bd.Rules().Komi() is not used to avoid multiple conversions of komi to float) | |
safe | ||
noCheck | ||
scoreBoard | Optional board to fill in the status of each point (SG_EMPTY means dame); null if not needed |
Definition at line 543 of file GoBoardUtil.h.
References Contains(), ScorePoint(), SG_BLACK, and SG_WHITE.
float GoBoardUtil::TrompTaylorScore | ( | const BOARD & | bd, | |
float | komi, | |||
SgPointArray< SgEmptyBlackWhite > * | scoreBoard = 0 | |||
) |
Compute the Tromp-Taylor-score for the current positions.
The Tromp-Taylor score is a chinese scoring method that assumes that all stones on the board are alive.
bd | The board with the position to score. | |
komi | The komi | |
scoreBoard | Optional board to fill in the status of each point (SG_EMPTY means dame) |
Definition at line 745 of file GoBoardUtil.h.
References SgMarker::Contains(), SgMarker::Include(), SgStack< T, SIZE >::IsEmpty(), SgSList< T, SIZE >::Iterator, SgStack< T, SIZE >::Pop(), SgStack< T, SIZE >::Push(), SgSList< T, SIZE >::PushBack(), SG_ASSERT, SG_BLACK, SG_EMPTY, and SG_WHITE.
Referenced by GoGtpEngine::CmdFinalScore(), and PassWins().
Is p contained in anchor[] ? anchor[] must be terminated by END_POINT.
Definition at line 411 of file GoBoardUtil.h.
References SG_ENDPOINT.
Referenced by AreSameBlocks(), and IsSimpleChain().
SgPoint GoBoardUtil::FindNeighbor | ( | const BOARD & | bd, | |
SgPoint | p, | |||
SgEmptyBlackWhite | c | |||
) |
Find a neighboring point in color c.
Precondition: Call only if such a point exists.
Definition at line 421 of file GoBoardUtil.h.
References SG_ASSERT, SG_NS, and SG_WE.
Referenced by GoEyeUtil::IsTwoPointEye().
Convert the given move to human-readable coordinates.
(lower left A1 to upper right T19, leaving out column I).
Definition at line 434 of file GoBoardUtil.h.
References GetCoordString(), and GoBoard::Size().
bool GoBoardUtil::IsCompletelySurrounded | ( | const BOARD & | bd, | |
SgPoint | p | |||
) |
Return if point is surrounded by one color and no adjacent block is in atari.
Good criterion for move generation in Monte-Carlo. See: Remi Coulom: Efficient selectivity and backup operators in Monte-Carlo tree search, CG2006, Appendix A.1, http://remi.coulom.free.fr/CG2006/
Definition at line 441 of file GoBoardUtil.h.
bool GoBoardUtil::IsNeighborOfSome | ( | const BOARD & | bd, | |
SgPoint | p, | |||
SgPoint | anchors[], | |||
SgBlackWhite | toPlay | |||
) |
Definition at line 460 of file GoBoardUtil.h.
References SG_ENDPOINT.
Referenced by SelfAtari(), and SelfAtariForColor().
bool GoBoardUtil::IsSimpleChain | ( | const BOARD & | bd, | |
SgPoint | block, | |||
SgPoint & | other | |||
) |
Does block have two shared liberties with some other block? WARNING: for efficiency this checks only the first two liberties of the block.
So it is accurate for two-liberty blocks, and a heuristic for blocks with more liberties.
Definition at line 479 of file GoBoardUtil.h.
References ContainsAnchor(), and SG_ENDPOINT.
Play a move for the current player if legal.
bd | The board. | |
p | Move to play; SG_PASS or on-board point. |
Definition at line 509 of file GoBoardUtil.h.
References PlayIfLegal(), and GoBoard::ToPlay().
SgEmptyBlackWhite GoBoardUtil::ScorePoint | ( | const BOARD & | bd, | |
SgPoint | p, | |||
bool | noCheck | |||
) |
Helper function used in ScoreSimpleEndPosition.
Definition at line 515 of file GoBoardUtil.h.
References SelfAtari(), SG_ASSERT, SG_BLACK, SG_DEBUG_ONLY, SG_EMPTY, and SG_WHITE.
Referenced by ScoreSimpleEndPosition().
float GoBoardUtil::ScoreSimpleEndPosition | ( | const BOARD & | bd, | |
float | komi, | |||
const SgBWSet & | safe, | |||
bool | noCheck, | |||
SgPointArray< SgEmptyBlackWhite > * | scoreBoard | |||
) |
Score position with given safe stones and only simple eyes.
This is a fast scoring function (e.g. suitable for Monte-Carlo), that can be used if playing continues as long as there are legal moves which do not fill the player's single point eyes. Precomputed safety status of points is used, all other empty points must be single empty points surrounded by one color. The score is counted using 1 point for all black stones or empty points with only black stones adjacent, and -1 point for white stones or empty points with only white stones adjacent. Komi of board is taken into account.
bd | ||
komi | Komi (bd.Rules().Komi() is not used to avoid multiple conversions of komi to float) | |
safe | ||
noCheck | ||
scoreBoard | Optional board to fill in the status of each point (SG_EMPTY means dame); null if not needed |
Definition at line 543 of file GoBoardUtil.h.
References Contains(), ScorePoint(), SG_BLACK, and SG_WHITE.
bool GoBoardUtil::SelfAtari | ( | const BOARD & | bd, | |
SgPoint | p | |||
) |
Check if move would be self-atari.
Faster than Executing the move, then calling InAtari().
Definition at line 576 of file GoBoardUtil.h.
References SelfAtariForColor().
bool GoBoardUtil::SelfAtariForColor | ( | const BOARD & | bd, | |
SgPoint | p, | |||
SgBlackWhite | toPlay | |||
) |
Check if move would be self-atari for given color.
That color may be different from bd.ToPlay().
Definition at line 582 of file GoBoardUtil.h.
References IsNeighborOfSome(), SG_ASSERT, SG_EMPTY, SG_NULLPOINT, and SgOppBW().
Referenced by SelfAtari().
bool GoBoardUtil::SelfAtari | ( | const BOARD & | bd, | |
SgPoint | p, | |||
int & | numStones | |||
) |
Same as above, but also compute number of stones put into selfatari.
numStones is set only if the return value is 'true'.
Definition at line 663 of file GoBoardUtil.h.
References IsNeighborOfSome(), SG_ASSERT, SG_EMPTY, SG_ENDPOINT, SG_NULLPOINT, and SgOppBW().
float GoBoardUtil::TrompTaylorScore | ( | const BOARD & | bd, | |
float | komi, | |||
SgPointArray< SgEmptyBlackWhite > * | scoreBoard = 0 | |||
) |
Compute the Tromp-Taylor-score for the current positions.
The Tromp-Taylor score is a chinese scoring method that assumes that all stones on the board are alive.
bd | The board with the position to score. | |
komi | The komi | |
scoreBoard | Optional board to fill in the status of each point (SG_EMPTY means dame) |
Definition at line 745 of file GoBoardUtil.h.
References SgMarker::Contains(), SgMarker::Include(), SgStack< T, SIZE >::IsEmpty(), SgSList< T, SIZE >::Iterator, SgStack< T, SIZE >::Pop(), SgStack< T, SIZE >::Push(), SgSList< T, SIZE >::PushBack(), SG_ASSERT, SG_BLACK, SG_EMPTY, and SG_WHITE.
Referenced by GoGtpEngine::CmdFinalScore(), and PassWins().