stellarUCI Chess engine written in C++20 |
git clone git://git.dimitrijedobrota.com/stellar.git |
Log | Files | Refs | README | LICENSE |
utils.hpp (1825B)
0 #ifndef STELLAR_UTILS_HPP 1 #define STELLAR_UTILS_HPP 2 3 #include <cstdint> 4 5 #define C64(constantU64) constantU64##ULL 6 #define C32(constantU64) constantU64##UL 7 8 typedef uint64_t U64; 9 typedef uint32_t U32; 10 11 #define ENABLE_INCR_OPERATORS_ON(T) \ 12 inline T &operator++(T &d) { return d = T(int(d) + 1); } \ 13 inline T &operator--(T &d) { return d = T(int(d) - 1); } 14 15 /* Color */ 16 17 enum Color { 18 WHITE, 19 BLACK, 20 COLOR_NB = 2 21 }; 22 23 inline constexpr const Color other(const Color color) { return static_cast<Color>(!color); } 24 25 /* Square */ 26 27 enum Square : int { 28 // clang-format off 29 a1, b1, c1, d1, e1, f1, g1, h1, 30 a2, b2, c2, d2, e2, f2, g2, h2, 31 a3, b3, c3, d3, e3, f3, g3, h3, 32 a4, b4, c4, d4, e4, f4, g4, h4, 33 a5, b5, c5, d5, e5, f5, g5, h5, 34 a6, b6, c6, d6, e6, f6, g6, h6, 35 a7, b7, c7, d7, e7, f7, g7, h7, 36 a8, b8, c8, d8, e8, f8, g8, h8, no_sq 37 // clang-format on 38 }; 39 40 ENABLE_INCR_OPERATORS_ON(Square) 41 42 constexpr const Square mirror_array[]{ 43 // clang-format off 44 a8, b8, c8, d8, e8, f8, g8, h8, 45 a7, b7, c7, d7, e7, f7, g7, h7, 46 a6, b6, c6, d6, e6, f6, g6, h6, 47 a5, b5, c5, d5, e5, f5, g5, h5, 48 a4, b4, c4, d4, e4, f4, g4, h4, 49 a3, b3, c3, d3, e3, f3, g3, h3, 50 a2, b2, c2, d2, e2, f2, g2, h2, 51 a1, b1, c1, d1, e1, f1, g1, h1, no_sq 52 // clang-format on 53 }; 54 55 constexpr uint8_t get_file(const Square square) { return square & 0x07; } 56 constexpr uint8_t get_rank(const Square square) { return square >> 3; } 57 constexpr Square get_mirror(const Square square) { return mirror_array[square]; } 58 59 /* piece */ 60 61 enum Type { 62 PAWN = 0, 63 KNIGHT, 64 BISHOP, 65 ROOK, 66 QUEEN, 67 KING, 68 NO_TYPE, 69 }; 70 71 ENABLE_INCR_OPERATORS_ON(Type) 72 73 #endif