ConstBoard contains data and methods for dealing with the constant aspects of a Hex board. More...
#include <ConstBoard.hpp>
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 ConstBoard & | Get (int size) |
Creates a square board or returns pre-existing instance of a board of that size. | |
static ConstBoard & | Get (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< HexPoint > | m_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< HexPoint > | m_neighbours [BITSETSIZE][Pattern::MAX_EXTENSION+1] |
Neigbour lists for each location and radius. |
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.
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.
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.
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] |
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] |
Definition at line 163 of file ConstBoard.cpp.
References AllValid(), EdgesAndInterior(), Interior(), m_cells, m_locations, m_valid, benzene_bitset< _Nb >::reset(), and benzene_bitset< _Nb >::set().
Referenced by Init().
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().
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] |
Returns iterator to the board cells, starting on the outer edges.
Definition at line 260 of file ConstBoard.hpp.
References m_locations_index, and m_points.
Referenced by VCSet::AllocateAndCopyLists(), GroupBuilder::Build(), VCSet::Clear(), VCBuilder::ComputeCapturedSets(), ComputeNeighbours(), ComputeValid(), VCSet::FreeLists(), VCSet::operator==(), VCSet::SetSoftLimit(), and VCSet::VCSet().
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] |
Returns a bitset with all valid board cells.
Definition at line 210 of file ConstBoard.hpp.
References m_cells.
Referenced by BoardUtils::FindSplittingDecomposition(), StoneBoard::GetLegal(), VCPattern::Matches(), PatternState::MatchOnBoard(), BoardUtils::RandomEmptyCell(), HexSgUtil::SetPositionInNode(), DfsSolver::SolveDecomposition(), and StoneBoard::WhoseTurn().
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] |
Returns the height of the board.
Definition at line 205 of file ConstBoard.hpp.
References m_height.
Referenced by BoardUtils::CenterPoint(), BoardUtils::CenterPointLeft(), BoardUtils::CenterPointRight(), ComputePointList(), BoardUtils::CoordsToPoint(), DfsSolverUtil::DistanceFromCenter(), StoneBoard::Height(), BookUtil::ImportSolvedStates(), Init(), PatternMatcherData::Initialize(), BoardUtils::Mirror(), and BoardUtils::Rotate().
void ConstBoard::Init | ( | ) | [private] |
Definition at line 123 of file ConstBoard.cpp.
References ComputeNeighbours(), ComputePointList(), ComputeValid(), CreateIterators(), Height(), LogFine(), and Width().
Referenced by ConstBoard().
BoardIterator ConstBoard::Interior | ( | ) | const [inline] |
Returns iterator to the interior board cells.
Definition at line 255 of file ConstBoard.hpp.
References m_cells_index, and m_points.
Referenced by HandicapPlayer::buildResponseMap(), PatternState::ClearGodels(), BenzeneHtpEngine::CmdEvalInfluence(), BenzeneHtpEngine::CmdEvalResist(), BenzeneHtpEngine::CmdEvalTwoDist(), ComputeNeighbours(), TwoDistance::ComputeScores(), ComputeValid(), PatternMatcherData::Initialize(), and TwoDistance::SetAllToInfinity().
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.
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] |
Returns the width of the board.
Definition at line 200 of file ConstBoard.hpp.
References m_width.
Referenced by BoardUtils::CenterPoint(), BoardUtils::CenterPointLeft(), BoardUtils::CenterPointRight(), ComputePointList(), BoardUtils::CoordsToPoint(), DfsSolverUtil::DistanceFromCenter(), Get(), BookUtil::ImportSolvedStates(), Init(), PatternMatcherData::Initialize(), BoardUtils::Mirror(), BoardUtils::Rotate(), and StoneBoard::Width().
int ConstBoard::m_all_index [private] |
Will probably always be zero.
Definition at line 158 of file ConstBoard.hpp.
Referenced by AllValid(), and CreateIterators().
bitset_t ConstBoard::m_cells [private] |
All valid interior cells.
Definition at line 173 of file ConstBoard.hpp.
Referenced by ComputeValid(), GetCells(), and IsCell().
int ConstBoard::m_cells_index [private] |
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==().
bitset_t ConstBoard::m_locations [private] |
All valid locations.
Definition at line 170 of file ConstBoard.hpp.
Referenced by ComputeValid(), GetLocations(), and IsLocation().
int ConstBoard::m_locations_index [private] |
Index in points where edges start.
Definition at line 161 of file ConstBoard.hpp.
Referenced by CreateIterators(), and EdgesAndInterior().
std::vector<HexPoint> ConstBoard::m_neighbours[BITSETSIZE][Pattern::MAX_EXTENSION+1] [private] |
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().
bitset_t ConstBoard::m_valid [private] |
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().