Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  
Classes | Namespaces | Defines | Typedefs | Functions | Variables

SgPoint.h File Reference

Definitions of points on the board. More...

#include <climits>
#include <cstdlib>
#include <iosfwd>
#include <string>
#include <boost/static_assert.hpp>
#include "SgArray.h"
#include "SgMove.h"
#include "SgUtil.h"

Go to the source code of this file.

Classes

struct  SgWritePoint
 Write point. More...
class  SgReadPoint
 Read point. More...
class  SgPointUtil::PointToRow
 Lookup table internally used by SgPointUtil::Row(). More...
class  SgPointUtil::PointToCol
 Lookup table internally used by SgPointUtil::Col(). More...

Namespaces

namespace  SgPointUtil

Defines

#define SG_ASSERT_GRIDRANGE(c)   SG_ASSERTRANGE(c, 1, SG_MAX_SIZE)
#define SG_ASSERT_BOARDRANGE(p)

Typedefs

typedef int SgPoint
 Point or SG_PASS.
typedef int SgGrid
 Coordinate in range 0 to SG_MAX_SIZE.

Functions

bool SgIsSpecialMove (SgMove m)
 Test if move is not a point.
std::ostream & operator<< (std::ostream &out, const SgWritePoint &writePoint)
std::istream & operator>> (std::istream &in, const SgReadPoint &readPoint)
char SgPointUtil::Letter (int coord)
std::string SgPointUtil::PointToString (SgPoint p)
SgPoint SgPointUtil::Pt (int col, int row)
 Converts from (col, row) to a one-dimensional point.
SgGrid SgPointUtil::Col (SgPoint p)
 Return column of point.
SgGrid SgPointUtil::Row (SgPoint p)
 Return row of point.
bool SgPointUtil::InBoardRange (SgPoint p)
bool SgPointUtil::AreAdjacent (SgPoint p1, SgPoint p2)
 True if the two points are adjacent to each other.
bool SgPointUtil::AreDiagonal (SgPoint p1, SgPoint p2)
 True if the two points are diagonally adjacent to each other.
int SgPointUtil::Distance (SgPoint p1, SgPoint p2)
 Manhattan distance between two points on the board.
bool SgPointUtil::In8Neighborhood (SgPoint p1, SgPoint p2)
 p2 is in 3x3 area around p1.
SgPoint SgPointUtil::Rotate (int rotation, SgPoint p, int size)
 Rotate/mirror point.
int SgPointUtil::InvRotation (int rotation)
 Return the inverse rotation as used in SgPointUtil::Rotate.

Variables

const int SG_MIN_SIZE = 2
 Minimum board size.
const int SG_MAX_SIZE = 19
 Maximum board size.
const SgPoint SG_ENDPOINT = 0
 Marker used for marking the end of points lists stored in arrays.
const int SG_MINPOINT = 0
 For symmetry, and for use in loops etc.
const int SG_MAXPOINT = SG_MAX_SIZE * SG_MAX_SIZE + 3 * (SG_MAX_SIZE + 1)
 Board plus borders.
const int SG_MAX_ONBOARD = SG_MAX_SIZE * SG_MAX_SIZE
 Maximum number of points on board.
const int SG_MAX_MOVES = SG_MAX_ONBOARD + 1
 The maximum number of moves.
const int SG_WE = 1
 West-East : offset of horizontal neighbors.
const int SG_NS = SG_MAX_SIZE + 1
 North-South: offset of vertical neighbors.
const SgPoint SG_NULLPOINT = SG_NULLMOVE
 Special parameter of type Point.
const SgMove SG_PASS = SG_MAXPOINT + 1

Detailed Description

Definitions of points on the board.

Points are defined in a way that they can be used as indices in an array, for a one-dimensional representation of a two-dimensional board with border (off-board) points between rows and columns. They are also compatible with SgMove (i.e. they use no negative integers, there is no overlap with the negative values for special moves in SgMove), so they can be used as move integers for games where a move can be described by a single point on the board.

See also:
sgboardrepresentation

Definition in file SgPoint.h.


Define Documentation

#define SG_ASSERT_BOARDRANGE (   p  ) 
#define SG_ASSERT_GRIDRANGE (   c  )     SG_ASSERTRANGE(c, 1, SG_MAX_SIZE)

Typedef Documentation

typedef int SgGrid

Coordinate in range 0 to SG_MAX_SIZE.

Definition at line 146 of file SgPoint.h.

typedef int SgPoint

Point or SG_PASS.

Definition at line 101 of file SgPoint.h.


Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const SgWritePoint writePoint 
)

Definition at line 146 of file SgPoint.cpp.

References SgWritePoint::m_p, and SgPointUtil::PointToString().

std::istream & operator>> ( std::istream &  in,
const SgReadPoint readPoint 
)

Definition at line 203 of file SgPoint.h.

References SgReadPoint::Read().

bool SgIsSpecialMove ( SgMove  m  ) 

Test if move is not a point.

Returns true for special moves with negative values as defined in SgMove.h (e.g. SG_NULLMOVE) and for SG_PASS.

Definition at line 140 of file SgPoint.h.

References SG_PASS.

Referenced by SgPropPointList::ToString().


Variable Documentation

const SgPoint SG_ENDPOINT = 0

Marker used for marking the end of points lists stored in arrays.

Definition at line 104 of file SgPoint.h.

Referenced by SgBoardConst::BoardConstImpl::BoardConstImpl(), and SgPointIterator::operator bool().

const int SG_MAX_MOVES = SG_MAX_ONBOARD + 1

The maximum number of moves.

Limit using the largest possible board size and pass move.

Definition at line 117 of file SgPoint.h.

Maximum number of points on board.

Definition at line 113 of file SgPoint.h.

const int SG_MAX_SIZE = 19

Maximum board size.

The default value is 19, but the code can be compiled using the predefined macro SG_DEFINE_MAX_SIZE to specify a different value for better space efficiency (and speed) if only small boards are used or to support larger boards. Currently, only maximum sizes up to 25 are supported, because of limitations of the string representation of points. Note that if SG_DEFINE_MAX_SIZE is used, external projects using the SmartGame library must also compiled with the same definition for SG_DEFINE_MAX_SIZE, otherwise run-time crashes will occur because of a disagreement on array sizes.

Definition at line 92 of file SgPoint.h.

Referenced by SgBoardConst::BoardConstImpl::BoardConstImpl(), SgPointSet::Center(), SgPointSet::CheckedContains(), SgPointSet::PrecompAllPoints::Get(), SgGameReader::HandleProperties(), SgGameWriter::HandleProps(), SgPointUtil::InBoardRange(), SgPointUtil::PointToCol::PointToCol(), SgPointUtil::PointToRow::PointToRow(), SgPropUtil::PointToSgfString(), SgNb4Iterator::Precomp::Precomp(), SgPointSet::PrecompAllPoints::PrecompAllPoints(), SgReadPoint::Read(), SgConnComp8Iterator::SgConnComp8Iterator(), SgConnCompIterator::SgConnCompIterator(), and SgPropUtil::SgfStringToPoint().

const int SG_MAXPOINT = SG_MAX_SIZE * SG_MAX_SIZE + 3 * (SG_MAX_SIZE + 1)
const int SG_MIN_SIZE = 2
const int SG_MINPOINT = 0

For symmetry, and for use in loops etc.

Definition at line 107 of file SgPoint.h.

const int SG_NS = SG_MAX_SIZE + 1
const SgMove SG_PASS = SG_MAXPOINT + 1
const int SG_WE = 1


Sun Mar 13 2011 Doxygen 1.7.1