select player + roundcount helper done
This commit is contained in:
+27
-1
@@ -1,5 +1,31 @@
|
||||
#include "chess.h"
|
||||
#include "util.h"
|
||||
|
||||
bool init_board(board_t *board) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void select_player(player_e *player, unsigned int round_count) {
|
||||
if (round_count == 1) {
|
||||
*player = WHITE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (*player == WHITE) {
|
||||
*player = BLACK;
|
||||
return;
|
||||
}
|
||||
|
||||
if (*player == BLACK) {
|
||||
*player = WHITE;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool get_move(move_t *move);
|
||||
|
||||
bool perform_move(player_e player, move_t move);
|
||||
|
||||
end_condition_e check_edge_cases(board_t board);
|
||||
|
||||
void announce_results(player_e player);
|
||||
+17
@@ -67,4 +67,21 @@ typedef enum {
|
||||
// initializes the board with the default configuration of pieces
|
||||
bool init_board(board_t *board);
|
||||
|
||||
// selects the player to currently play
|
||||
// if it is the first round, it selects white
|
||||
void select_player(player_e *player, unsigned int round_count);
|
||||
|
||||
// listens for a command to make a move by the currently playing player
|
||||
bool get_move(move_t *move);
|
||||
|
||||
// performs the move if is it possible
|
||||
bool perform_move(player_e player, move_t move);
|
||||
|
||||
// checks for captures, prommotions and mates
|
||||
end_condition_e check_edge_cases(board_t board);
|
||||
|
||||
// if there is one of the mates, end the game and show who has won
|
||||
void announce_results(player_e player);
|
||||
|
||||
|
||||
#endif // CHESS_H
|
||||
+3
-1
@@ -20,6 +20,7 @@ int main() {
|
||||
board_t board;
|
||||
move_t move;
|
||||
player_e player;
|
||||
unsigned int round_count = 0;
|
||||
end_condition_e end_condition;
|
||||
bool running = true;
|
||||
|
||||
@@ -28,8 +29,9 @@ int main() {
|
||||
init_board(&board);
|
||||
|
||||
while (running) {
|
||||
round_count++;
|
||||
|
||||
select_player(&player);
|
||||
select_player(&player, round_count);
|
||||
|
||||
get_move(&move);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user