Knight-Path 1.0.D018
|
#include <position.h>
Public Types | |
typedef std::vector< position > | list_t |
Public Member Functions | |
~position () | |
The destructor. | |
position () | |
The default constructor. | |
position (char rank, char file) | |
The default constructor. | |
position (const position &rhs) | |
position & | operator= (const position &rhs) |
list_t | knight_moves (void) const |
void | write (std::ostream &os) const |
bool | operator== (const position &rhs) const |
bool | operator!= (const position &rhs) const |
void | plot (char board[8][8], char c) const |
int | distance (const position &elsewhere) const |
int | get_x (void) const |
int | get_y (void) const |
Static Public Member Functions | |
static position | read (std::istream &is) |
Private Member Functions | |
position (int x, int y) | |
bool | valid (void) const |
char | get_rank (void) const |
char | get_file (void) const |
Private Attributes | |
unsigned | p |
The position class is used to represent a position on a chess board. The board is assumed to be a standard 8x8 board.
Input and output using algebraic notation is available. See http://en.wikipedia.org/wiki/Algebraic_notation_%28chess%29 for more information.
Rows (called "ranks") are numbered 1..8, when viewed from white's side of the board, with 1 closest (at the bottom) and 8 farthest (at the top).
Columns (called "files") are numbered 'a' to 'h', when viewed from white's side of the board with 'a' on the left and 'h' on the right.
Definition at line 40 of file position.h.
typedef std::vector<position> position::list_t |
Definition at line 43 of file position.h.
position::~position | ( | ) |
The destructor.
It is not virtual, thou shalt not derive from this class.
Definition at line 25 of file position.cc.
position::position | ( | ) |
The default constructor.
The position is undefined, and will result in a run-time assert failure if used without being initialised.
Definition at line 30 of file position.cc.
position::position | ( | char | rank, |
char | file | ||
) |
The default constructor.
The position is undefined, and will result in a run-time assert failure if used without being initialised.
rank | The Y coordinate, as a char between '1' and '8'. |
file | The X coordinate, as a char between 'a' and 'h' (or, to be generous, from 'A' to 'H'). |
Definition at line 45 of file position.cc.
position::position | ( | const position & | rhs | ) |
The copy constructor.
rhs | The right hand side of the initialization. |
Definition at line 67 of file position.cc.
position::position | ( | int | x, |
int | y | ||
) | [private] |
A constructor. This is not part of the public interface.
x | The X coordinate of the position (0..7) |
y | The Y coordinate of the position (0..7) |
Definition at line 56 of file position.cc.
int position::distance | ( | const position & | elsewhere | ) | const |
The distance method may be used to calculate the taxi-cab distance (see http://en.wikipedia.org/wiki/Taxicab_geometry) between this point and the given point.
elsewhere | The other position of interest. |
Definition at line 247 of file position.cc.
char position::get_file | ( | void | ) | const [private] |
The get_file method is used to obtain the column number. Each column (called a "file" in chess jargon) are numbered 'a' to 'h', when viewed from white's side of the board with 'a' on the left and 'h' on the right.
Definition at line 108 of file position.cc.
char position::get_rank | ( | void | ) | const [private] |
The get_rank method is used to obtain the row number. Each row (called a "rank" in chess jargon) are numbered 1..8, when viewed from white's side of the board, with 1 closest (at the bottom) and 8 farthest (at the top).
Definition at line 91 of file position.cc.
int position::get_x | ( | void | ) | const |
The get_x method is used to obtain the X coordinate of the position.
Definition at line 116 of file position.cc.
int position::get_y | ( | void | ) | const |
The get_y method is used to obtain the Y coordinate of the position.
Definition at line 99 of file position.cc.
position::list_t position::knight_moves | ( | void | ) | const |
The knight_moves method is used to generate a list of legal knight moves from this position. It is assumed there are no other pieces on the board.
Definition at line 200 of file position.cc.
bool position::operator!= | ( | const position & | rhs | ) | const |
The inequality operator is used to test two position for inequality.
rhs | The right hand side of the comparison. |
Definition at line 190 of file position.cc.
The assignment operator.
rhs | The right hand side of the assignment. |
Definition at line 74 of file position.cc.
bool position::operator== | ( | const position & | rhs | ) | const |
The equality operator is used to test two position for equality.
rhs | The right hand side of the comparison. |
Definition at line 180 of file position.cc.
void position::plot | ( | char | board[8][8], |
char | c | ||
) | const |
The plot method is used to draw the given character into the given board at this position.
board | The board to be drawn on. The first domension is y|rank, the second dimension is x|file. |
c | The character to be drawn on the board. |
Definition at line 239 of file position.cc.
position position::read | ( | std::istream & | is | ) | [static] |
The read class method is used to read a position, in text form, from an input stream. Both upper and lower case are accepted for the file/column portion.
is | The text input stream to be read. |
Definition at line 133 of file position.cc.
bool position::valid | ( | void | ) | const [private] |
The valid method is used to ensure that the position is valid before any processing takes place.
Definition at line 83 of file position.cc.
void position::write | ( | std::ostream & | os | ) | const |
The write method is used to write a text representation of a chess board position.
os | The output stream to write the position onto. |
Definition at line 171 of file position.cc.
unsigned position::p [private] |
The p instance variable is used to remember the rank and file of the position, in a single variable.
Definition at line 194 of file position.h.