13 bool game_end =
false;
14 bool correct_move =
false;
17 bool white_move =
true;
19 board *chess_board_copy;
30 std::cout <<
" turn. ";
36 std::cout <<
" turn. ";
39 if(chess_board.
is_check(white_move)){
40 std::cout << std::endl;
42 std::cout <<
"Warning : Check state" << std::endl;
45 std::cout <<
"What move ? " << std::endl;
47 if(movement ==
"/quit" || movement ==
"/resign" || movement ==
"/draw"){
51 if(movement ==
"/quit"){
54 if(movement ==
"/resign"){
61 if(movement ==
"/draw"){
71 if(chess_board.
is_legal(start,end,white_move)){
73 chess_board_copy =
new board(chess_board);
74 chess_board_copy->
move(start,end);
75 if(chess_board_copy->
is_check(white_move)){
77 std::cout <<
"Illegal move. Your king will be checked" << std::endl;
79 chess_board.
move(start,end);
84 std::cout <<
"Promotion. Choose a piece to substitue the pawn : B/N/R/Q" << std::endl;
85 std::string chose_promotion =
"";
86 while((chose_promotion !=
"B") && (chose_promotion !=
"N")
87 && (chose_promotion !=
"R") && (chose_promotion !=
"Q")){
88 std::cin >> chose_promotion;
89 if((chose_promotion !=
"B") && (chose_promotion !=
"N")
90 && (chose_promotion !=
"R") && (chose_promotion !=
"Q")){
91 std::cout <<
"Wrong input format. Input to be among : B,N,R and Q" << std::endl;
95 if(chose_promotion ==
"B"){
98 if(chose_promotion ==
"N"){
101 if(chose_promotion ==
"R"){
104 if(chose_promotion ==
"Q"){
109 delete chess_board_copy;
111 std::cout <<
"Illegal move." << std::endl;
118 chess_board_copy =
new board(chess_board);
120 if(chess_board_copy->
is_check(white_move)){
122 std::cout <<
"Illegal move. Your king will be checked" << std::endl;
127 delete chess_board_copy;
129 std::cout <<
"Illegal move." << std::endl;
136 chess_board_copy =
new board(chess_board);
138 if(chess_board_copy->
is_check(white_move)){
140 std::cout <<
"Illegal move. Your king will be checked" << std::endl;
145 delete chess_board_copy;
147 std::cout <<
"Illegal move." << std::endl;
152 std::cout <<
"Wrong input format. Format need to be in algrebic notation : b1c3 for example. 0-0-0 and 0-0 for the castlings" << std::endl;
161 if(chess_board.
is_check(!white_move)){
165 std::cout <<
"White win.";
169 std::cout <<
"Draw.";
173 if(chess_board.
is_check(!white_move)){
177 std::cout <<
"Black win.";
181 std::cout <<
"Draw.";
186 white_move = !white_move;
192 std::cout <<
" 1-0" << std::endl;
196 std::cout <<
" 0-1" << std::endl;
200 std::cout <<
" 1/2-1/2" << std::endl;
204 std::cout <<
" ?-?" << std::endl;
void print_neutral_endl()
print a neutral font color and background color new line
coordinates get_coord_from_string(std::string move)
Retrieve coordinates from a string.
A class representing the chess board.
bool is_promotion_needed(coordinates coord)
check if a promotion is needed
void canonical_print()
print the board in canonical form
bool is_check(bool white_king)
check if the selected player is in check state
bool is_king_castling_legal(bool white_move)
check if the king-side castling move is legal, without checking it in regards to king check state
bool is_checkmate_or_pat(bool white_move)
check if the other player can move without being in a check state
bool is_legal(coordinates move_from, coordinates move_to, bool white_move)
Check if a move is legal, without checking it in regards to king check state.
void print()
print the board
bool is_queen_castling_legal(bool white_move)
check if the queen-side castling move is legal, without checking it in regards to king check state
void move(coordinates move_from, coordinates move_to)
Move a piece from one position to another, supposing that the move is legal.
void king_castle(bool white_move)
perform the king-side castling move
void promote(coordinates to_promote, piece_type new_type)
Perform a promotion on the specified coordinates. Don't check anything.
void queen_castle(bool white_move)
perform the queen-side castling move
a class representing coordinates
#define BACKGROUND_COLOR1
#define WARNING_TEXT_COLOR
winner_type
an enumeration to represent the game result
int main()
The main function.
bool king_castle_input(std::string const &cmd)
Check if an input correponds to a king castling move.
void terminal_reset_all()
reset all terminal attributes
bool standard_input(std::string const &cmd)
Check if an input corresponds to a standard move.
bool correct_input(std::string const &cmd)
Check if an input is conform.
void terminal_set_background_color(terminal_color color)
set the terminal background color to the input
bool queen_castle_input(std::string const &cmd)
Check if an input corresponds to a queen castling move.
void terminal_set_text_color(terminal_color color)
set the terminal font color to the input