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.
Definition in file SgPoint.h.
#include <climits>
#include <cstdlib>
#include <iosfwd>
#include <string>
#include "SgArray.h"
#include "SgMove.h"
#include "SgUtil.h"
Go to the source code of this file.
Namespaces | |
namespace | SgPointUtil |
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... | |
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 |
#define SG_ASSERT_BOARDRANGE | ( | p | ) |
Value:
SG_ASSERTRANGE(p, SgPointUtil::Pt(1, 1), \ SgPointUtil::Pt(SG_MAX_SIZE, SG_MAX_SIZE))
Definition at line 138 of file SgPoint.h.
Referenced by SgPointSet::Adjacent8To(), SgPointSet::AdjacentTo(), SgPointSet::CheckedContains(), SgPointUtil::PointToCol::Col(), SgSimpleSet::Exclude(), SgPointSet::Exclude(), SgSimpleSet::Include(), SgPointSet::Include(), SgMarker::Include(), SgSetIterator::operator *(), and SgPointUtil::PointToRow::Row().
#define SG_ASSERT_GRIDRANGE | ( | c | ) | SG_ASSERTRANGE(c, 1, SG_MAX_SIZE) |
Definition at line 136 of file SgPoint.h.
Referenced by SgBoardConst::ChangeSize(), SgBoardConst::Create(), SgPointUtil::Pt(), and SgBoardConst::SgBoardConst().
std::ostream& operator<< | ( | std::ostream & | out, | |
const SgWritePoint & | writePoint | |||
) |
Definition at line 147 of file SgPoint.cpp.
References SgWritePoint::m_p, and SgPointUtil::PointToString().
std::istream & operator>> | ( | std::istream & | in, | |
const SgReadPoint & | readPoint | |||
) |
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 128 of file SgPoint.h.
References SG_PASS.
Referenced by SgPropPointList::ToString().
const SgPoint SG_ENDPOINT = 0 |
Marker used for marking the end of points lists stored in arrays.
Definition at line 89 of file SgPoint.h.
Referenced by SgBoardConst::BoardConstImpl::BoardConstImpl(), and SgPointIterator::operator bool().
const int SG_MAX_MOVES = SG_MAX_ONBOARD + 1 |
const int SG_MAX_ONBOARD = SG_MAX_SIZE * SG_MAX_SIZE |
const int SG_MAX_SIZE = 19 |
Maximum board size.
Definition at line 83 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) |
Board plus borders.
Definition at line 95 of file SgPoint.h.
Referenced by SgBoardConst::BoardConstImpl::BoardConstImpl(), SgSimpleSet::Clear(), SgEvaluatedMovesArray::Clear(), SgPointSet::ConnComp(), SgPointSet::ConnComp8(), SgSimpleSet::GetPoints(), SgMarker::GetPoints(), SgSimpleSet::IsEmpty(), SgEvaluatedMovesArray::SelectNextBest(), and SgEvaluatedMovesArray::SgEvaluatedMovesArray().
const int SG_MIN_SIZE = 2 |
Minimum board size.
Definition at line 80 of file SgPoint.h.
Referenced by SgPointSet::PrecompAllPoints::Get(), SgGameWriter::HandleProps(), SgPropUtil::PointToSgfString(), SgPointSet::PrecompAllPoints::PrecompAllPoints(), and SgPropUtil::SgfStringToPoint().
const int SG_MINPOINT = 0 |
const int SG_NS = SG_MAX_SIZE + 1 |
North-South: offset of vertical neighbors.
Definition at line 109 of file SgPoint.h.
Referenced by SgPointSet::Adjacent8To(), SgPointSet::AdjacentTo(), SgPointUtil::AreAdjacent(), SgPointUtil::AreDiagonal(), SgBoardConst::BoardConstImpl::BoardConstImpl(), SgPointSet::Border8(), SgPointSet::BorderNoClip(), SgPointSet::Grow(), SgPointSet::Grow8(), SgPointUtil::In8Neighborhood(), SgPointSet::Kernel(), SgBoardConst::Left(), SgRectIterator::operator++(), SgNb4Iterator::Precomp::Precomp(), SgPointUtil::Pt(), SgBoardConst::Right(), and SgBoardConst::Side().
const SgPoint SG_NULLPOINT = SG_NULLMOVE |
Special parameter of type Point.
Definition at line 112 of file SgPoint.h.
Referenced by SgPointSet::Center(), SgMiaiMap::ConvertFromSgMiaiStrategy(), SgMiaiMap::ExecuteMove(), SgPointSet::Is8Connected(), SgPointSet::IsConnected(), SgMiaiStrategy::OpenThreatMove(), SgPointSet::PointOf(), and SgMiaiMap::Status().
const SgMove SG_PASS = SG_MAXPOINT + 1 |
Definition at line 122 of file SgPoint.h.
Referenced by SgEvaluatedMoves::BestMove(), SgSearch::CallExecute(), SgPropPointList::FromString(), SgSearch::NullMovePrune(), SgPropUtil::PointToSgfString(), SgPointUtil::PointToString(), SgReadPoint::Read(), SgPointUtil::Rotate(), SgPropUtil::SgfStringToPoint(), and SgIsSpecialMove().
const int SG_WE = 1 |
West-East : offset of horizontal neighbors.
Definition at line 106 of file SgPoint.h.
Referenced by SgPointSet::Adjacent8To(), SgPointSet::AdjacentTo(), SgPointUtil::AreAdjacent(), SgPointUtil::AreDiagonal(), SgBoardConst::BoardConstImpl::BoardConstImpl(), SgPointSet::Border8(), SgPointSet::BorderNoClip(), SgPointSet::Grow(), SgPointSet::Grow8(), SgPointUtil::In8Neighborhood(), SgPointSet::Kernel(), SgBoardConst::Left(), SgRectIterator::operator++(), SgNb4Iterator::Precomp::Precomp(), SgBoardConst::Right(), and SgBoardConst::Side().