stellar

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

utils.h (2017B)


      1 #ifndef __UTILS_H
      2 #define __UTILS_H
      3 
      4 // useful macros
      5 #define MAX(a, b) ((a > b) ? a : b)
      6 #define MIN(a, b) ((a < b) ? a : b)
      7 
      8 // define number types
      9 typedef unsigned long long U64;           // define bitboard data type
     10 #define C64(constantU64) constantU64##ULL // define shorthand for constants
     11 
     12 typedef unsigned int U32;
     13 #define C32(constantU32) constantU32##U
     14 
     15 // useful bit patterns
     16 extern const U64 universe;
     17 extern const U64 notAFile;
     18 extern const U64 notHFile;
     19 
     20 // useful bit functions
     21 #define bit_get(bitboard, square) (((bitboard) >> (square)) & C64(1))
     22 #define bit_set(bitboard, square) ((bitboard) |= C64(1) << (square))
     23 #define bit_pop(bitboard, square) ((bitboard) &= ~(C64(1) << (square)))
     24 int bit_count(U64 bitboard);
     25 int bit_lsb_index(U64 bitboard);
     26 
     27 #define bitboard_for_each_bit(var, bb)                                         \
     28   for (var = bit_lsb_index(bb); bb; bit_pop(bb, var), var = bit_lsb_index(bb))
     29 
     30 void bitboard_print(U64 bitboard);
     31 
     32 // squares
     33 // clang-format off
     34 enum enumSquare {
     35   a1, b1, c1, d1, e1, f1, g1, h1,
     36   a2, b2, c2, d2, e2, f2, g2, h2,
     37   a3, b3, c3, d3, e3, f3, g3, h3,
     38   a4, b4, c4, d4, e4, f4, g4, h4,
     39   a5, b5, c5, d5, e5, f5, g5, h5,
     40   a6, b6, c6, d6, e6, f6, g6, h6,
     41   a7, b7, c7, d7, e7, f7, g7, h7,
     42   a8, b8, c8, d8, e8, f8, g8, h8, no_sq
     43 };
     44 // clang-format on
     45 typedef enum enumSquare Square;
     46 
     47 extern const char *square_to_coordinates[];
     48 Square coordinates_to_square(char * cord);
     49 
     50 // board moving
     51 typedef U64 (*direction_f)(U64);
     52 U64 soutOne(U64 b);
     53 U64 nortOne(U64 b);
     54 U64 eastOne(U64 b);
     55 U64 westOne(U64 b);
     56 U64 soEaOne(U64 b);
     57 U64 soWeOne(U64 b);
     58 U64 noEaOne(U64 b);
     59 U64 noWeOne(U64 b);
     60 
     61 // board rotation
     62 U64 rotateLeft(U64 x, int s);
     63 U64 rotateRight(U64 x, int s);
     64 
     65 // enum types for color and piece type
     66 enum enumColor { WHITE = 0, BLACK };
     67 enum enumPiece { PAWN = 0, KNIGHT, BISHOP, ROOK, QUEEN, KING };
     68 
     69 typedef enum enumColor eColor;
     70 typedef enum enumPiece ePiece;
     71 
     72 int get_time_ms(void);
     73 
     74 typedef U64 (*attack_f)(Square square, U64 occupancy);
     75 
     76 
     77 #endif