stellar

Stellar - Chess engine written in C
Log | Files | Refs

moves.h (1568B)


      1 #ifndef MOVES_H
      2 #define MOVES_H
      3 
      4 #include <stdint.h>
      5 
      6 #include "CBoard.h"
      7 
      8 typedef struct Move Move;
      9 struct Move {
     10     unsigned source : 6;
     11     unsigned target : 6;
     12     unsigned piece : 5;
     13     unsigned piece_capture : 5;
     14     unsigned piece_promote : 5;
     15     unsigned dbl : 1;
     16     unsigned enpassant : 1;
     17     unsigned castle : 1;
     18     unsigned capture : 1;
     19     unsigned promote : 1;
     20 };
     21 
     22 typedef struct MoveList_T *MoveList_T;
     23 struct MoveList_T {
     24     Move moves[256];
     25     int count;
     26 };
     27 
     28 int Move_cmp(Move a, Move b);
     29 Move Move_encode(Square src, Square tgt, Piece_T Piece, Piece_T Capture,
     30                  Piece_T Promote, int dbl, int enpassant, int castle);
     31 void Move_print(Move move);
     32 MoveList_T MoveList_new(void);
     33 void MoveList_free(MoveList_T *p);
     34 Move MoveList_move(MoveList_T self, int index);
     35 int MoveList_size(MoveList_T self);
     36 void MoveList_reset(MoveList_T self);
     37 void MoveList_add(MoveList_T self, Move move);
     38 void MoveList_print(MoveList_T self);
     39 MoveList_T MoveList_generate(MoveList_T moves, CBoard_T board);
     40 int Move_make(Move move, CBoard_T board, int flag);
     41 
     42 #define Move_source(move) (move.source)
     43 #define Move_target(move) (move.target)
     44 #define Move_double(move) (move.dbl)
     45 #define Move_enpassant(move) (move.enpassant)
     46 #define Move_castle(move) (move.castle)
     47 #define Move_capture(move) (move.capture)
     48 #define Move_promote(move) (move.promote)
     49 
     50 #define Move_piece(move) (Piece_fromIndex(move.piece))
     51 #define Move_piece_capture(move) (Piece_fromIndex(move.piece_capture))
     52 #define Move_piece_promote(move) (Piece_fromIndex(move.piece_promote))
     53 
     54 #endif