Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes

GoRegionBoard Class Reference

GoRegionBoard provides GoRegion, GoBlock and optionally GoChain. More...

#include <GoRegionBoard.h>

List of all members.

Public Member Functions

 GoRegionBoard (const GoBoard &board)
 Constructor.
virtual ~GoRegionBoard ()
 release memory.
void Clear ()
 delete all blocks and regions, set board size
void CheckConsistency () const
 For debugging.
bool UpToDate () const
 Have blocks and regions been computed for current board position?
bool ComputedHealthy () const
bool ChainsUpToDate () const
 Have chains been computed for current board position?
void ExecuteMovePrologue ()
 MUST call before playing move on GoBoard.
void OnExecutedMove (GoPlayerMove playerMove)
 Called after a move or added stone has been successfully executed.
void OnExecutedUncodedMove (int move, SgBlackWhite moveColor)
 Similar to OnExecutedMove, but move is not coded into one int.
void OnUndoneMove ()
 Called after a move has been undone.
SgVectorOf< GoBlock > & AllBlocks (SgBlackWhite color)
 All GoBlock's of given color.
const SgVectorOf< GoBlock > & AllBlocks (SgBlackWhite color) const
 All GoBlock's of given color.
SgVectorOf< GoChain > & AllChains (SgBlackWhite color)
 All GoChain's of given color.
const SgVectorOf< GoChain > & AllChains (SgBlackWhite color) const
 All GoChain's of given color.
SgVectorOf< GoRegion > & AllRegions (SgBlackWhite color)
 All GoRegion's of given color.
const SgVectorOf< GoRegion > & AllRegions (SgBlackWhite color) const
 All GoRegion's of given color.
const SgPointSetAll (SgBlackWhite color) const
 See GoBoard::All.
const SgPointSetAllEmpty () const
 See GoBoard::AllEmpty.
const SgPointSetAllPoints () const
 See GoBoard::AllPoints.
bool IsColor (SgPoint p, int c) const
 See GoBoard::IsColor.
void WriteBlocks (std::ostream &stream) const
 write information on all GoBlock's
void WriteRegions (std::ostream &stream) const
 write information on all GoRegion's
void GenBlocksRegions ()
 generate all blocks and regions
void GenChains ()
 Compute all GoChain's.
void ReInitializeBlocksRegions ()
 Clear all flags etc.
void SetComputedFlagForAll (GoRegionFlag flag)
 mark all regions that the given attribute has been computed
const GoBoardBoard () const
GoBlockGetBlock (const SgPointSet &boundary, SgBlackWhite color) const
 Searches the list of all blocks for the block.
GoRegionPreviousRegionAt (SgPoint p, SgBlackWhite color) const
 For incremental update, region where stone was just played.
GoRegionRegionAt (SgPoint p, SgBlackWhite color) const
 Region of color at point p.
void RegionsAt (const SgPointSet &area, SgBlackWhite color, SgVectorOf< GoRegion > *regions) const
 Region of color in area.
void AdjacentRegions (const SgVector< SgPoint > &points, SgBlackWhite color, SgVectorOf< GoRegion > *regions) const
 Region of color adjacent to points.
void PreviousBlocksAt (const SgVector< SgPoint > &area, SgBlackWhite color, SgVectorOf< GoBlock > *captures) const
 Return GoBlock's just captured on last move, before update.
GoBlockBlockAt (SgPoint p) const
 GoBlock at point p.
GoChainChainAt (SgPoint p) const
 GoChain at point p.
bool IsSafeBlock (SgPoint p) const
 Is block at point p marked as safe?
void SetToSafe (SgPoint p) const
 Set safe flag for block at p.
void SetSafeFlags (const SgBWSet &safe)
 Set safe flags for all blocks in safe.
void SetComputedHealthy ()
 Set m_computedHealthy flag to true.

Static Public Member Functions

static bool Init ()
 class initialization
static void Fini ()
 class finalization

Private Member Functions

void GenBlocks ()
 Generate blocks.
void FindBlocksWithEye ()
 Set the m_has1Eye flag for all blocks with 1 eye.
GoBlockGenBlock (SgPoint anchor, SgBlackWhite color)
 Generate the block with given anchor.
GoRegionGenRegion (const SgPointSet &area, SgBlackWhite color)
 Generate a region of color in area.
void UpdateBlock (int move, SgBlackWhite moveColor)
 incremental update of block after move
void SetRegionArrays (GoRegion *r)
 Sets m_region elements to point to r.
void AddBlock (GoBlock *b, bool isExecute=true)
 add block to GoRegionBoard
void RemoveBlock (GoBlock *b, bool isExecute, bool removeFromRegions)
 remove block from GoRegionBoard
void AddRegion (GoRegion *r, bool isExecute=true)
 add region to GoRegionBoard
void RemoveRegion (GoRegion *r, bool isExecute=true)
 remove region from GoRegionBoard
void MergeAdjacentAndAddBlock (SgPoint move, SgBlackWhite capturedColor)
 For all captured stones: merge its adjacent previous regions into one.
GoRegionMergeAll (const SgVectorOf< GoRegion > &regions, const SgPointSet &captured, SgBlackWhite color)
 Merge all regions and the captured area into new large region.
void PushRegion (int type, GoRegion *r)
 push on m_stack
void PushStone (GoRegion *r, SgPoint move)
 push on m_stack
void PushBlock (int type, GoBlock *b)
 push on m_stack
void AppendStone (GoBlock *b, SgPoint move)
 add stome to b and push information on m_stack

Private Attributes

SgIncrementalStack m_stack
 stores incremental state changes for execute/undo moves
const GoBoardm_board
SgBWArray< SgPointArray
< GoRegion * > > 
m_region
 pointer to region, defined only at anchor of region
SgPointArray< GoBlock * > m_block
 pointer from stone to block, 0 if empty point
SgBWArray< SgVectorOf< GoBlock > > m_allBlocks
 All blocks on board.
SgBWArray< SgVectorOf< GoChain > > m_allChains
 All chains on board.
SgBWArray< SgVectorOf< GoRegion > > m_allRegions
 All regions on board.
SgHashCode m_code
 Code for last time block and region information was computed.
SgHashCode m_chainsCode
 Code for last time chain information was computed.
bool m_invalid
 does block and region data match current board?
bool m_computedHealthy
 has healthy count been computed for all blocks?
int m_boardSize
 Boardsize is needed to avoid problems with resizing an empty board.

Static Private Attributes

static int s_alloc = 0
 debugging bookkeeping.
static int s_free = 0

Detailed Description

GoRegionBoard provides GoRegion, GoBlock and optionally GoChain.

To keep it updated during search, call OnExecutedMove (or OnExecutedUncodedMove) and OnUndoneMove when Executing/Undoing a move.

A GoRegionBoard depends on a GoBoard (supplied at construction) for keeping the low-level board state, Go rules etc.

There is a certain amount of duplication between the private blocks of a GoBoard and the GoBlock's in a GoRegionBoard.

GoChain's are not updated automatically for performance reasons

Definition at line 29 of file GoRegionBoard.h.


Constructor & Destructor Documentation

GoRegionBoard::GoRegionBoard ( const GoBoard board  )  [explicit]

Constructor.

Definition at line 69 of file GoRegionBoard.cpp.

References GenBlocksRegions(), SgHash< N >::Invalidate(), m_chainsCode, m_code, and s_alloc.

GoRegionBoard::~GoRegionBoard (  )  [virtual]

release memory.

Calls Clear()

Definition at line 83 of file GoRegionBoard.cpp.

References Clear(), and s_free.


Member Function Documentation

void GoRegionBoard::AddBlock ( GoBlock b,
bool  isExecute = true 
) [private]
void GoRegionBoard::AddRegion ( GoRegion r,
bool  isExecute = true 
) [private]
void GoRegionBoard::AdjacentRegions ( const SgVector< SgPoint > &  points,
SgBlackWhite  color,
SgVectorOf< GoRegion > *  regions 
) const

Region of color adjacent to points.

Definition at line 449 of file GoRegionBoard.cpp.

References AllRegions(), and SgVectorOf< T >::PushBack().

const SgPointSet& GoRegionBoard::All ( SgBlackWhite  color  )  const

See GoBoard::All.

Definition at line 115 of file GoRegionBoard.h.

References GoBoard::All(), and Board().

Referenced by GenBlocksRegions().

const SgVectorOf<GoBlock>& GoRegionBoard::AllBlocks ( SgBlackWhite  color  )  const

All GoBlock's of given color.

Definition at line 85 of file GoRegionBoard.h.

References m_allBlocks.

SgVectorOf<GoBlock>& GoRegionBoard::AllBlocks ( SgBlackWhite  color  ) 
const SgVectorOf<GoChain>& GoRegionBoard::AllChains ( SgBlackWhite  color  )  const

All GoChain's of given color.

Definition at line 97 of file GoRegionBoard.h.

References m_allChains.

SgVectorOf<GoChain>& GoRegionBoard::AllChains ( SgBlackWhite  color  ) 

All GoChain's of given color.

Definition at line 91 of file GoRegionBoard.h.

References m_allChains.

Referenced by ChainAt(), Clear(), GoRegion::FindChains(), GenChains(), and GoSafetySolver::Merge().

const SgPointSet& GoRegionBoard::AllEmpty (  )  const

See GoBoard::AllEmpty.

Definition at line 121 of file GoRegionBoard.h.

References GoBoard::AllEmpty(), and Board().

const SgPointSet& GoRegionBoard::AllPoints (  )  const

See GoBoard::AllPoints.

Definition at line 124 of file GoRegionBoard.h.

References GoBoard::AllPoints(), and Board().

Referenced by CheckConsistency(), and GenBlocksRegions().

SgVectorOf<GoRegion>& GoRegionBoard::AllRegions ( SgBlackWhite  color  ) 
const SgVectorOf<GoRegion>& GoRegionBoard::AllRegions ( SgBlackWhite  color  )  const

All GoRegion's of given color.

Definition at line 109 of file GoRegionBoard.h.

References m_allRegions.

void GoRegionBoard::AppendStone ( GoBlock b,
SgPoint  move 
) [private]

add stome to b and push information on m_stack

Definition at line 168 of file GoRegionBoard.cpp.

References GoBlock::AddStone(), m_block, m_stack, SgIncrementalStack::PushInt(), and SgIncrementalStack::PushPtrEvent().

Referenced by UpdateBlock().

GoBlock* GoRegionBoard::BlockAt ( SgPoint  p  )  const

GoBlock at point p.

Definition at line 193 of file GoRegionBoard.h.

References m_block, and SG_ASSERT.

Referenced by IsSafeBlock(), SetToSafe(), and UpdateBlock().

const GoBoard& GoRegionBoard::Board (  )  const
GoChain * GoRegionBoard::ChainAt ( SgPoint  p  )  const

GoChain at point p.

Definition at line 730 of file GoRegionBoard.cpp.

References AllChains(), Board(), ChainsUpToDate(), GoBoard::GetStone(), and SG_ASSERT.

bool GoRegionBoard::ChainsUpToDate (  )  const

Have chains been computed for current board position?

Definition at line 59 of file GoRegionBoard.h.

References Board(), GoBoard::GetHashCode(), m_chainsCode, and UpToDate().

Referenced by ChainAt(), and GenChains().

void GoRegionBoard::CheckConsistency (  )  const
void GoRegionBoard::Clear (  ) 
bool GoRegionBoard::ComputedHealthy (  )  const

Definition at line 53 of file GoRegionBoard.h.

References m_computedHealthy.

void GoRegionBoard::ExecuteMovePrologue (  ) 

MUST call before playing move on GoBoard.

Definition at line 182 of file GoRegionBoard.cpp.

References GenBlocksRegions(), SgDebug(), and UpToDate().

void GoRegionBoard::FindBlocksWithEye (  )  [private]

Set the m_has1Eye flag for all blocks with 1 eye.

Definition at line 633 of file GoRegionBoard.cpp.

References AllRegions().

Referenced by GenBlocksRegions().

void GoRegionBoard::Fini (  )  [static]

class finalization

Definition at line 47 of file GoRegionBoard.cpp.

References s_alloc, s_free, and SG_ASSERT.

GoBlock * GoRegionBoard::GenBlock ( SgPoint  anchor,
SgBlackWhite  color 
) [private]

Generate the block with given anchor.

Definition at line 391 of file GoRegionBoard.cpp.

References AddBlock(), and Board().

Referenced by GenBlocks(), and UpdateBlock().

void GoRegionBoard::GenBlocks (  )  [private]

Generate blocks.

Definition at line 743 of file GoRegionBoard.cpp.

References Board(), and GenBlock().

Referenced by GenBlocksRegions().

void GoRegionBoard::GenBlocksRegions (  ) 
void GoRegionBoard::GenChains (  ) 

Compute all GoChain's.

Todo:
currently this only creates 1 chain for each block.

The merging is only done in GoSafetySolver::GenBlocksRegions() and must be moved here.

Definition at line 671 of file GoRegionBoard.cpp.

References AllBlocks(), AllChains(), AllRegions(), Board(), ChainsUpToDate(), GoBoard::GetHashCode(), m_chainsCode, SgVectorOf< T >::PushBack(), and SG_ASSERT.

Referenced by GoSafetySolver::GenBlocksRegions().

GoRegion * GoRegionBoard::GenRegion ( const SgPointSet area,
SgBlackWhite  color 
) [private]

Generate a region of color in area.

Definition at line 606 of file GoRegionBoard.cpp.

References AddRegion(), and Board().

Referenced by GenBlocksRegions(), MergeAll(), and OnExecutedUncodedMove().

GoBlock * GoRegionBoard::GetBlock ( const SgPointSet boundary,
SgBlackWhite  color 
) const

Searches the list of all blocks for the block.

Boundary must belong to a single block.

Definition at line 709 of file GoRegionBoard.cpp.

References AllBlocks(), Board(), SG_ASSERT, SgDebug(), GoBoard::Size(), SgPointSet::SubsetOf(), UpToDate(), and SgPointSet::Write().

static bool GoRegionBoard::Init (  )  [static]

class initialization

bool GoRegionBoard::IsColor ( SgPoint  p,
int  c 
) const

See GoBoard::IsColor.

Definition at line 127 of file GoRegionBoard.h.

References Board(), and GoBoard::IsColor().

Referenced by RegionAt(), and UpdateBlock().

bool GoRegionBoard::IsSafeBlock ( SgPoint  p  )  const

Is block at point p marked as safe?

Definition at line 37 of file GoRegionBoard.cpp.

References BlockAt(), and GoBlock::IsSafe().

void GoRegionBoard::MergeAdjacentAndAddBlock ( SgPoint  move,
SgBlackWhite  capturedColor 
) [private]

For all captured stones: merge its adjacent previous regions into one.

then for all captured stones: add their area to its single adjacent region.

Definition at line 473 of file GoRegionBoard.cpp.

References Board(), MergeAll(), SgVectorOf< T >::NonEmpty(), PreviousBlocksAt(), SgVector< T >::PushBack(), RegionsAt(), RemoveBlock(), SG_ASSERT, SG_UNUSED(), and GoBoard::Size().

Referenced by OnExecutedUncodedMove().

GoRegion * GoRegionBoard::MergeAll ( const SgVectorOf< GoRegion > &  regions,
const SgPointSet captured,
SgBlackWhite  color 
) [private]

Merge all regions and the captured area into new large region.

Definition at line 458 of file GoRegionBoard.cpp.

References GenRegion(), and RemoveRegion().

Referenced by MergeAdjacentAndAddBlock().

void GoRegionBoard::OnExecutedMove ( GoPlayerMove  playerMove  ) 

Called after a move or added stone has been successfully executed.

The board is guaranteed to be in a legal state.

Definition at line 177 of file GoRegionBoard.cpp.

References GoPlayerMove::Color(), OnExecutedUncodedMove(), and GoPlayerMove::Point().

void GoRegionBoard::OnExecutedUncodedMove ( int  move,
SgBlackWhite  moveColor 
)
void GoRegionBoard::OnUndoneMove (  ) 
void GoRegionBoard::PreviousBlocksAt ( const SgVector< SgPoint > &  area,
SgBlackWhite  color,
SgVectorOf< GoBlock > *  captures 
) const

Return GoBlock's just captured on last move, before update.

For incremental update. Can be called for any empty point. returns 0 if no previous block there.

Definition at line 399 of file GoRegionBoard.cpp.

References SgVectorOf< T >::Include(), m_block, and SG_UNUSED().

Referenced by MergeAdjacentAndAddBlock().

GoRegion* GoRegionBoard::PreviousRegionAt ( SgPoint  p,
SgBlackWhite  color 
) const

For incremental update, region where stone was just played.

Definition at line 161 of file GoRegionBoard.h.

References Board(), m_region, and SG_ASSERT.

Referenced by OnExecutedUncodedMove().

void GoRegionBoard::PushBlock ( int  type,
GoBlock b 
) [private]

push on m_stack

Definition at line 303 of file GoRegionBoard.cpp.

References m_stack, and SgIncrementalStack::PushPtrEvent().

Referenced by AddBlock(), and RemoveBlock().

void GoRegionBoard::PushRegion ( int  type,
GoRegion r 
) [private]

push on m_stack

Definition at line 298 of file GoRegionBoard.cpp.

References m_stack, and SgIncrementalStack::PushPtrEvent().

Referenced by AddRegion(), and RemoveRegion().

void GoRegionBoard::PushStone ( GoRegion r,
SgPoint  move 
) [private]
GoRegion* GoRegionBoard::RegionAt ( SgPoint  p,
SgBlackWhite  color 
) const

Region of color at point p.

Definition at line 169 of file GoRegionBoard.h.

References Board(), IsColor(), m_region, SG_ASSERT, and UpToDate().

void GoRegionBoard::RegionsAt ( const SgPointSet area,
SgBlackWhite  color,
SgVectorOf< GoRegion > *  regions 
) const

Region of color in area.

Definition at line 441 of file GoRegionBoard.cpp.

References AllRegions(), and SgVectorOf< T >::PushBack().

Referenced by MergeAdjacentAndAddBlock(), RemoveBlock(), and UpdateBlock().

void GoRegionBoard::ReInitializeBlocksRegions (  ) 

Clear all flags etc.

to recompute regions and blocks

Definition at line 592 of file GoRegionBoard.cpp.

References AllBlocks(), AllRegions(), SG_ASSERT, and UpToDate().

Referenced by GoStaticSafetySolver::GenBlocksRegions().

void GoRegionBoard::RemoveBlock ( GoBlock b,
bool  isExecute,
bool  removeFromRegions 
) [private]
void GoRegionBoard::RemoveRegion ( GoRegion r,
bool  isExecute = true 
) [private]
void GoRegionBoard::SetComputedFlagForAll ( GoRegionFlag  flag  ) 

mark all regions that the given attribute has been computed

Definition at line 749 of file GoRegionBoard.cpp.

References AllRegions().

Referenced by GoStaticSafetySolver::FindSafePoints().

void GoRegionBoard::SetComputedHealthy (  ) 

Set m_computedHealthy flag to true.

Definition at line 760 of file GoRegionBoard.cpp.

References m_computedHealthy.

Referenced by GoStaticSafetySolver::FindHealthy().

void GoRegionBoard::SetRegionArrays ( GoRegion r  )  [private]

Sets m_region elements to point to r.

Definition at line 338 of file GoRegionBoard.cpp.

References GoRegion::Color(), m_region, and GoRegion::Points().

Referenced by AddRegion().

void GoRegionBoard::SetSafeFlags ( const SgBWSet safe  ) 

Set safe flags for all blocks in safe.

Definition at line 53 of file GoRegionBoard.cpp.

References AllBlocks(), and AllRegions().

Referenced by GoSafetySolver::FindSafePair(), GoSafetySolver::FindSurroundedSafeAreas(), and GoSafetySolver::FindSurroundedSingleRegion().

void GoRegionBoard::SetToSafe ( SgPoint  p  )  const

Set safe flag for block at p.

Definition at line 42 of file GoRegionBoard.cpp.

References BlockAt(), and GoBlock::SetToSafe().

void GoRegionBoard::UpdateBlock ( int  move,
SgBlackWhite  moveColor 
) [private]
bool GoRegionBoard::UpToDate (  )  const
void GoRegionBoard::WriteBlocks ( std::ostream &  stream  )  const

write information on all GoBlock's

Definition at line 689 of file GoRegionBoard.cpp.

References AllBlocks().

void GoRegionBoard::WriteRegions ( std::ostream &  stream  )  const

write information on all GoRegion's

Definition at line 699 of file GoRegionBoard.cpp.

References AllRegions().


Member Data Documentation

All blocks on board.

Definition at line 290 of file GoRegionBoard.h.

Referenced by AllBlocks(), Clear(), and RemoveBlock().

All chains on board.

Definition at line 293 of file GoRegionBoard.h.

Referenced by AllChains(), and Clear().

All regions on board.

Definition at line 296 of file GoRegionBoard.h.

Referenced by AllRegions(), Clear(), and RemoveRegion().

pointer from stone to block, 0 if empty point

Definition at line 287 of file GoRegionBoard.h.

Referenced by AddBlock(), AppendStone(), BlockAt(), CheckConsistency(), Clear(), OnUndoneMove(), PreviousBlocksAt(), and RemoveBlock().

const GoBoard& GoRegionBoard::m_board [private]

Definition at line 281 of file GoRegionBoard.h.

Referenced by Board(), Clear(), and UpToDate().

Boardsize is needed to avoid problems with resizing an empty board.

Definition at line 313 of file GoRegionBoard.h.

Referenced by Clear(), and UpToDate().

Code for last time chain information was computed.

Definition at line 302 of file GoRegionBoard.h.

Referenced by ChainsUpToDate(), GenChains(), and GoRegionBoard().

Code for last time block and region information was computed.

Definition at line 299 of file GoRegionBoard.h.

Referenced by Clear(), GenBlocksRegions(), GoRegionBoard(), OnExecutedUncodedMove(), OnUndoneMove(), and UpToDate().

has healthy count been computed for all blocks?

Todo:
in fully incremental mode, this should be determined locally for each block, not globally.

Definition at line 310 of file GoRegionBoard.h.

Referenced by Clear(), ComputedHealthy(), and SetComputedHealthy().

bool GoRegionBoard::m_invalid [private]

does block and region data match current board?

Definition at line 305 of file GoRegionBoard.h.

Referenced by Clear(), GenBlocksRegions(), and UpToDate().

pointer to region, defined only at anchor of region

Definition at line 284 of file GoRegionBoard.h.

Referenced by CheckConsistency(), Clear(), OnUndoneMove(), PreviousRegionAt(), PushStone(), RegionAt(), RemoveRegion(), and SetRegionArrays().

stores incremental state changes for execute/undo moves

Definition at line 265 of file GoRegionBoard.h.

Referenced by AppendStone(), Clear(), OnExecutedUncodedMove(), OnUndoneMove(), PushBlock(), PushRegion(), PushStone(), and RemoveBlock().

int GoRegionBoard::s_alloc = 0 [static, private]

debugging bookkeeping.

Todo:
do it in debug only

Definition at line 316 of file GoRegionBoard.h.

Referenced by Fini(), and GoRegionBoard().

int GoRegionBoard::s_free = 0 [static, private]

Definition at line 316 of file GoRegionBoard.h.

Referenced by Fini(), and ~GoRegionBoard().


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


Sun Mar 13 2011 Doxygen 1.7.1