Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

GoLadder Class Reference

#include <GoLadder.h>

List of all members.


Detailed Description

This class contains all the ladder-specific stuff.

Definition at line 41 of file 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.
GoBoardm_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.


Constructor & Destructor Documentation

GoLadder::GoLadder (  ) 

Definition at line 33 of file GoLadder.cpp.


Member Function Documentation

bool GoLadder::BlockIsAdjToPrey ( SgPoint  p,
int  numAdj 
) [private]

Definition at line 99 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 37 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 76 of file GoLadder.cpp.

References BlockIsAdjToPrey(), GoBoard::InAtari(), GoBoard::IsColor(), SgSList< T, SIZE >::Iterator, m_bd, m_hunterColor, SgSList< 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 313 of file GoLadder.cpp.

References SgPointUtil::AreAdjacent(), CheckMoveOverflow(), GOOD_FOR_PREY, SgSList< T, SIZE >::IsEmpty(), GoBoard::LibertyIterator, m_bd, m_hunterColor, GoBoard::NumEmptyNeighbors(), GoBoard::Play(), PlayHunterMove(), PreyLadder(), SgVector< T >::PushBack(), and GoBoard::Undo().

int GoLadder::HunterLadder ( int  depth,
SgPoint  lib1,
const GoPointList adjBlk,
SgVector< SgPoint > *  sequence 
) [private]

Definition at line 300 of file GoLadder.cpp.

References CheckMoveOverflow(), GOOD_FOR_HUNTER, GOOD_FOR_PREY, SgVector< T >::SetTo(), and SG_UNUSED().

Referenced by Ladder(), and PlayPreyMove().

void GoLadder::InitMaxMoveNumber (  )  [private]

Definition at line 42 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 525 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?

Returns:
Positive value if ladder is good for prey, negative, if good for hunter.

Definition at line 400 of file GoLadder.cpp.

References GoBoardUtil::AdjacentStones(), BlockIsAdjToPrey(), GoModBoard::Board(), CheckMoveOverflow(), SgPointSet::Clear(), SgVector< T >::Clear(), SgVector< T >::Concat(), FilterAdjacent(), GoBoard::GetStone(), GOOD_FOR_HUNTER, GOOD_FOR_PREY, HunterLadder(), InitMaxMoveNumber(), GoBoard::IsColor(), IsSnapback(), SgSList< T, SIZE >::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, and SgOppBW().

Referenced by GoLadderUtil::Ladder(), and GoLadderUtil::LadderStatus().

void GoLadder::MarkStonesAsPrey ( SgPoint  p,
SgVector< SgPoint > *  stones = 0 
) [private]

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 54 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 111 of file GoLadder.cpp.

References GoBoard::AreInSameBlock(), GoBoard::CapturingMove(), SgVector< T >::Clear(), GOOD_FOR_PREY, GoBoard::InAtari(), SgSList< T, SIZE >::Iterator, m_bd, m_hunterColor, GoBoardUtil::PlayIfLegal(), PreyLadder(), SgVector< T >::PushBack(), SgSList< 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 160 of file GoLadder.cpp.

References GoBoardUtil::AdjacentStones(), GoBoard::CapturedStones(), GoBoard::CapturingMove(), SgVector< T >::Clear(), SgPointSet::Exclude(), FilterAdjacent(), GOOD_FOR_HUNTER, GOOD_FOR_PREY, HunterLadder(), SgPointSet::Include(), SgVector< T >::Include(), GoBoard::IsEmpty(), SgVector< T >::IsEmpty(), SgSList< T, SIZE >::Iterator, SgVector< T >::Length(), m_bd, m_hunterColor, m_partOfPrey, m_preyColor, MarkStonesAsPrey(), GoBoardUtil::NeighborsOfColor(), GoBoardUtil::PlayIfLegal(), PointIsAdjToPrey(), SgVector< T >::PushBack(), SgSList< T, SIZE >::PushBackList(), SG_ASSERT, SG_EMPTY, and GoBoard::Undo().

Referenced by PreyLadder().

bool GoLadder::PointIsAdjToPrey ( SgPoint  p  )  [private]

Definition at line 91 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 254 of file GoLadder.cpp.

References BlockIsAdjToPrey(), CheckMoveOverflow(), GOOD_FOR_PREY, SgSList< T, SIZE >::Iterator, GoBoard::LibertyIterator, 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 369 of file GoLadder.cpp.

References SgSList< T, SIZE >::Contains(), GoBoard::IsEmpty(), SgSList< T, SIZE >::IsEmpty(), SgSList< T, SIZE >::Iterator, SgSList< T, SIZE >::Length(), m_bd, GoBoard::Occupied(), and SgSList< T, SIZE >::PushBack().

Referenced by FilterAdjacent(), and Ladder().


Member Data Documentation

GoBoard* GoLadder::m_bd [private]

Definition at line 64 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 70 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 62 of file GoLadder.h.

Referenced by CheckMoveOverflow(), and InitMaxMoveNumber().

SgPointSet GoLadder::m_partOfPrey [private]

Definition at line 66 of file GoLadder.h.

Referenced by Ladder(), MarkStonesAsPrey(), PlayPreyMove(), and PointIsAdjToPrey().

SgBlackWhite GoLadder::m_preyColor [private]

Definition at line 68 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 59 of file GoLadder.h.

Referenced by InitMaxMoveNumber().


The documentation for this class was generated from the following files:


17 Jun 2010 Doxygen 1.4.7