Constant data for a given board size for games with square boards. More...
#include <SgBoardConst.h>
Classes | |
struct | BoardConstImpl |
Public Member Functions | |
SgBoardConst (SgGrid size) | |
void | ChangeSize (SgGrid newSize) |
Change the information for this object to another size. | |
SgGrid | Size () const |
Get board size. | |
SgGrid | Line (SgPoint p) const |
Distance from the nearest border point. | |
SgGrid | Pos (SgPoint p) const |
The distance to the second-closest border point. | |
int | Up (SgPoint p) const |
Offset for neighboring point away from edge of board. | |
int | Left (SgPoint p) const |
Offset for neighbor to the left, when looking in Up() direction. | |
int | Right (SgPoint p) const |
int | Side (SgPoint p, int i) const |
const SgPointSet & | Corners () const |
Set of points in corners of the board. | |
const SgPointSet & | Edges () const |
Set of points on edge but not in corners of the board. | |
const SgPointSet & | Centers () const |
All points on board not in Corners() or Edges(). | |
const SgPointSet & | SideExtensions () const |
Points for standard side extensions on lines 2 to 4. | |
const SgPointSet & | LineSet (SgGrid line) const |
Set of all points on given line. | |
int | FirstBoardPoint () const |
Upper left corner of the board. | |
int | LastBoardPoint () const |
See FirstBoardPoint. | |
const SgPoint * | NeighborIterAddress (SgPoint p) const |
List of on-board neighbor points terminated by SG_ENDPOINT. | |
const SgPoint * | BoardIterAddress () const |
const SgPoint * | BoardIterEnd () const |
const SgPoint * | LineIterAddress (SgGrid line) const |
const SgPoint * | CornerIterAddress () const |
Private Types | |
typedef SgArray < boost::shared_ptr < BoardConstImpl > , SG_MAX_SIZE+1 > | BoardConstImplArray |
Private Member Functions | |
void | Create (SgGrid size) |
Private Attributes | |
boost::shared_ptr< BoardConstImpl > | m_const |
Static Private Attributes | |
static BoardConstImplArray | s_const |
Constant data for a given board size for games with square boards.
All boards created with the same board size share the same data to reduce memory consumption and increase cache hits.
Definition at line 22 of file SgBoardConst.h.
typedef SgArray<boost::shared_ptr<BoardConstImpl>,SG_MAX_SIZE + 1> SgBoardConst::BoardConstImplArray [private] |
Definition at line 147 of file SgBoardConst.h.
SgBoardConst::SgBoardConst | ( | SgGrid | size | ) |
Definition at line 194 of file SgBoardConst.cpp.
References Create(), SG_ASSERT_GRIDRANGE, and SgInitCheck().
const SgPoint * SgBoardConst::BoardIterAddress | ( | ) | const |
Definition at line 231 of file SgBoardConst.h.
References m_const.
const SgPoint * SgBoardConst::BoardIterEnd | ( | ) | const |
Definition at line 236 of file SgBoardConst.h.
References m_const.
const SgPointSet & SgBoardConst::Centers | ( | ) | const |
All points on board not in Corners() or Edges().
Definition at line 206 of file SgBoardConst.h.
References m_const.
void SgBoardConst::ChangeSize | ( | SgGrid | newSize | ) |
Change the information for this object to another size.
Does nothing if 'newSize' is the same.
Definition at line 201 of file SgBoardConst.cpp.
References Create(), m_const, SG_ASSERT, and SG_ASSERT_GRIDRANGE.
const SgPoint * SgBoardConst::CornerIterAddress | ( | ) | const |
Definition at line 246 of file SgBoardConst.h.
References m_const.
const SgPointSet & SgBoardConst::Corners | ( | ) | const |
Set of points in corners of the board.
On 12x12 boards and larger, this includes 5x5 area from corner except the 5,5 point itself (the classical opening moves and below). See SgBoardConst::BoardConstImpl::BoardConstImpl for details. On smaller boards, includes the 4x4 area except the 4,4 point itself.
Definition at line 196 of file SgBoardConst.h.
References m_const.
void SgBoardConst::Create | ( | SgGrid | size | ) | [private] |
Definition at line 184 of file SgBoardConst.cpp.
References m_const, s_const, SG_ASSERT, and SG_ASSERT_GRIDRANGE.
Referenced by ChangeSize(), and SgBoardConst().
const SgPointSet & SgBoardConst::Edges | ( | ) | const |
Set of points on edge but not in corners of the board.
On 12x12 boards and larger, this includes points on lines 1-4. On smaller boards, lines 1 to 3.
Definition at line 201 of file SgBoardConst.h.
References m_const.
int SgBoardConst::FirstBoardPoint | ( | ) | const |
Upper left corner of the board.
Using FirstBoardPoint and LastBoardPoint the board points can be traversed with a for-loop. This avoids the border points before and after the board, but not the ones to the side of the board; one must still check for border fields within the loop.
Definition at line 221 of file SgBoardConst.h.
References m_const.
int SgBoardConst::LastBoardPoint | ( | ) | const |
int SgBoardConst::Left | ( | SgPoint | p | ) | const |
Distance from the nearest border point.
Points on the edge of the board have distance 1; border (off-board) points have distance 0.
Definition at line 161 of file SgBoardConst.h.
References m_const.
Definition at line 241 of file SgBoardConst.h.
References m_const.
const SgPointSet & SgBoardConst::LineSet | ( | SgGrid | line | ) | const |
List of on-board neighbor points terminated by SG_ENDPOINT.
Points are sorted from low to high.
Definition at line 166 of file SgBoardConst.h.
References m_const.
The distance to the second-closest border point.
Points on the edge of the board have distance 1; border (off-board) points have distance 0.
Definition at line 171 of file SgBoardConst.h.
References m_const.
int SgBoardConst::Right | ( | SgPoint | p | ) | const |
Definition at line 186 of file SgBoardConst.h.
int SgBoardConst::Side | ( | SgPoint | p, | |
int | i | |||
) | const |
Definition at line 191 of file SgBoardConst.h.
References m_const, SG_NS, and SG_WE.
Referenced by SgSideIterator::operator*(), and SgSideIterator::SgSideIterator().
const SgPointSet & SgBoardConst::SideExtensions | ( | ) | const |
Points for standard side extensions on lines 2 to 4.
Definition at line 211 of file SgBoardConst.h.
References m_const.
SgGrid SgBoardConst::Size | ( | ) | const |
int SgBoardConst::Up | ( | SgPoint | p | ) | const |
Offset for neighboring point away from edge of board.
Definition at line 176 of file SgBoardConst.h.
References m_const.
boost::shared_ptr<BoardConstImpl> SgBoardConst::m_const [private] |
Definition at line 149 of file SgBoardConst.h.
Referenced by BoardIterAddress(), BoardIterEnd(), Centers(), ChangeSize(), CornerIterAddress(), Corners(), Create(), Edges(), FirstBoardPoint(), LastBoardPoint(), Left(), Line(), LineIterAddress(), LineSet(), NeighborIterAddress(), Pos(), Right(), Side(), SideExtensions(), Size(), and Up().
SgBoardConst::BoardConstImplArray SgBoardConst::s_const [static, private] |
Definition at line 153 of file SgBoardConst.h.
Referenced by Create().