Conquer Chess
Chess and Starcraft combined
Loading...
Searching...
No Matches
Classes | Functions
piece.h File Reference
#include "action_history.h"
#include "delta_t.h"
#include "chess_color.h"
#include "piece_type.h"
#include "piece_action.h"
#include "piece_id.h"
#include "message_type.h"
#include "race.h"
#include "read_only.h"
#include <iosfwd>
#include <string>
#include <vector>
Include dependency graph for piece.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  piece
 A chess piece. More...
 

Functions

bool can_attack_on_empty_board (const chess_color color, const piece_type &p, const square &from, const square &to)
 Can a piece attack from 'from' to 'to'? This function assumes the board is empty.
 
bool can_capture (const piece_type &p, const square &from, const square &to, const chess_color color)
 Can a piece capture from 'from' to 'to'? This function assumes the board is empty.
 
bool can_move_on_empty_board (const chess_color color, const piece_type &p, const square &from, const square &to)
 Can a piece move from 'from' to 'to'? This function assumes the board is empty.
 
bool can_promote (const chess_color color, const piece_type &p, const square &s) noexcept
 Can this piece promote?
 
bool can_promote (const piece &p) noexcept
 Can this piece promote?
 
void clear_actions (piece &p)
 Clear all the actions.
 
int count_piece_actions (const piece &p)
 Count the number of actions a piece has.
 
std::string describe_actions (const piece &p)
 Describe the actions a piece have, e.g. 'idle', or 'moving to (3, 4)'.
 
double get_f_health (const piece &p) noexcept
 Get the fraction of the health, where 1.0 denotes full health.
 
double get_f_shield (const piece &p) noexcept
 Get the fraction of the shield, where 1.0 denotes full shields.
 
square get_occupied_square (const piece &p) noexcept
 Get the square that this piece occupies now.
 
piece get_test_white_king () noexcept
 Create a piece to be used in testing: a white king on e1.
 
piece get_test_white_knight (const race r=race::classic) noexcept
 Create a piece to be used in testing: a white knight on c3.
 
bool has_actions (const piece &p) noexcept
 Does the piece have actions to do?
 
bool has_just_double_moved (const piece &p, const in_game_time &when) noexcept
 Has this piece (i.e.
 
bool has_moved (const piece &p) noexcept
 Has this piece (attempted to) move?
 
bool is_dead (const piece &p) noexcept
 Is the unit dead?
 
bool is_enpassantable (const piece &p, const in_game_time &when)
 Can the unit be captured by en-passant?
 
bool is_idle (const piece &p) noexcept
 Is the unit idle?
 
bool is_on_starting_rank (const chess_color c, const square &q) noexcept
 Is this piece (a pawn) on the starting rank?
 
bool is_pawn (const piece &p) noexcept
 Is the piece a pawn?
 
bool is_selected (const piece &p)
 Determine from the action history if the piece is selected.
 
void test_piece ()
 Test this class and its free functions.
 
void tick_attack (piece &p, const delta_t &dt, game &g)
 Process a tick, when the current action is an attack.
 
void tick_attack_en_passant (piece &p, const delta_t &dt, game &g)
 
void tick_castle_kingside (piece &p, const delta_t &dt, game &g)
 Process a tick, when the current action is a castling to kingside.
 
void tick_castle_queenside (piece &p, const delta_t &dt, game &g)
 Process a tick, when the current action is a castling to queenside.
 
void tick_move (piece &p, const delta_t &dt, game &g)
 Process a tick, when the current action is a move.
 
char to_fen_char (const piece &p) noexcept
 Convert the piece to a FEN character.
 
bool operator== (const piece &lhs, const piece &rhs) noexcept
 
bool operator!= (const piece &lhs, const piece &rhs) noexcept
 
std::ostream & operator<< (std::ostream &os, const piece &p) noexcept
 

Function Documentation

◆ can_attack_on_empty_board()

bool can_attack_on_empty_board ( const chess_color  color,
const piece_type p,
const square from,
const square to 
)

Can a piece attack from 'from' to 'to'? This function assumes the board is empty.

◆ can_capture()

bool can_capture ( const piece_type p,
const square from,
const square to,
const chess_color  color 
)

Can a piece capture from 'from' to 'to'? This function assumes the board is empty.

◆ can_move_on_empty_board()

bool can_move_on_empty_board ( const chess_color  color,
const piece_type p,
const square from,
const square to 
)

Can a piece move from 'from' to 'to'? This function assumes the board is empty.

◆ can_promote() [1/2]

bool can_promote ( const chess_color  color,
const piece_type p,
const square s 
)
noexcept

Can this piece promote?

◆ can_promote() [2/2]

bool can_promote ( const piece p)
noexcept

Can this piece promote?

◆ clear_actions()

void clear_actions ( piece p)

Clear all the actions.

◆ count_piece_actions()

int count_piece_actions ( const piece p)

Count the number of actions a piece has.

◆ describe_actions()

std::string describe_actions ( const piece p)

Describe the actions a piece have, e.g. 'idle', or 'moving to (3, 4)'.

◆ get_f_health()

double get_f_health ( const piece p)
noexcept

Get the fraction of the health, where 1.0 denotes full health.

◆ get_f_shield()

double get_f_shield ( const piece p)
noexcept

Get the fraction of the shield, where 1.0 denotes full shields.

Assumes the piece is a Rooxx

◆ get_occupied_square()

square get_occupied_square ( const piece p)
noexcept

Get the square that this piece occupies now.

◆ get_test_white_king()

piece get_test_white_king ( )
noexcept

Create a piece to be used in testing: a white king on e1.

◆ get_test_white_knight()

piece get_test_white_knight ( const race  r = race::classic)
noexcept

Create a piece to be used in testing: a white knight on c3.

◆ has_actions()

bool has_actions ( const piece p)
noexcept

Does the piece have actions to do?

◆ has_just_double_moved()

bool has_just_double_moved ( const piece p,
const in_game_time when 
)
noexcept

Has this piece (i.e.

a pawn) did a double move forward last time unit? Only pawns can do this, e.g. e2-e4 or e7-e5

◆ has_moved()

bool has_moved ( const piece p)
noexcept

Has this piece (attempted to) move?

◆ is_dead()

bool is_dead ( const piece p)
noexcept

Is the unit dead?

◆ is_enpassantable()

bool is_enpassantable ( const piece p,
const in_game_time when 
)

Can the unit be captured by en-passant?

◆ is_idle()

bool is_idle ( const piece p)
noexcept

Is the unit idle?

◆ is_on_starting_rank()

bool is_on_starting_rank ( const chess_color  c,
const square q 
)
noexcept

Is this piece (a pawn) on the starting rank?

◆ is_pawn()

bool is_pawn ( const piece p)
noexcept

Is the piece a pawn?

◆ is_selected()

bool is_selected ( const piece p)

Determine from the action history if the piece is selected.

◆ operator!=()

bool operator!= ( const piece lhs,
const piece rhs 
)
noexcept

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
const piece p 
)
noexcept

◆ operator==()

bool operator== ( const piece lhs,
const piece rhs 
)
noexcept

◆ test_piece()

void test_piece ( )

Test this class and its free functions.

◆ tick_attack()

void tick_attack ( piece p,
const delta_t dt,
game g 
)

Process a tick, when the current action is an attack.

◆ tick_attack_en_passant()

void tick_attack_en_passant ( piece p,
const delta_t dt,
game g 
)

◆ tick_castle_kingside()

void tick_castle_kingside ( piece p,
const delta_t dt,
game g 
)

Process a tick, when the current action is a castling to kingside.

◆ tick_castle_queenside()

void tick_castle_queenside ( piece p,
const delta_t dt,
game g 
)

Process a tick, when the current action is a castling to queenside.

◆ tick_move()

void tick_move ( piece p,
const delta_t dt,
game g 
)

Process a tick, when the current action is a move.

◆ to_fen_char()

char to_fen_char ( const piece p)
noexcept

Convert the piece to a FEN character.

Type Character when white Character when black
bishop b B
king k K
knight n N
pawn p P
queen q Q
rook r R