The main function.
10 {
12 std::string movement;
13 bool game_end = false;
14 bool correct_move = false;
17 bool white_move = true;
19 board *chess_board_copy;
20 while(!game_end){
22 movement = "";
23 correct_move = false;
24 while(!correct_move){
25 if(white_move){
28 std::cout << "White";
30 std::cout << " turn. ";
31 }else{
34 std::cout << "Black";
36 std::cout << " turn. ";
37 }
38
39 if(chess_board.
is_check(white_move)){
40 std::cout << std::endl;
42 std::cout << "Warning : Check state" << std::endl;
44 }
45 std::cout << "What move ? " << std::endl;
46 std::cin >> movement;
47 if(movement == "/quit" || movement == "/resign" || movement == "/draw"){
48
49 game_end = true;
50 correct_move = true;
51 if(movement == "/quit"){
53 }
54 if(movement == "/resign"){
55 if(white_move){
57 }else{
59 }
60 }
61 if(movement == "/draw"){
63 }
64 }else{
66
68
71 if(chess_board.
is_legal(start,end,white_move)){
72
73 chess_board_copy =
new board(chess_board);
74 chess_board_copy->
move(start,end);
75 if(chess_board_copy->
is_check(white_move)){
76
77 std::cout << "Illegal move. Your king will be checked" << std::endl;
78 }else{
79 chess_board.
move(start,end);
80 correct_move = true;
83
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;
92 }
93 }
94
95 if(chose_promotion == "B"){
97 }
98 if(chose_promotion == "N"){
100 }
101 if(chose_promotion == "R"){
103 }
104 if(chose_promotion == "Q"){
106 }
107 }
108 }
109 delete chess_board_copy;
110 }else{
111 std::cout << "Illegal move." << std::endl;
112 }
113 }
115
117
118 chess_board_copy =
new board(chess_board);
120 if(chess_board_copy->
is_check(white_move)){
121
122 std::cout << "Illegal move. Your king will be checked" << std::endl;
123 }else{
125 correct_move = true;
126 }
127 delete chess_board_copy;
128 }else{
129 std::cout << "Illegal move." << std::endl;
130 }
131 }
133
135
136 chess_board_copy =
new board(chess_board);
138 if(chess_board_copy->
is_check(white_move)){
139
140 std::cout << "Illegal move. Your king will be checked" << std::endl;
141 }else{
143 correct_move = true;
144 }
145 delete chess_board_copy;
146 }else{
147 std::cout << "Illegal move." << std::endl;
148 }
149 }
150 }else{
151
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;
153 }
154 }
155 }
156
158 game_end = true;
160 if(white_move){
161 if(chess_board.
is_check(!white_move)){
165 std::cout << "White win.";
167 }else{
169 std::cout << "Draw.";
171 }
172 }else{
173 if(chess_board.
is_check(!white_move)){
177 std::cout << "Black win.";
179 }else{
181 std::cout << "Draw.";
183 }
184 }
185 }
186 white_move = !white_move;
187 }
189 switch (game_result)
190 {
192 std::cout << " 1-0" << std::endl;
193 break;
194
196 std::cout << " 0-1" << std::endl;
197 break;
198
200 std::cout << " 1/2-1/2" << std::endl;
201 break;
202
204 std::cout << " ?-?" << std::endl;
205 break;
206
207 }
208}
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
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