tartan  1.2.1.0
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 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...
 
Positionoperator= (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

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. 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::ostreamoperator<< (std::ostream &, const Position &)
 std::ostream output operator More...
 

Detailed Description

Piece position at the Board.

Member Enumeration Documentation

◆ Mode

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:124
int y() const
y coordinate
Definition: board.hpp:129

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 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 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 Function 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: