This class contains all the ladder-specific stuff. More...
#include <GoLadder.h>
Public Member Functions | |
GoLadder () | |
int | Ladder (const GoBoard &bd, SgPoint prey, SgBlackWhite toPlay, SgVector< SgPoint > *sequence, bool twoLibIsEscape=false) |
Main ladder routine. | |
Private Member Functions | |
bool | CheckMoveOverflow () const |
void | InitMaxMoveNumber () |
bool | PointIsAdjToPrey (SgPoint p) |
bool | BlockIsAdjToPrey (SgPoint p, int numAdj) |
void | MarkStonesAsPrey (SgPoint p, SgVector< SgPoint > *stones=0) |
Marks all stones in the block p as part of the prey. | |
void | FilterAdjacent (GoPointList &adjBlocks) |
Filter out captured blocks, blocks not in atari, and blocks not adjacent to the prey. | |
int | PlayHunterMove (int depth, SgPoint move, SgPoint lib1, SgPoint lib2, const GoPointList &adjBlk, SgVector< SgPoint > *sequence) |
Play hunter move and update all the relevant information. | |
int | PlayPreyMove (int depth, SgPoint move, SgPoint lib1, const GoPointList &adjBlk, SgVector< SgPoint > *sequence) |
Play prey move and update all the relevant information. | |
bool | IsSnapback (SgPoint prey) |
Check whether the block at 'prey' is caught in a snapback. | |
int | PreyLadder (int depth, SgPoint lib1, const GoPointList &adjBlk, SgVector< SgPoint > *sequence) |
int | HunterLadder (int depth, SgPoint lib1, const GoPointList &adjBlk, SgVector< SgPoint > *sequence) |
int | HunterLadder (int depth, SgPoint lib1, SgPoint lib2, const GoPointList &adjBlk, SgVector< SgPoint > *sequence) |
void | ReduceToBlocks (GoPointList &stones) |
Private Attributes | |
int | m_maxMoveNumber |
Maximum move number before ladder should be aborted. | |
GoBoard * | m_bd |
SgPointSet | m_partOfPrey |
SgBlackWhite | m_preyColor |
SgBlackWhite | m_hunterColor |
Static Private Attributes | |
static const int | MAX_LADDER_MOVES = 200 |
Maximum number of moves in ladder. |
This class contains all the ladder-specific stuff.
Definition at line 40 of file GoLadder.h.
GoLadder::GoLadder | ( | ) |
Definition at line 32 of file GoLadder.cpp.
bool GoLadder::BlockIsAdjToPrey | ( | SgPoint | p, | |
int | numAdj | |||
) | [private] |
Definition at line 96 of file GoLadder.cpp.
References GoBoard::IsColor(), m_bd, m_hunterColor, PointIsAdjToPrey(), and SG_ASSERT.
Referenced by FilterAdjacent(), Ladder(), and PreyLadder().
bool GoLadder::CheckMoveOverflow | ( | ) | const [private] |
Definition at line 36 of file GoLadder.cpp.
References m_bd, m_maxMoveNumber, and GoBoard::MoveNumber().
Referenced by HunterLadder(), Ladder(), and PreyLadder().
void GoLadder::FilterAdjacent | ( | GoPointList & | adjBlocks | ) | [private] |
Filter out captured blocks, blocks not in atari, and blocks not adjacent to the prey.
The latter are found by checking whether blocks adjacent to the block in question are the prey or not. Does not return the correct blocks if the prey has more than three liberties, but in that case, the prey has escaped anyway.
Definition at line 73 of file GoLadder.cpp.
References BlockIsAdjToPrey(), GoBoard::InAtari(), GoBoard::IsColor(), SgArrayList< SgPoint, SG_MAX_ONBOARD+1 >::Iterator, m_bd, m_hunterColor, SgArrayList< T, SIZE >::PushBack(), and ReduceToBlocks().
Referenced by Ladder(), and PlayPreyMove().
int GoLadder::HunterLadder | ( | int | depth, | |
SgPoint | lib1, | |||
SgPoint | lib2, | |||
const GoPointList & | adjBlk, | |||
SgVector< SgPoint > * | sequence | |||
) | [private] |
Definition at line 308 of file GoLadder.cpp.
References SgPointUtil::AreAdjacent(), CheckMoveOverflow(), SgArrayList< T, SIZE >::IsEmpty(), m_bd, m_hunterColor, GoBoard::NumEmptyNeighbors(), GoBoard::Play(), PlayHunterMove(), PreyLadder(), SgVector< T >::PushBack(), SgVector< T >::SwapWith(), and GoBoard::Undo().
int GoLadder::HunterLadder | ( | int | depth, | |
SgPoint | lib1, | |||
const GoPointList & | adjBlk, | |||
SgVector< SgPoint > * | sequence | |||
) | [private] |
Definition at line 295 of file GoLadder.cpp.
References CheckMoveOverflow(), SgVector< T >::SetTo(), and SG_UNUSED().
Referenced by Ladder(), and PlayPreyMove().
void GoLadder::InitMaxMoveNumber | ( | ) | [private] |
Definition at line 41 of file GoLadder.cpp.
References GO_MAX_NUM_MOVES, m_bd, m_maxMoveNumber, MAX_LADDER_MOVES, and GoBoard::MoveNumber().
Referenced by Ladder().
bool GoLadder::IsSnapback | ( | SgPoint | prey | ) | [private] |
Check whether the block at 'prey' is caught in a snapback.
Snapback means that it can be captured, but it's only a single stone, and the prey can capture right back.
Definition at line 519 of file GoLadder.cpp.
References GoBoard::GetStone(), GoBoard::InAtari(), GoBoard::IsSingleStone(), m_bd, GoBoardUtil::PlayIfLegal(), SgOppBW(), and GoBoard::Undo().
Referenced by Ladder().
int GoLadder::Ladder | ( | const GoBoard & | bd, | |
SgPoint | prey, | |||
SgBlackWhite | toPlay, | |||
SgVector< SgPoint > * | sequence, | |||
bool | twoLibIsEscape = false | |||
) |
Main ladder routine.
twoLibIsEscape: if prey is to play and has two libs, does it count as an immediate escape, or shall we keep trying to capture?
Definition at line 395 of file GoLadder.cpp.
References GoBoardUtil::AdjacentStones(), BlockIsAdjToPrey(), GoModBoard::Board(), CheckMoveOverflow(), SgPointSet::Clear(), SgVector< T >::Clear(), SgVector< T >::Concat(), FilterAdjacent(), GoBoard::GetStone(), HunterLadder(), InitMaxMoveNumber(), GoBoard::IsColor(), IsSnapback(), SgArrayList< SgPoint, SG_MAX_ONBOARD+1 >::Iterator, m_bd, m_hunterColor, m_partOfPrey, m_preyColor, MarkStonesAsPrey(), GoBoardUtil::NeighborsOfColor(), GoBoard::NumLiberties(), GoBoard::Occupied(), GoBoardUtil::PlayIfLegal(), PreyLadder(), SgVector< T >::PushBack(), ReduceToBlocks(), SgVector< T >::Reverse(), SG_ASSERT, SG_EMPTY, SgOppBW(), and GoBoard::Undo().
Referenced by GoLadderUtil::Ladder(), and GoLadderUtil::LadderStatus().
Marks all stones in the block p as part of the prey.
If 'stones' is not 0, then append the stones to the existing list.
Definition at line 52 of file GoLadder.cpp.
References SgPointSet::Include(), GoBoard::IsValidPoint(), m_bd, m_partOfPrey, GoBoard::Occupied(), SgVector< T >::PushBack(), and SG_ASSERT.
Referenced by Ladder(), and PlayPreyMove().
int GoLadder::PlayHunterMove | ( | int | depth, | |
SgPoint | move, | |||
SgPoint | lib1, | |||
SgPoint | lib2, | |||
const GoPointList & | adjBlk, | |||
SgVector< SgPoint > * | sequence | |||
) | [private] |
Play hunter move and update all the relevant information.
Play at one of the two liberties of the prey.
Definition at line 107 of file GoLadder.cpp.
References GoBoard::AreInSameBlock(), GoBoard::CapturingMove(), SgVector< T >::Clear(), GoBoard::InAtari(), SgArrayList< SgPoint, SG_MAX_ONBOARD+1 >::Iterator, m_bd, m_hunterColor, GoBoardUtil::PlayIfLegal(), PreyLadder(), SgVector< T >::PushBack(), SgArrayList< T, SIZE >::PushBack(), SG_ASSERT, and GoBoard::Undo().
Referenced by HunterLadder().
int GoLadder::PlayPreyMove | ( | int | depth, | |
SgPoint | move, | |||
SgPoint | lib1, | |||
const GoPointList & | adjBlk, | |||
SgVector< SgPoint > * | sequence | |||
) | [private] |
Play prey move and update all the relevant information.
Extend the prey by playing at its only liberty, or capture a block adjacent to the prey.
Definition at line 155 of file GoLadder.cpp.
References GoBoardUtil::AdjacentStones(), GoBoard::CapturedStones(), GoBoard::CapturingMove(), SgVector< T >::Clear(), SgPointSet::Exclude(), FilterAdjacent(), HunterLadder(), SgPointSet::Include(), SgVector< T >::Include(), SgVector< T >::IsEmpty(), GoBoard::IsEmpty(), SgArrayList< SgPoint, SG_MAX_ONBOARD+1 >::Iterator, SgVector< T >::Length(), m_bd, m_hunterColor, m_partOfPrey, m_preyColor, MarkStonesAsPrey(), GoBoardUtil::NeighborsOfColor(), GoBoardUtil::PlayIfLegal(), PointIsAdjToPrey(), SgVector< T >::PushBack(), SgArrayList< T, SIZE >::PushBackList(), SG_ASSERT, SG_EMPTY, and GoBoard::Undo().
Referenced by PreyLadder().
bool GoLadder::PointIsAdjToPrey | ( | SgPoint | p | ) | [private] |
Definition at line 88 of file GoLadder.cpp.
References m_partOfPrey, SG_NS, and SG_WE.
Referenced by BlockIsAdjToPrey(), and PlayPreyMove().
int GoLadder::PreyLadder | ( | int | depth, | |
SgPoint | lib1, | |||
const GoPointList & | adjBlk, | |||
SgVector< SgPoint > * | sequence | |||
) | [private] |
Definition at line 249 of file GoLadder.cpp.
References BlockIsAdjToPrey(), CheckMoveOverflow(), SgArrayList< SgPoint, SG_MAX_ONBOARD+1 >::Iterator, m_bd, PlayPreyMove(), SgVector< T >::SetTo(), and SgVector< T >::SwapWith().
Referenced by HunterLadder(), Ladder(), and PlayHunterMove().
void GoLadder::ReduceToBlocks | ( | GoPointList & | stones | ) | [private] |
Definition at line 364 of file GoLadder.cpp.
References SgArrayList< T, SIZE >::Clear(), SgArrayList< T, SIZE >::Contains(), GoBoard::IsEmpty(), SgArrayList< T, SIZE >::IsEmpty(), SgArrayList< SgPoint, SG_MAX_ONBOARD+1 >::Iterator, SgArrayList< T, SIZE >::Length(), m_bd, GoBoard::Occupied(), and SgArrayList< T, SIZE >::PushBack().
Referenced by FilterAdjacent(), and Ladder().
GoBoard* GoLadder::m_bd [private] |
Definition at line 61 of file GoLadder.h.
Referenced by BlockIsAdjToPrey(), CheckMoveOverflow(), FilterAdjacent(), HunterLadder(), InitMaxMoveNumber(), IsSnapback(), Ladder(), MarkStonesAsPrey(), PlayHunterMove(), PlayPreyMove(), PreyLadder(), and ReduceToBlocks().
SgBlackWhite GoLadder::m_hunterColor [private] |
Definition at line 67 of file GoLadder.h.
Referenced by BlockIsAdjToPrey(), FilterAdjacent(), HunterLadder(), Ladder(), PlayHunterMove(), and PlayPreyMove().
int GoLadder::m_maxMoveNumber [private] |
Maximum move number before ladder should be aborted.
Definition at line 59 of file GoLadder.h.
Referenced by CheckMoveOverflow(), and InitMaxMoveNumber().
SgPointSet GoLadder::m_partOfPrey [private] |
Definition at line 63 of file GoLadder.h.
Referenced by Ladder(), MarkStonesAsPrey(), PlayPreyMove(), and PointIsAdjToPrey().
SgBlackWhite GoLadder::m_preyColor [private] |
Definition at line 65 of file GoLadder.h.
Referenced by Ladder(), and PlayPreyMove().
const int GoLadder::MAX_LADDER_MOVES = 200 [static, private] |
Maximum number of moves in ladder.
If board has simple ko rule, ladders could not terminate.
Definition at line 56 of file GoLadder.h.
Referenced by InitMaxMoveNumber().