Utility functions for users of class GoBoard. More...
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. | |
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 | AtLeastTwoSharedLibs (const GoBoard &bd, SgPoint block1, SgPoint block2) |
Return whether 'block1' and 'block2' have at least two shared liberties. | |
bool | BlockIsAdjacentTo (const GoBoard &bd, SgPoint block, const SgPointSet &walls) |
void | BlocksAdjacentToPoints (const GoBoard &bd, const SgVector< SgPoint > &points, SgBlackWhite c, SgVector< SgPoint > *anchors) |
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'. | |
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. | |
bool | ContainsAnchor (const SgPoint anchor[], const SgPoint p) |
Is p contained in anchor[] ? anchor[] must be terminated by END_POINT. | |
void | DiagonalsOfColor (const GoBoard &bd, SgPoint p, int c, SgVector< SgPoint > *diagonals) |
Get diagonal points with a color. | |
void | DumpBoard (const GoBoard &bd, std::ostream &out=SgDebug()) |
Write board including move history to stream. | |
bool | EndOfGame (const GoBoard &bd) |
Return whether the game is finished. | |
void | ExpandToBlocks (const GoBoard &board, SgPointSet &pointSet) |
Add other stones of blocks to SgPointSet if one is in set. | |
template<class BOARD > | |
SgPoint | FindNeighbor (const BOARD &bd, SgPoint p, SgEmptyBlackWhite c) |
Find a neighboring point in color c. | |
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. | |
void | GetCoordString (const GoBoard &board, SgMove move, std::string *s) |
Convert the given move to human-readable coordinates. | |
SgRect | GetDirtyRegion (const GoBoard &bd, SgMove move, SgBlackWhite color, bool checklibs=false, bool premove=false) |
Which intersections were modified with the last move. | |
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 | HasStonesOfBothColors (const GoBoard &bd, const SgVector< SgPoint > &stones) |
template<class BOARD > | |
bool | IsBoardEmpty (const BOARD &bd) |
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. | |
bool | IsHandicapPoint (SgGrid size, SgGrid col, SgGrid row) |
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 | 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. | |
SgPointSet | Lines (const GoBoard &bd, SgGrid from, SgGrid to) |
all points on lines [from..to] | |
bool | ManySecondaryLibs (const GoBoard &bd, SgPoint block) |
bool | MoveNotLegalOrAtari (const GoBoard &bd, SgPoint move) |
Either move is not legal, or the block at move is in atari after the move. | |
bool | MoveLegalAndNotAtari (const GoBoard &bd, SgPoint move) |
Move is legal and the block at move is not in atari after the move. | |
SgArrayList< 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 | TrompTaylorPassWins (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. | |
bool | PlayIfLegal (GoBoard &bd, SgPoint p) |
Play a move for the current player 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, SgArrayList< 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. | |
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. | |
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) |
bool | ScorePosition (const GoBoard &bd, const SgPointSet &deadStones, float &score) |
Count score given the set of dead stones. | |
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. | |
float | ScoreSimpleEndPosition (const GoBoard &bd, float komi, bool noCheck=false) |
Score position with all stones safe and only simple eyes. | |
int | Stones (const GoBoard &bd, SgPoint p, SgPoint stones[]) |
Fill stones in an array. | |
void | TestForChain (GoBoard &bd, SgPoint block, SgPoint block2, SgPoint lib, SgVector< SgPoint > *extended) |
template<class BOARD > | |
float | TrompTaylorScore (const BOARD &bd, float komi, SgPointArray< SgEmptyBlackWhite > *scoreBoard=0) |
Compute the Tromp-Taylor-score for the current positions. | |
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. | |
void | UndoAll (GoBoard &bd) |
Undo all moves or setup stones. |
Utility functions for users of class GoBoard.
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.
void GoBoardUtil::AddNeighborBlocksOfColor | ( | const GoBoard & | bd, | |
SgPoint | p, | |||
SgBlackWhite | color, | |||
SgVector< SgPoint > & | neighbors | |||
) |
Add anchors of neighbor blocks to list.
Definition at line 82 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 96 of file GoBoardUtil.cpp.
References GoBoard::Play().
void GoBoardUtil::AdjacentBlocks | ( | const GoBoard & | bd, | |
SgPoint | p, | |||
int | maxLib, | |||
SgVector< SgPoint > * | blocks | |||
) |
SgVector version of GoBoard::AdjacentBlocks.
Definition at line 137 of file GoBoardUtil.cpp.
References GoBoard::AdjacentBlocks(), SgVector< T >::SetTo(), SG_ASSERT, and SG_MAXPOINT.
Referenced by GoGtpEngine::CmdPointInfo().
GoPointList GoBoardUtil::AdjacentStones | ( | const GoBoard & | bd, | |
SgPoint | point | |||
) |
Get list of stones adjacent to a block.
Definition at line 109 of file GoBoardUtil.cpp.
References SgMarker::Clear(), GoBoard::GetStone(), GoBoard::IsColor(), GoBoard::IsValidPoint(), GoBoard::m_userMarker, SgMarker::NewMark(), GoBoard::NumNeighbors(), GoBoard::Occupied(), SG_ASSERT, SG_NS, SG_UNUSED(), SG_WE, and SgOppBW().
Referenced by GoLadder::Ladder(), and GoLadder::PlayPreyMove().
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 947 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), GoBoard::IsColor(), GoBoard::IsEmpty(), and GoBoard::NumLiberties().
Return whether 'block1' and 'block2' have at least two shared liberties.
Not defined for empty or border points.
Definition at line 715 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), GoBoard::IsLibertyOfBlock(), GoBoard::Occupied(), and SG_ASSERT.
Referenced by TestForChain().
bool GoBoardUtil::BlockIsAdjacentTo | ( | const GoBoard & | bd, | |
SgPoint | block, | |||
const SgPointSet & | walls | |||
) |
Definition at line 222 of file GoBoardUtil.cpp.
References SgPointSet::Contains(), SG_NS, and SG_WE.
void GoBoardUtil::BlocksAdjacentToPoints | ( | const GoBoard & | bd, | |
const SgVector< SgPoint > & | points, | |||
SgBlackWhite | c, | |||
SgVector< SgPoint > * | anchors | |||
) |
Definition at line 146 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 > * | anchors | |||
) |
List the anchors of all blocks of color 'c' adjacent to the region consisting of 'points'.
Definition at line 183 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.
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 237 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), SgArrayList< T, SIZE >::Length(), GoBoard::Occupied(), SgArrayList< T, SIZE >::PushBack(), SG_NS, and SG_WE.
Referenced by GoGtpExtraCommands::CmdCfgDistance().
Is p contained in anchor[] ? anchor[] must be terminated by END_POINT.
Definition at line 379 of file GoBoardUtil.h.
References SG_ENDPOINT.
Referenced by IsSimpleChain().
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 345 of file GoBoardUtil.cpp.
References SgVector< T >::Clear(), GoBoard::IsColor(), SgVector< T >::PushBack(), SG_NS, and SG_WE.
void GoBoardUtil::DumpBoard | ( | const GoBoard & | bd, | |
std::ostream & | out = SgDebug() | |||
) |
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 279 of file GoBoardUtil.cpp.
References GoPlayerMove::Color(), GoSetup::IsEmpty(), GoSetup::m_player, GoSetup::m_stones, GoPlayerMove::Point(), PointToSgfString(), GoBoard::Setup(), SG_BLACK, SG_PROPPOINTFMT_GO, and GoBoard::Size().
Referenced by GoGtpEngine::DumpState().
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 359 of file GoBoardUtil.cpp.
References GoBoard::Move(), GoBoard::MoveNumber(), GoBoard::Rules(), SG_PASS, SgOppBW(), GoBoard::ToPlay(), and GoRules::TwoPassesEndGame().
Referenced by GoGtpEngine::BoardChanged().
void GoBoardUtil::ExpandToBlocks | ( | const GoBoard & | board, | |
SgPointSet & | pointSet | |||
) |
Add other stones of blocks to SgPointSet if one is in set.
Definition at line 322 of file GoBoardUtil.cpp.
References GoBoard::All(), GoBoard::Occupied(), SG_ASSERT, SG_BLACK, SG_WHITE, GoBoard::Size(), and SgPointSet::SubsetOf().
Referenced by GoSafetyUtil::AddToSafe().
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 389 of file GoBoardUtil.h.
References SG_ASSERT, SG_NS, and SG_WE.
Referenced by GoEyeUtil::IsTwoPointEye().
Include move in list if it is legal.
Definition at line 381 of file GoBoardUtil.cpp.
References SgVector< T >::Include(), and 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 393 of file GoBoardUtil.cpp.
References SgPointUtil::Col(), SgPointUtil::Row(), SG_ASSERT, SG_COUPONMOVE, SG_NULLMOVE, and SG_PASS.
Referenced by GetCoordString().
Convert the given move to human-readable coordinates.
(lower left A1 to upper right T19, leaving out column I).
Definition at line 402 of file GoBoardUtil.h.
References GetCoordString(), 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 869 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), GoBoard::CapturedStones(), GoBoard::CapturingMove(), SgPointSet::Include(), SgRect::Include(), GoBoard::IsColor(), SgArrayList< SgPoint, SG_MAX_ONBOARD+1 >::Iterator, GoBoard::NumLiberties(), GoBoard::Occupied(), SG_PASS, and SgOppBW().
Return whether block has at least one adjacent opponent block with at most maxLib liberties.
Definition at line 413 of file GoBoardUtil.cpp.
References GoBoard::AtMostNumLibs(), GoBoard::GetStone(), GoBoard::IsColor(), GoBoard::Occupied(), SG_ASSERT, and SgOppBW().
Definition at line 749 of file GoBoardUtil.cpp.
References GoBoard::GetStone(), GoBoard::Occupied(), and SgOppBW().
bool GoBoardUtil::IsBoardEmpty | ( | const BOARD & | bd | ) |
Definition at line 409 of file GoBoardUtil.h.
References SG_BLACK, and SG_WHITE.
Referenced by GoGtpEngine::BoardChanged(), GoGtpEngine::CheckBoardEmpty(), and GoGame::PlaceHandicap().
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 415 of file GoBoardUtil.h.
Definition at line 425 of file GoBoardUtil.cpp.
Referenced by GoWriteBoard().
bool GoBoardUtil::IsNeighborOfSome | ( | const BOARD & | bd, | |
SgPoint | p, | |||
SgPoint | anchors[], | |||
SgBlackWhite | toPlay | |||
) |
Definition at line 434 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 453 of file GoBoardUtil.h.
References ContainsAnchor(), and SG_ENDPOINT.
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 452 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 483 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().
SgPointSet GoBoardUtil::Lines | ( | const GoBoard & | bd, | |
SgGrid | from, | |||
SgGrid | to | |||
) |
all points on lines [from..to]
Definition at line 858 of file GoBoardUtil.cpp.
References GoBoard::LineSet(), SG_ASSERT, and GoBoard::Size().
Definition at line 507 of file GoBoardUtil.cpp.
References SgMarker::Clear(), GoBoard::IsEmpty(), and SgMarker::NewMark().
Move is legal and the block at move is not in atari after the move.
Definition at line 773 of file GoBoardUtil.cpp.
References GoModBoard::Board(), and GoBoard::InAtari().
Either move is not legal, or the block at move is in atari after the move.
Definition at line 766 of file GoBoardUtil.cpp.
References GoModBoard::Board(), and GoBoard::InAtari().
Referenced by TestForChain().
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 548 of file GoBoardUtil.cpp.
References SgVector< T >::Clear(), GoBoard::IsColor(), SgVector< T >::PushBack(), SG_NS, and SG_WE.
SgArrayList< SgPoint, 4 > GoBoardUtil::NeighborsOfColor | ( | const GoBoard & | bd, | |
SgPoint | p, | |||
int | c | |||
) |
Get adjacent points with a color.
bd | The board. | |
p | The point. | |
c | The color. |
Definition at line 533 of file GoBoardUtil.cpp.
References GoBoard::IsColor(), SgArrayList< T, SIZE >::PushBack(), SG_NS, and SG_WE.
Referenced by GoLadder::Ladder(), and GoLadder::PlayPreyMove().
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 579 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().
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 483 of file GoBoardUtil.h.
References PlayIfLegal(), and GoBoard::ToPlay().
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 597 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), SgVector< T >::Insert(), GoBoard::Occupied(), SG_ASSERT, and SgVector< T >::SwapWith().
void GoBoardUtil::ReduceToAnchors | ( | const GoBoard & | bd, | |
const SgVector< SgPoint > & | stones, | |||
SgArrayList< 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 608 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), SgArrayList< T, SIZE >::Clear(), SgArrayList< 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 618 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 634 of file GoBoardUtil.cpp.
References GoRules::Handicap(), GoRules::JapaneseHandicap(), GoBoard::Rules(), SG_BLACK, and GoBoard::TotalNumStones().
Referenced by GoGame::GoToNode().
SgEmptyBlackWhite GoBoardUtil::ScorePoint | ( | const BOARD & | bd, | |
SgPoint | p, | |||
bool | noCheck | |||
) |
Helper function used in ScoreSimpleEndPosition.
Definition at line 489 of file GoBoardUtil.h.
References SelfAtari(), SG_ASSERT, SG_BLACK, SG_DEBUG_ONLY, SG_EMPTY, and SG_WHITE.
Referenced by ScoreSimpleEndPosition().
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 780 of file GoBoardUtil.cpp.
References SgMarker::Contains(), SgPointSet::Contains(), GoBoard::GetColor(), GoRules::JapaneseScoring(), GoRules::Komi(), GoBoard::NumPrisoners(), GoBoard::Occupied(), GoBoard::Rules(), SG_BLACK, SG_WHITE, and GoKomi::ToFloat().
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 517 of file GoBoardUtil.h.
References ScorePoint(), SG_BLACK, and SG_WHITE.
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 641 of file GoBoardUtil.cpp.
References 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 637 of file GoBoardUtil.h.
References IsNeighborOfSome(), SG_ASSERT, SG_EMPTY, SG_ENDPOINT, SG_NULLPOINT, and SgOppBW().
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 550 of file GoBoardUtil.h.
References SelfAtariForColor().
Referenced by ScorePoint().
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 556 of file GoBoardUtil.h.
References IsNeighborOfSome(), SG_ASSERT, SG_EMPTY, SG_NULLPOINT, and SgOppBW().
Referenced by SelfAtari().
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 650 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), SgVector< T >::Clear(), GoBoard::IsLibertyOfBlock(), GoBoard::Occupied(), SgVector< T >::PushBack(), and SG_ASSERT.
void GoBoardUtil::SharedLibertyBlocks | ( | const GoBoard & | bd, | |
SgPoint | anchor, | |||
int | maxLib, | |||
SgVector< SgPoint > * | blocks | |||
) |
Definition at line 669 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), GoBoard::AtMostNumLibs(), SgMarker::Clear(), GoBoard::GetStone(), SgMarker::Include(), GoBoard::IsColor(), GoBoard::m_userMarker, SgMarker::NewMark(), GoBoard::NumNeighbors(), SgVector< T >::PushBack(), SG_ASSERT, SG_NS, SG_UNUSED(), and SG_WE.
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 828 of file GoBoardUtil.cpp.
References GoBoard::Anchor(), GoBoard::IsSingleStone(), GoBoard::IsValidPoint(), GoBoard::Occupied(), and SG_ASSERT.
void GoBoardUtil::TestForChain | ( | GoBoard & | bd, | |
SgPoint | block, | |||
SgPoint | block2, | |||
SgPoint | lib, | |||
SgVector< SgPoint > * | extended | |||
) |
Definition at line 735 of file GoBoardUtil.cpp.
References AtLeastTwoSharedLibs(), GoBoard::GetStone(), MoveNotLegalOrAtari(), SgVector< T >::PushBack(), GoBoard::SetToPlay(), and SgOppBW().
bool GoBoardUtil::TrompTaylorPassWins | ( | const GoBoard & | bd, | |
SgBlackWhite | toPlay | |||
) |
Check if Tromp-Taylor rules and pass wins.
Definition at line 562 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().
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 719 of file GoBoardUtil.h.
References SgMarker::Contains(), SgMarker::Include(), SgStack< T, SIZE >::IsEmpty(), SgArrayList< SgPoint, SG_MAX_ONBOARD+1 >::Iterator, SgStack< T, SIZE >::Pop(), SgStack< T, SIZE >::Push(), SgArrayList< T, SIZE >::PushBack(), SG_ASSERT, SG_BLACK, SG_EMPTY, and SG_WHITE.
Referenced by GoGtpEngine::CmdFinalScore(), and TrompTaylorPassWins().
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 846 of file GoBoardUtil.cpp.
References GoBoard::Move(), GoBoard::MoveNumber(), SG_PASS, SgOppBW(), and GoBoard::ToPlay().
void GoBoardUtil::UndoAll | ( | GoBoard & | bd | ) |
Undo all moves or setup stones.
Definition at line 709 of file GoBoardUtil.cpp.
References GoBoard::CanUndo(), and GoBoard::Undo().
Referenced by GoBook::Entry::ApplyTo(), GoBook::InsertEntry(), and GoBoardRestorer::~GoBoardRestorer().