tartan
1.2.1.0
|
Piece position at the Board. More...
#include <board.hpp>
Public Types | |
enum class | Mode { Normal = 1 , Reverse = -1 } |
Boolean functions operation mode. More... | |
Public Member Functions | |
Position ()=default | |
Create Position object at a1. | |
Position (int x, int y) | |
Create Position object with coordinates x y More... | |
Position (char l, int d) | |
Create Position object with coordinates ld (eq. b3 ) More... | |
Position (const std::string &str) | |
Creates Position object at str position. More... | |
Position (const char *str) | |
Creates Position object at str position. More... | |
Position (const Position &) | |
Copy constructor. More... | |
Position & | operator= (const Position &) |
Copy assignment operator. More... | |
int | x () const |
x coordinate More... | |
int | y () const |
y coordinate More... | |
char | letter () const |
Letter representation of x coordinate. More... | |
int | digit () const |
Digit representation of y coordinate. More... | |
int | setX (int x) |
Set x coordinate. More... | |
int | setY (int y) |
Set y coordinate. More... | |
char | setLetter (char x) |
Set x coordinate with string representation. More... | |
int | setDigit (short y) |
Set y coordinate. More... | |
std::string | str () const |
String position representation. More... | |
Position | operator+ (const Position &) const |
Addition operator. More... | |
Position | operator- (const Position &) const |
Substraction operator. More... | |
Position | operator+= (const Position &) |
cosnt More... | |
Position | operator-= (const Position &) |
cosnt More... | |
Position | operator() (int dx, int dy) const |
Offset current position. More... | |
Position | operator() (char dc, int dd) const |
Offset current position. More... | |
Position manipulation | |
Position | offset (int dx, int dy) const |
Offset current position. More... | |
Position | offset (char dc, int dd) const |
Offset current position. More... | |
bool | atLeft () const |
Check if the position are at left border. More... | |
bool | atRight () const |
Check if the position are at right border. More... | |
bool | atTop () const |
Check if the position are at top border. More... | |
bool | atBottom () const |
Check if the position are at bottom border. More... | |
Mode | mode () const |
Current mode. More... | |
Mode | setMode (Mode m) |
Set offset mode. More... | |
Friends | |
bool | operator== (const Position &, const Position &) |
Comparison operator. More... | |
std::ostream & | operator<< (std::ostream &, const Position &) |
std::ostream output operator More... | |
|
strong |
tt::Position::Position | ( | int | x, |
int | y | ||
) |
Create Position object with coordinates x
y
x | x coordinate |
y | y coordinate |
tt::Position::Position | ( | char | l, |
int | d | ||
) |
Create Position object with coordinates ld
(eq. b3
)
l | letter x coordinate |
d | digit y coordinate |
tt::Position::Position | ( | const std::string & | str | ) |
Creates Position object at str
position.
The str
arguments has the form of
where the <x>
is the lowercase letter in range a-h inclusive, <y>
is a number from range [1;8].
Table for <x>
letter-to-digit mapping
Letter | Digit |
---|---|
a | 1 |
b | 2 |
c | 3 |
d | 4 |
e | 5 |
f | 6 |
g | 7 |
h | 8 |
Example arguments:
Argument | x() | y() |
---|---|---|
"d4" | 4 | 4 |
"e7" | 5 | 7 |
"h3" | 8 | 3 |
str | 2-character letter-digit string representation of position |
|
inline |
Creates Position object at str
position.
The str
arguments has the form of
where the <x>
is the lowercase letter in range a-h inclusive, <y>
is a number from range [1;8].
Table for <x>
letter-to-digit mapping
Letter | Digit |
---|---|
a | 1 |
b | 2 |
c | 3 |
d | 4 |
e | 5 |
f | 6 |
g | 7 |
h | 8 |
Example arguments:
Argument | x() | y() |
---|---|---|
"d4" | 4 | 4 |
"e7" | 5 | 7 |
"h3" | 8 | 3 |
str | 2-character letter-digit string representation of position |
tt::Position::Position | ( | const Position & | other | ) |
Copy constructor.
bool tt::Position::atBottom | ( | ) | const |
bool tt::Position::atLeft | ( | ) | const |
bool tt::Position::atRight | ( | ) | const |
bool tt::Position::atTop | ( | ) | const |
|
inline |
|
inline |
|
inline |
Position tt::Position::offset | ( | char | dc, |
int | dd | ||
) | const |
Offset current position.
Works as offset(int dx, int dy) but with character-digit representation
dc | x coordinate incrementation represented as string |
dd | y coordinate incrementation |
std::out_of_range |
Position tt::Position::offset | ( | int | dx, |
int | dy | ||
) | const |
Offset current position.
Returns new position at (x±dx, y±dy). Operation sign depends on current mode().
dx | x coordinate incrementation |
dy | y coordinate incrementation |
std::out_of_range |
Position tt::Position::operator() | ( | char | dc, |
int | dd | ||
) | const |
Offset current position.
Works as offset(int dx, int dy) but with character-digit representation
dc | x coordinate incrementation represented as string |
dd | y coordinate incrementation |
std::out_of_range |
Position tt::Position::operator() | ( | int | dx, |
int | dy | ||
) | const |
Offset current position.
Returns new position at (x±dx, y±dy). Operation sign depends on current mode().
dx | x coordinate incrementation |
dy | y coordinate incrementation |
std::out_of_range |
Addition operator.
Substraction operator.
Copy assignment operator.
|
inline |
Set y coordinate.
y | new value |
std::out_of_range | if y is < 1 or > 8 |
std::out_of_range |
|
inline |
Set x coordinate with string representation.
x | x coordinate represented as string |
Position::Mode tt::Position::setMode | ( | Position::Mode | m | ) |
Set offset mode.
m | new offset mode value |
int tt::Position::setX | ( | int | x | ) |
Set x coordinate.
x | new value |
std::out_of_range | if x is < 1 or > 8 |
int tt::Position::setY | ( | int | y | ) |
Set y coordinate.
y | new value |
std::out_of_range | if y is < 1 or > 8 |
std::string tt::Position::str | ( | ) | const |
String position representation.
|
inline |
x coordinate
|
inline |
y coordinate
|
friend |
std::ostream output operator
Puts string representation of position to std::ostream.
Comparison operator.
true
if corresponding coordinates of both objects are equal