probably BASIC move logic done
This commit is contained in:
+56
-3
@@ -71,12 +71,65 @@ bool get_move(move_t *move) {
|
||||
return is_move_in_bounds(*move);
|
||||
}
|
||||
|
||||
bool perform_move(player_e player, move_t move) {
|
||||
|
||||
bool compare_pos(pos_t a, pos_t b) {
|
||||
return a.x == b.x && a.y == b.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* check the wanted pos_t against all valid move options
|
||||
* of the current piece
|
||||
*/
|
||||
bool is_move_legal(move_t move) {
|
||||
valid_move_t valid_moves[PIECE_COUNT] = DEFAULT_VALID_MOVES;
|
||||
for (int i = 0; i < PIECE_COUNT; i++) {
|
||||
for (int j = 0;
|
||||
j < valid_moves[i].piece_move_count &&
|
||||
move.piece == valid_moves[i].piece;
|
||||
j++
|
||||
) {
|
||||
pos_t new_pos = {move.from.x+move.to.x, move.from.y+move.to.y};
|
||||
if (compare_pos(new_pos, valid_moves[i].options[j]) == true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool is_none(board_t board, pos_t pos) {
|
||||
return board[pos.y][pos.x] == NONE;
|
||||
}
|
||||
|
||||
// the move can be:
|
||||
// 1. legal x illegal
|
||||
// 2. the 'to' pos could be occupied x non-occupied
|
||||
// 2a. it could be capturable x non-capturable
|
||||
bool validate_move(board_t board, move_t move) {
|
||||
bool none = is_none(board, move.to);
|
||||
bool move_legal = is_move_legal(move);
|
||||
if (none == true && move_legal == true) {
|
||||
// free ability to move
|
||||
return true;
|
||||
} else if (none == false && move_legal == true) {
|
||||
// capturing
|
||||
return true;
|
||||
} else {
|
||||
// otherwise, invalid move
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** TODO: capturing and promotions */
|
||||
bool perform_move(board_t *board, player_e player, move_t move) {
|
||||
if (validate_move(*board, move) == true) {
|
||||
*board[move.to.y][move.to.x] = move.piece; // move piece to wanted place
|
||||
*board[move.from.y][move.from.x] = NONE; // erase the remnants
|
||||
}
|
||||
}
|
||||
|
||||
end_condition_e check_edge_cases(board_t board) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
void announce_results(end_condition_e end_condition, player_e player) {
|
||||
|
||||
Reference in New Issue
Block a user