stellar

Stellar - UCI Chess engine written in C++20
git clone git://git.dimitrijedobrota.com/stellar.git
Log | Files | Refs | README | LICENSE

utils.hpp (1825B)


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