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