probably BASIC move logic done

This commit is contained in:
Odweta
2026-02-18 10:13:57 +01:00
parent e9b74eee16
commit ec44c7c07f
3 changed files with 74 additions and 23 deletions
+17 -19
View File
@@ -49,11 +49,6 @@ typedef struct {
pos_t to;
} move_t;
typedef struct {
int dirx;
int diry;
} relative_move_t;
// the default arrangment of pieces on the board
#define BOARD_DEFAULT_CONFIG \
(board_t){\
@@ -68,7 +63,7 @@ typedef struct {
typedef struct {
piece_e piece;
relative_move_t moves[MAX_PIECE_MOVE_COUNT];
pos_t options[MAX_PIECE_MOVE_COUNT];
unsigned int piece_move_count;
} valid_move_t;
@@ -90,27 +85,30 @@ typedef struct {
* absolute x,y values -> e.g. the rook can move
* up, down, left, right * n -> and then bounds & edge cases are checked
*/
#define DEFAULT_VALID_MOVES \
(valid_move_t[PIECE_COUNT]){\
{NONE, (relative_move_t[0]){}, 0},\
{PAWN, (relative_move_t[4]){\
{0, -1}, {-1, -1}, {+1, -1}, {0, -2}\
#define DEFAULT_VALID_MOVES (valid_move_t[PIECE_COUNT]){\
{NONE, {}, 0},\
{PAWN, {\
{ 0, -1}, {-1, -1}, {+1, -1}, { 0, -2}\
}, 4},\
{ROOK, (relative_move_t[4]){\
{0, -1}, {0, +1}, {-1, 0}, {+1, 0}\
{ROOK, {\
{ 0, -1}, { 0, +1}, {-1, 0}, {+1, 0}\
}, 4},\
{KNIGHT, (relative_move_t)[8], {\
{KNIGHT, {\
{-1, -2}, {+1, -2}, {-2, -1}, {-2, +1},\
{+2, -1}, {+2, +1}, {-1, -2}, {-1, +2}\
}, 8},\
{BISHOP, (relative_move_t[4]){\
{BISHOP, {\
{-1, -1}, {-1, +1}, {+1, -1}, {+1, +1}\
}, 4},\
{QUEEN, (relative_move_t[8]){\
{0, -1}, {0, +1}, {-1, 0}, {+1, 0},\
{QUEEN, {\
{0, -1}, {0, +1}, {-1, 0}, {+1, 0},\
{-1, -1}, {-1, +1}, {+1, -1}, {+1, +1}\
}, 8},\
{KING, {\
{ 0, -1}, { 0, +1}, {-1, 0}, {+1, 0},\
{-1, -1}, {-1, +1}, {+1, -1}, {+1, +1}\
}, 8}\
}\
}
typedef enum {
CHECKMATE,
@@ -128,7 +126,7 @@ void select_player(player_e *player, unsigned int round_count);
bool get_move(move_t *move);
// performs the move if is it possible
bool perform_move(player_e player, move_t move);
bool perform_move(board_t *board, player_e player, move_t move);
// checks for captures, prommotions and mates
end_condition_e check_edge_cases(board_t board);