Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

ConstBoard Class Reference

ConstBoard contains data and methods for dealing with the constant aspects of a Hex board. More...

#include <ConstBoard.hpp>

List of all members.

Public Member Functions

int Width () const
 Returns the width of the board.
int Height () const
 Returns the height of the board.
bitset_t GetCells () const
 Returns a bitset with all valid board cells.
bitset_t GetLocations () const
 Returns a bitset with all valid board locations (cells and edges).
bitset_t GetValid () const
 Returns a bitset of cells comprising all valid moves (this includes swap and resign).
bool IsCell (HexPoint cell) const
 Returns true if cell is a valid cell on this board.
bool IsCell (const bitset_t &bs) const
 Returns true if bs encodes a set of valid cells.
bool IsLocation (HexPoint cell) const
 Returns true if cell is a location on this board.
bool IsLocation (const bitset_t &bs) const
 Returns true if bs encodes a set of valid locations.
bool IsValid (HexPoint cell) const
 Returns true if cell is a valid move on this board.
bool IsValid (const bitset_t &bs) const
 Returns true if bs encodes a set of valid moves.
bool Adjacent (HexPoint p1, HexPoint p2) const
 Returns true if p1 is adjacent to p2.
int Distance (HexPoint x, HexPoint y) const
 Returns the distance between two valid HexPoints.
BoardIterator Interior () const
 Returns iterator to the interior board cells.
BoardIterator EdgesAndInterior () const
 Returns iterator to the board cells, starting on the outer edges.
BoardIterator AllValid () const
 Returns iterator that runs over all valid moves.
BoardIterator Nbs (HexPoint cell) const
 Returns iterator to the first neighbour of cell.
BoardIterator Nbs (HexPoint cell, int radius) const
 Returns iterator to the neighbourhood extending outward by radius cells of cell.
Operators

bool operator== (const ConstBoard &other) const
bool operator!= (const ConstBoard &other) const

Static Public Member Functions

static ConstBoardGet (int size)
 Creates a square board or returns pre-existing instance of a board of that size.
static ConstBoardGet (int width, int height)
 Creates a non-square board or returns pre-existing instance of a board of that size.

Private Member Functions

 ConstBoard (int size)
 Constructs a square board.
 ConstBoard (int width, int height)
 Constructs a rectangular board.
 ~ConstBoard ()
 Destructor.
void Init ()
void ComputeNeighbours ()
void ComputePointList ()
void CreateIterators ()
void ComputeValid ()

Private Attributes

int m_width
int m_height
std::vector< HexPointm_points
 The set of all valid cells/moves.
int m_all_index
 Will probably always be zero.
int m_locations_index
 Index in points where edges start.
int m_cells_index
 Index in points where interior cells start.
bitset_t m_valid
 All valid moves/cells.
bitset_t m_locations
 All valid locations.
bitset_t m_cells
 All valid interior cells.
std::vector< HexPointm_neighbours [BITSETSIZE][Pattern::MAX_EXTENSION+1]
 Neigbour lists for each location and radius.

Detailed Description

ConstBoard contains data and methods for dealing with the constant aspects of a Hex board.

That is, ConstBoard stores a cell's neighbours, cell-to-cell distances, etc. It also offers iterators to run over the board and the neighbours of a cell.

Only a single instance of ConstBoard exists for each boardsize.

See Board Representation for how the points are laid out on an example board, and Cell Neighbours for a discussion on how neighbours are calculated.

This class does not track played stones. To keep track of played stone information see StoneBoard.

Definition at line 58 of file ConstBoard.hpp.


Constructor & Destructor Documentation

ConstBoard::ConstBoard ( int  size  )  [private]

Constructs a square board.

Definition at line 68 of file ConstBoard.cpp.

References HexAssert, Init(), m_height, m_width, MAX_HEIGHT, and MAX_WIDTH.

Referenced by Get().

ConstBoard::ConstBoard ( int  width,
int  height 
) [private]

Constructs a rectangular board.

Definition at line 77 of file ConstBoard.cpp.

References HexAssert, Init(), m_height, m_width, MAX_HEIGHT, and MAX_WIDTH.

ConstBoard::~ConstBoard (  )  [private]

Destructor.

Definition at line 86 of file ConstBoard.cpp.


Member Function Documentation

bool ConstBoard::Adjacent ( HexPoint  p1,
HexPoint  p2 
) const

Returns true if p1 is adjacent to p2.

Iterates over neighbour list of p1, so not O(1).

Definition at line 92 of file ConstBoard.cpp.

References Nbs().

Referenced by VCUtils::ValidEdgeBridge().

BoardIterator ConstBoard::AllValid (  )  const [inline]

Returns iterator that runs over all valid moves.

Definition at line 265 of file ConstBoard.hpp.

References m_all_index, and m_points.

Referenced by ComputeValid().

void ConstBoard::ComputeNeighbours (  )  [private]

Add edges to neighbour lists of neighbouring edges.

Bug:
NORTH is now distance 2 from SOUTH, but won't appear in the neighbour lists for r >= 2; likewise for EAST/WEST.

Definition at line 178 of file ConstBoard.cpp.

References BoardUtils::CoordsToPoint(), HexPointUtil::DeltaX(), HexPointUtil::DeltaY(), EdgesAndInterior(), Interior(), INVALID_POINT, HexPointUtil::isEdge(), HexPointUtil::leftEdge(), m_neighbours, Pattern::MAX_EXTENSION, NUM_DIRECTIONS, HexPointUtil::pointToCoords(), and HexPointUtil::rightEdge().

Referenced by Init().

void ConstBoard::ComputePointList (  )  [private]

Note:
There are several pieces of code that rely on the fact points are visited in the order (a1,b1,...,a2,b2,...,etc) (StoneBoard::GetBoardID() is one). Do not change this order unless you know what you are doing!!.

Definition at line 133 of file ConstBoard.cpp.

References HexPointUtil::coordsToPoint(), FIRST_CELL, FIRST_SPECIAL, Height(), INVALID_POINT, m_points, and Width().

Referenced by Init().

void ConstBoard::ComputeValid (  )  [private]
void ConstBoard::CreateIterators (  )  [private]

Definition at line 150 of file ConstBoard.cpp.

References FIRST_CELL, FIRST_EDGE, FIRST_SPECIAL, m_all_index, m_cells_index, m_locations_index, and m_points.

Referenced by Init().

int ConstBoard::Distance ( HexPoint  x,
HexPoint  y 
) const

Returns the distance between two valid HexPoints.

Definition at line 100 of file ConstBoard.cpp.

References HexAssert, HexPointUtil::isEdge(), IsValid(), and HexPointUtil::pointToCoords().

Referenced by DfsSolverUtil::DistanceFromCenter().

BoardIterator ConstBoard::EdgesAndInterior (  )  const [inline]
ConstBoard & ConstBoard::Get ( int  width,
int  height 
) [static]

Creates a non-square board or returns pre-existing instance of a board of that size.

Definition at line 52 of file ConstBoard.cpp.

References ConstBoard(), and Width().

ConstBoard & ConstBoard::Get ( int  size  )  [static]

Creates a square board or returns pre-existing instance of a board of that size.

Definition at line 47 of file ConstBoard.cpp.

bitset_t ConstBoard::GetCells (  )  const [inline]
bitset_t ConstBoard::GetLocations (  )  const [inline]

Returns a bitset with all valid board locations (cells and edges).

Definition at line 215 of file ConstBoard.hpp.

References m_locations.

Referenced by StoneBoard::ComputeHash(), StoneBoard::GetBlack(), StoneBoard::GetColor(), StoneBoard::GetEmpty(), StoneBoard::GetOccupied(), and StoneBoard::GetWhite().

bitset_t ConstBoard::GetValid (  )  const [inline]

Returns a bitset of cells comprising all valid moves (this includes swap and resign).

Definition at line 220 of file ConstBoard.hpp.

References m_valid.

int ConstBoard::Height (  )  const [inline]
void ConstBoard::Init (  )  [private]
BoardIterator ConstBoard::Interior (  )  const [inline]
bool ConstBoard::IsCell ( const bitset_t bs  )  const [inline]

Returns true if bs encodes a set of valid cells.

Definition at line 230 of file ConstBoard.hpp.

References BitsetUtil::IsSubsetOf(), and m_cells.

bool ConstBoard::IsCell ( HexPoint  cell  )  const [inline]

Returns true if cell is a valid cell on this board.

Definition at line 225 of file ConstBoard.hpp.

References m_cells, and benzene_bitset< _Nb >::test().

Referenced by PatternState::CheckRotatedPattern(), and PatternState::UpdateRingGodel().

bool ConstBoard::IsLocation ( const bitset_t bs  )  const [inline]

Returns true if bs encodes a set of valid locations.

Definition at line 240 of file ConstBoard.hpp.

References BitsetUtil::IsSubsetOf(), and m_locations.

bool ConstBoard::IsLocation ( HexPoint  cell  )  const [inline]

Returns true if cell is a location on this board.

Definition at line 235 of file ConstBoard.hpp.

References m_locations, and benzene_bitset< _Nb >::test().

Referenced by Groups::CaptainizeBitset(), BoardUtils::Mirror(), Nbs(), BoardUtils::Rotate(), and PatternState::Update().

bool ConstBoard::IsValid ( const bitset_t bs  )  const [inline]

Returns true if bs encodes a set of valid moves.

Definition at line 250 of file ConstBoard.hpp.

References BitsetUtil::IsSubsetOf(), and m_valid.

bool ConstBoard::IsValid ( HexPoint  cell  )  const [inline]

Returns true if cell is a valid move on this board.

Definition at line 245 of file ConstBoard.hpp.

References m_valid, and benzene_bitset< _Nb >::test().

Referenced by Distance(), BoardUtils::Mirror(), Game::PlayMove(), and BoardUtils::Rotate().

BoardIterator ConstBoard::Nbs ( HexPoint  cell,
int  radius 
) const [inline]

Returns iterator to the neighbourhood extending outward by radius cells of cell.

Definition at line 276 of file ConstBoard.hpp.

References HexAssert, IsLocation(), m_neighbours, and Pattern::MAX_EXTENSION.

BoardIterator ConstBoard::Nbs ( HexPoint  cell  )  const [inline]

Returns iterator to the first neighbour of cell.

See also:
Cell Neighbours

Definition at line 270 of file ConstBoard.hpp.

References HexAssert, IsLocation(), and m_neighbours.

Referenced by Adjacent(), VCBuilder::Merge(), PatternState::Update(), and VCUtils::ValidEdgeBridge().

bool ConstBoard::operator!= ( const ConstBoard other  )  const [inline]

Definition at line 289 of file ConstBoard.hpp.

References operator==().

bool ConstBoard::operator== ( const ConstBoard other  )  const [inline]

Definition at line 283 of file ConstBoard.hpp.

References m_height, and m_width.

Referenced by operator!=().

int ConstBoard::Width (  )  const [inline]

Member Data Documentation

int ConstBoard::m_all_index [private]

Will probably always be zero.

Todo:
remove?

Definition at line 158 of file ConstBoard.hpp.

Referenced by AllValid(), and CreateIterators().

All valid interior cells.

Definition at line 173 of file ConstBoard.hpp.

Referenced by ComputeValid(), GetCells(), and IsCell().

Index in points where interior cells start.

Definition at line 164 of file ConstBoard.hpp.

Referenced by CreateIterators(), and Interior().

int ConstBoard::m_height [private]

Definition at line 150 of file ConstBoard.hpp.

Referenced by ConstBoard(), Height(), and operator==().

All valid locations.

Definition at line 170 of file ConstBoard.hpp.

Referenced by ComputeValid(), GetLocations(), and IsLocation().

Index in points where edges start.

Definition at line 161 of file ConstBoard.hpp.

Referenced by CreateIterators(), and EdgesAndInterior().

Neigbour lists for each location and radius.

Definition at line 176 of file ConstBoard.hpp.

Referenced by ComputeNeighbours(), and Nbs().

std::vector<HexPoint> ConstBoard::m_points [private]

The set of all valid cells/moves.

Assumed to be in the following order: special moves, edges, interior cells.

Definition at line 154 of file ConstBoard.hpp.

Referenced by AllValid(), ComputePointList(), CreateIterators(), EdgesAndInterior(), and Interior().

All valid moves/cells.

Definition at line 167 of file ConstBoard.hpp.

Referenced by ComputeValid(), GetValid(), and IsValid().

int ConstBoard::m_width [private]

Definition at line 148 of file ConstBoard.hpp.

Referenced by ConstBoard(), operator==(), and Width().


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


6 Jan 2011 Doxygen 1.6.3