moves.h (1853B)
1 #ifndef STELLAR_MOVES_H 2 #define STELLAR_MOVES_H 3 4 #include <stdbool.h> 5 #include <stdint.h> 6 7 #include "board.h" 8 9 typedef struct Move Move; 10 struct Move { 11 unsigned source : 6; 12 unsigned target : 6; 13 unsigned piece : 5; 14 unsigned piece_capture : 5; 15 unsigned piece_promote : 5; 16 bool dbl : 1; 17 bool enpassant : 1; 18 bool castle : 1; 19 bool capture : 1; 20 bool promote : 1; 21 }; 22 23 typedef struct MoveList MoveList; 24 typedef struct MoveE MoveE; 25 26 struct MoveList { 27 int count; 28 struct MoveE { 29 Move move; 30 int score; 31 } moves[256]; 32 }; 33 34 int move_cmp(Move a, Move b); 35 Move move_encode(Square src, Square tgt, Piece piece, Piece capture, 36 Piece promote, int dbl, int enpassant, int castle); 37 void move_print(Move move); 38 MoveList *move_list_new(void); 39 40 void move_list_free(MoveList **p); 41 Move move_list_index_move(const MoveList *self, int index); 42 int move_list_index_score(const MoveList *self, int index); 43 void move_list_index_score_set(MoveList *self, int index, int score); 44 45 int move_make(Move move, Board *board, int flag); 46 47 int move_list_size(const MoveList *self); 48 void move_list_reset(MoveList *self); 49 void move_list_add(MoveList *self, Move move); 50 void move_list_print(const MoveList *self); 51 void move_list_sort(MoveList *list); 52 53 MoveList *move_list_generate(MoveList *moves, const Board *board); 54 55 #define move_source(move) (move.source) 56 #define move_target(move) (move.target) 57 #define move_double(move) (move.dbl) 58 #define move_enpassant(move) (move.enpassant) 59 #define move_castle(move) (move.castle) 60 #define move_capture(move) (move.capture) 61 #define move_promote(move) (move.promote) 62 63 #define move_piece(move) (piece_from_index(move.piece)) 64 #define move_piece_capture(move) (piece_from_index(move.piece_capture)) 65 #define move_piece_promote(move) (piece_from_index(move.piece_promote)) 66 67 #endif