tartan 1.2.2.1
Chess API
Loading...
Searching...
No Matches
tt::Piece::Position Class Reference

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
 
 Position (char l, int d)
 Create Position object with coordinates ld (eq. b3)
 
 Position (const std::string &str)
 Creates Position object at str position.
 
 Position (const char *str)
 Creates Position object at str position.
 
 Position (const Position &)
 Copy constructor.
 
Positionoperator= (const Position &)
 Copy assignment operator.
 
int x () const
 x coordinate
 
int y () const
 y coordinate
 
char letter () const
 Letter representation of x coordinate.
 
int digit () const
 Digit representation of y coordinate.
 
int setX (int x)
 Set x coordinate.
 
int setY (int y)
 Set y coordinate.
 
char setLetter (char x)
 Set x coordinate with string representation.
 
int setDigit (short y)
 Set y coordinate.
 
std::string str () const
 String position representation.
 
Position operator+ (const Position &) const
 Addition operator.
 
Position operator- (const Position &) const
 Substraction operator.
 
Position operator+= (const Position &)
 cosnt
 
Position operator-= (const Position &)
 cosnt
 
Position operator() (int dx, int dy) const
 Offset current position.
 
Position operator() (char dc, int dd) const
 Offset current position.
 
Position manipulation

Set of functions that provide boolean operations on the Position object conditionally depending on it's mode() value.

Position offset (int dx, int dy) const
 Offset current position.
 
Position offset (char dc, int dd) const
 Offset current position.
 
bool atLeft () const
 Check if the position are at left border.
 
bool atRight () const
 Check if the position are at right border.
 
bool atTop () const
 Check if the position are at top border.
 
bool atBottom () const
 Check if the position are at bottom border.
 
Mode mode () const
 Current mode.
 
Mode setMode (Mode m)
 Set offset mode.
 

Friends

bool operator== (const Position &, const Position &)
 Comparison operator.
 
std::ostreamoperator<< (std::ostream &, const Position &)
 std::ostream output operator
 

Detailed Description

Piece position at the Board.

Member Enumeration Documentation

◆ Mode

enum class tt::Piece::Position::Mode
strong

Boolean functions operation mode.

Describes location of the coordinates origin.

See also
atTop(), atLeft(), atRight(), atBottom(), offset(), setMode(), mode()
Enumerator
Normal 

Place origin at the a1.

Reverse 

Place origin at the h8.

Constructor & Destructor Documentation

◆ Position() [1/5]

tt::Position::Position ( int  x,
int  y 
)

Create Position object with coordinates x y

Parameters
xx coordinate
yy coordinate

◆ Position() [2/5]

tt::Position::Position ( char  l,
int  d 
)

Create Position object with coordinates ld (eq. b3)

Parameters
lletter x coordinate
ddigit y coordinate

◆ Position() [3/5]

tt::Position::Position ( const std::string str)

Creates Position object at str position.

The str arguments has the form of

<x><y>
int x() const
x coordinate
Definition board.hpp:123
int y() const
y coordinate
Definition board.hpp:128

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
Parameters
str2-character letter-digit string representation of position

◆ Position() [4/5]

tt::Piece::Position::Position ( const char *  str)
inline

Creates Position object at str position.

The str arguments has the form of

<x><y>

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
Parameters
str2-character letter-digit string representation of position

◆ Position() [5/5]

tt::Position::Position ( const Position other)

Copy constructor.

Note
Copying does not copy the current Position::mode.

Member Function Documentation

◆ atBottom()

bool tt::Position::atBottom ( ) const

Check if the position are at bottom border.

Note
This function behaivor is influenced by current mode() value.
Returns
true if position is at left border false otherwise
See also
setMode().
Returns
true if position is at bottom border, false otherwise
See also
mode().

◆ atLeft()

bool tt::Position::atLeft ( ) const

Check if the position are at left border.

Note
This function behaivor is influenced by current mode() value.
Returns
true if position is at left border false otherwise
See also
setMode().

◆ atRight()

bool tt::Position::atRight ( ) const

Check if the position are at right border.

Note
This function behaivor is influenced by current mode() value.
Returns
true if position is at left border false otherwise
See also
setMode().
Returns
true if position is at right border false otherwise
See also
mode().

◆ atTop()

bool tt::Position::atTop ( ) const

Check if the position are at top border.

Note
This function behaivor is influenced by current mode() value.
Returns
true if position is at left border false otherwise
See also
setMode().
Returns
true if position is at top border false otherwise
See also
mode().

◆ digit()

int tt::Piece::Position::digit ( ) const
inline

Digit representation of y coordinate.

Returns
y coordinate in digit representation
See also
y()

◆ letter()

char tt::Piece::Position::letter ( ) const
inline

Letter representation of x coordinate.

Returns
x coordinate in letter representation
See also
x()

◆ mode()

Mode tt::Piece::Position::mode ( ) const
inline

Current mode.

Returns
current mode
See also
setMode(), Mode

◆ offset() [1/2]

Position tt::Position::offset ( char  dc,
int  dd 
) const

Offset current position.

Works as offset(int dx, int dy) but with character-digit representation

Parameters
dcx coordinate incrementation represented as string
ddy coordinate incrementation
Returns
new Position object at (x±dx, y±dy).
Exceptions
std::out_of_range
See also
offsetMode().

◆ offset() [2/2]

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().

Parameters
dxx coordinate incrementation
dyy coordinate incrementation
Returns
new Position object at (x±dx, y±dy).
Exceptions
std::out_of_range
See also
mode().

◆ operator()() [1/2]

Position tt::Position::operator() ( char  dc,
int  dd 
) const

Offset current position.

Works as offset(int dx, int dy) but with character-digit representation

Parameters
dcx coordinate incrementation represented as string
ddy coordinate incrementation
Returns
new Position object at (x±dx, y±dy).
Exceptions
std::out_of_range
See also
offsetMode().

◆ operator()() [2/2]

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().

Parameters
dxx coordinate incrementation
dyy coordinate incrementation
Returns
new Position object at (x±dx, y±dy).
Exceptions
std::out_of_range
See also
mode().

◆ operator+()

Position tt::Position::operator+ ( const Position p) const

Addition operator.

Returns
new object with sum of corresponding coordinates of argument objects

◆ operator+=()

Position tt::Position::operator+= ( const Position p)

cosnt

cosnt

◆ operator-()

Position tt::Position::operator- ( const Position p) const

Substraction operator.

Returns
new object with difference of corresponding coordinates of argument objects

◆ operator-=()

Position tt::Position::operator-= ( const Position p)

cosnt

cosnt

◆ operator=()

Position & tt::Position::operator= ( const Position other)

Copy assignment operator.

Note
Copying does not copy the current Position::mode.
Returns
a new object with same coordinates.

◆ setDigit()

int tt::Piece::Position::setDigit ( short  y)
inline

Set y coordinate.

Parameters
ynew value
Returns
old value
Exceptions
std::out_of_rangeif `y` is < 1 or > 8
std::out_of_range
See also
setY(int)

◆ setLetter()

char tt::Piece::Position::setLetter ( char  x)
inline

Set x coordinate with string representation.

Parameters
xx coordinate represented as string
Returns
old value

◆ setMode()

Position::Mode tt::Position::setMode ( Position::Mode  m)

Set offset mode.

Note
Depending on the mode() value, functions from Position manipulation group behave differently.
Parameters
mnew offset mode value
Returns
old offset mode value

◆ setX()

int tt::Position::setX ( int  x)

Set x coordinate.

Parameters
xnew value
Returns
old value
Exceptions
std::out_of_rangeif `x` is < 1 or > 8

◆ setY()

int tt::Position::setY ( int  y)

Set y coordinate.

Parameters
ynew value
Returns
old value
Exceptions
std::out_of_rangeif `y` is < 1 or > 8

◆ str()

std::string tt::Position::str ( ) const

String position representation.

Returns
string representation of current position

◆ x()

int tt::Piece::Position::x ( ) const
inline

x coordinate

Returns
x coordinate

◆ y()

int tt::Piece::Position::y ( ) const
inline

y coordinate

Returns
y coordinate

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream os,
const Position p 
)
friend

std::ostream output operator

Puts string representation of position to std::ostream.

Returns
called std::ostream object
See also
str()

◆ operator==

bool operator== ( const Position lhs,
const Position rhs 
)
friend

Comparison operator.

Returns
true if corresponding coordinates of both objects are equal

The documentation for this class was generated from the following files: