From 8ce26266f36a99875f91fae93473e7b6d429f7bb Mon Sep 17 00:00:00 2001 From: Odweta Date: Tue, 17 Feb 2026 17:27:14 +0100 Subject: [PATCH] started work on the movement logic --- src/chess.c | 2 +- src/chess.h | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/chess.c b/src/chess.c index 01d35fd..3a904d9 100644 --- a/src/chess.c +++ b/src/chess.c @@ -72,7 +72,7 @@ bool get_move(move_t *move) { } bool perform_move(player_e player, move_t move) { - + } end_condition_e check_edge_cases(board_t board) { diff --git a/src/chess.h b/src/chess.h index f8de0b0..4287762 100644 --- a/src/chess.h +++ b/src/chess.h @@ -21,6 +21,8 @@ // type abstractions typedef int board_t[BOARD_HORIZONTAL][BOARD_VERTICAL]; +#define PIECE_COUNT 7 // how many unique pieces are there +#define MAX_PIECE_MOVE_COUNT 27 // the max possible num of options where to move in one moment typedef enum { NONE, PAWN, @@ -47,6 +49,11 @@ 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){\ @@ -59,6 +66,24 @@ typedef struct { {2,3,4,5,6,4,3,2}\ } +typedef struct { + piece_e piece; + unsigned int piece_move_count; + relative_move_t moves[MAX_PIECE_MOVE_COUNT]; +} valid_move_t; + +/** FIXME: ALSO DEPENDS ON THE STATE OF THE GAME - e.g. a pawn cannot move two places in the middle of the game but can in the first round */ +#define DEFAULT_VALID_MOVES \ +(valid_move_t[PIECE_COUNT]){\ + .piece = NONE, .count = 0, .moves = {}\ + .piece = PAWN, .count = 0, .moves = {}\ + .piece = ROOK, .count = 0, .moves = {}\ + .piece = KNIGHT, .count = 0, .moves = {}\ + .piece = BISHOP, .count = 0, .moves = {}\ + .piece = QUEEN, .count = 0, .moves = {}\ + .piece = KING, .count = 0, .moves = {}\ +} + typedef enum { CHECKMATE, STALEMATE