sussed out the move model (i think)

This commit is contained in:
Odweta
2026-02-18 09:33:24 +01:00
parent 8ce26266f3
commit c9914b73a7
+38 -10
View File
@@ -68,21 +68,49 @@ typedef struct {
typedef struct { typedef struct {
piece_e piece; piece_e piece;
unsigned int piece_move_count;
relative_move_t moves[MAX_PIECE_MOVE_COUNT]; relative_move_t moves[MAX_PIECE_MOVE_COUNT];
unsigned int piece_move_count;
} valid_move_t; } 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 */ /** FIXED: 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
* => ASSUME NO OTHER PIECES - then ALWAYS CHECK
* FOR PIECE COLLISIONS and FOR ROUND COUNT
* (pawn 1 || 2 move)
*/
/** MAYBE: consider the POV from both sides???!!! */
/**
* the NONE, PAWN, KNIGHT and KING pieces' relative_moves are
* treated like specific coordinates relative to their
* position,
* whereas the BISHOP, ROOK and QUEEN pieces' 'moves'
* are treated as *directions* in which they can move rather than
* 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 \ #define DEFAULT_VALID_MOVES \
(valid_move_t[PIECE_COUNT]){\ (valid_move_t[PIECE_COUNT]){\
.piece = NONE, .count = 0, .moves = {}\ {NONE, (relative_move_t[0]){}, 0},\
.piece = PAWN, .count = 0, .moves = {}\ {PAWN, (relative_move_t[4]){\
.piece = ROOK, .count = 0, .moves = {}\ {0, -1}, {-1, -1}, {+1, -1}, {0, -2}\
.piece = KNIGHT, .count = 0, .moves = {}\ }, 4},\
.piece = BISHOP, .count = 0, .moves = {}\ {ROOK, (relative_move_t[4]){\
.piece = QUEEN, .count = 0, .moves = {}\ {0, -1}, {0, +1}, {-1, 0}, {+1, 0}\
.piece = KING, .count = 0, .moves = {}\ }, 14},\
} {KNIGHT, (relative_move_t)[8], {\
{-1, -2}, {+1, -2}, {-2, -1}, {-2, +1},\
{+2, -1}, {+2, +1}, {-1, -2}, {-1, +2}\
}, 8},\
{BISHOP, (relative_move_t[4]){\
{-1, -1}, {-1, +1}, {+1, -1}, {+1, +1}\
}, 14},\
{QUEEN, (relative_move_t[8]){\
{0, -1}, {0, +1}, {-1, 0}, {+1, 0},\
{-1, -1}, {-1, +1}, {+1, -1}, {+1, +1}\
}, 27}\
}\
typedef enum { typedef enum {
CHECKMATE, CHECKMATE,