+
+constexpr Value PieceValue[PHASE_NB][PIECE_NB] = {
+ { VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg, VALUE_ZERO, VALUE_ZERO,
+ VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg, VALUE_ZERO, VALUE_ZERO },
+ { VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg, VALUE_ZERO, VALUE_ZERO,
+ VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg, VALUE_ZERO, VALUE_ZERO }
+};
+
+typedef int Depth;
+
+enum : int {
+ DEPTH_QS_CHECKS = 0,
+ DEPTH_QS_NO_CHECKS = -1,
+ DEPTH_QS_RECAPTURES = -5,
+
+ DEPTH_NONE = -6,
+ DEPTH_OFFSET = DEPTH_NONE
+};
+
+enum Square : int {
+ SQ_A1, SQ_B1, SQ_C1, SQ_D1, SQ_E1, SQ_F1, SQ_G1, SQ_H1,
+ SQ_A2, SQ_B2, SQ_C2, SQ_D2, SQ_E2, SQ_F2, SQ_G2, SQ_H2,
+ SQ_A3, SQ_B3, SQ_C3, SQ_D3, SQ_E3, SQ_F3, SQ_G3, SQ_H3,
+ SQ_A4, SQ_B4, SQ_C4, SQ_D4, SQ_E4, SQ_F4, SQ_G4, SQ_H4,
+ SQ_A5, SQ_B5, SQ_C5, SQ_D5, SQ_E5, SQ_F5, SQ_G5, SQ_H5,
+ SQ_A6, SQ_B6, SQ_C6, SQ_D6, SQ_E6, SQ_F6, SQ_G6, SQ_H6,
+ SQ_A7, SQ_B7, SQ_C7, SQ_D7, SQ_E7, SQ_F7, SQ_G7, SQ_H7,
+ SQ_A8, SQ_B8, SQ_C8, SQ_D8, SQ_E8, SQ_F8, SQ_G8, SQ_H8,
+ SQ_NONE,
+
+ SQUARE_ZERO = 0,
+ SQUARE_NB = 64
+};
+
+enum Direction : int {
+ NORTH = 8,
+ EAST = 1,
+ SOUTH = -NORTH,
+ WEST = -EAST,
+
+ NORTH_EAST = NORTH + EAST,
+ SOUTH_EAST = SOUTH + EAST,
+ SOUTH_WEST = SOUTH + WEST,
+ NORTH_WEST = NORTH + WEST
+};
+
+enum File : int {
+ FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H, FILE_NB
+};
+
+enum Rank : int {
+ RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8, RANK_NB
+};
+
+// unique number for each piece type on each square
+enum PieceSquare : uint32_t {
+ PS_NONE = 0,
+ PS_W_PAWN = 1,
+ PS_B_PAWN = 1 * SQUARE_NB + 1,
+ PS_W_KNIGHT = 2 * SQUARE_NB + 1,
+ PS_B_KNIGHT = 3 * SQUARE_NB + 1,
+ PS_W_BISHOP = 4 * SQUARE_NB + 1,
+ PS_B_BISHOP = 5 * SQUARE_NB + 1,
+ PS_W_ROOK = 6 * SQUARE_NB + 1,
+ PS_B_ROOK = 7 * SQUARE_NB + 1,
+ PS_W_QUEEN = 8 * SQUARE_NB + 1,
+ PS_B_QUEEN = 9 * SQUARE_NB + 1,
+ PS_W_KING = 10 * SQUARE_NB + 1,
+ PS_END = PS_W_KING, // pieces without kings (pawns included)
+ PS_B_KING = 11 * SQUARE_NB + 1,
+ PS_END2 = 12 * SQUARE_NB + 1
+};
+
+struct ExtPieceSquare {
+ PieceSquare from[COLOR_NB];
+};
+
+// Array for finding the PieceSquare corresponding to the piece on the board
+extern ExtPieceSquare kpp_board_index[PIECE_NB];
+
+constexpr bool is_ok(PieceId pid);
+constexpr Square rotate180(Square sq);
+
+// Structure holding which tracked piece (PieceId) is where (PieceSquare)
+class EvalList {
+
+public:
+ // Max. number of pieces without kings is 30 but must be a multiple of 4 in AVX2
+ static const int MAX_LENGTH = 32;
+
+ // Array that holds the piece id for the pieces on the board
+ PieceId piece_id_list[SQUARE_NB];
+
+ // List of pieces, separate from White and Black POV
+ PieceSquare* piece_list_fw() const { return const_cast<PieceSquare*>(pieceListFw); }
+ PieceSquare* piece_list_fb() const { return const_cast<PieceSquare*>(pieceListFb); }
+
+ // Place the piece pc with piece_id on the square sq on the board
+ void put_piece(PieceId piece_id, Square sq, Piece pc)
+ {
+ assert(is_ok(piece_id));
+ if (pc != NO_PIECE)
+ {
+ pieceListFw[piece_id] = PieceSquare(kpp_board_index[pc].from[WHITE] + sq);
+ pieceListFb[piece_id] = PieceSquare(kpp_board_index[pc].from[BLACK] + rotate180(sq));
+ piece_id_list[sq] = piece_id;
+ }
+ else
+ {
+ pieceListFw[piece_id] = PS_NONE;
+ pieceListFb[piece_id] = PS_NONE;
+ piece_id_list[sq] = piece_id;
+ }
+ }
+
+ // Convert the specified piece_id piece to ExtPieceSquare type and return it
+ ExtPieceSquare piece_with_id(PieceId piece_id) const
+ {
+ ExtPieceSquare eps;
+ eps.from[WHITE] = pieceListFw[piece_id];
+ eps.from[BLACK] = pieceListFb[piece_id];
+ return eps;
+ }
+
+private:
+ PieceSquare pieceListFw[MAX_LENGTH];
+ PieceSquare pieceListFb[MAX_LENGTH];
+};
+
+// For differential evaluation of pieces that changed since last turn
+struct DirtyPiece {
+
+ // Number of changed pieces
+ int dirty_num;
+
+ // The ids of changed pieces, max. 2 pieces can change in one move
+ PieceId pieceId[2];
+
+ // What changed from the piece with that piece number
+ ExtPieceSquare old_piece[2];
+ ExtPieceSquare new_piece[2];
+};
+
+/// Score enum stores a middlegame and an endgame value in a single integer (enum).
+/// The least significant 16 bits are used to store the middlegame value and the
+/// upper 16 bits are used to store the endgame value. We have to take care to
+/// avoid left-shifting a signed int to avoid undefined behavior.
+enum Score : int { SCORE_ZERO };
+
+constexpr Score make_score(int mg, int eg) {
+ return Score((int)((unsigned int)eg << 16) + mg);