+const Bitboard Rank1BB = 0xFF;
+const Bitboard Rank2BB = Rank1BB << (8 * 1);
+const Bitboard Rank3BB = Rank1BB << (8 * 2);
+const Bitboard Rank4BB = Rank1BB << (8 * 3);
+const Bitboard Rank5BB = Rank1BB << (8 * 4);
+const Bitboard Rank6BB = Rank1BB << (8 * 5);
+const Bitboard Rank7BB = Rank1BB << (8 * 6);
+const Bitboard Rank8BB = Rank1BB << (8 * 7);
+
+
+/// A move needs 16 bits to be stored
+///
+/// bit 0- 5: destination square (from 0 to 63)
+/// bit 6-11: origin square (from 0 to 63)
+/// bit 12-13: promotion piece type - 2 (from KNIGHT-2 to QUEEN-2)
+/// bit 14-15: special move flag: promotion (1), en passant (2), castle (3)
+///
+/// Special cases are MOVE_NONE and MOVE_NULL. We can sneak these in because in
+/// any normal move destination square is always different from origin square
+/// while MOVE_NONE and MOVE_NULL have the same origin and destination square.
+
+enum Move {
+ MOVE_NONE = 0,
+ MOVE_NULL = 65
+};
+
+enum MoveType {
+ NORMAL = 0,
+ PROMOTION = 1 << 14,
+ ENPASSANT = 2 << 14,
+ CASTLE = 3 << 14
+};
+
+enum CastleRight { // Defined as in PolyGlot book hash key
+ CASTLES_NONE = 0,
+ WHITE_OO = 1,
+ WHITE_OOO = 2,
+ BLACK_OO = 4,
+ BLACK_OOO = 8,
+ ALL_CASTLES = 15,
+ CASTLE_RIGHT_NB = 16
+};
+
+enum CastlingSide {
+ KING_SIDE,
+ QUEEN_SIDE,
+ CASTLING_SIDE_NB = 2
+};
+
+enum Phase {
+ PHASE_ENDGAME = 0,
+ PHASE_MIDGAME = 128,
+ MG = 0, EG = 1, PHASE_NB = 2
+};
+
+enum ScaleFactor {
+ SCALE_FACTOR_DRAW = 0,
+ SCALE_FACTOR_NORMAL = 64,
+ SCALE_FACTOR_MAX = 128,
+ SCALE_FACTOR_NONE = 255
+};
+
+enum Bound {
+ BOUND_NONE = 0,
+ BOUND_UPPER = 1,
+ BOUND_LOWER = 2,
+ BOUND_EXACT = BOUND_UPPER | BOUND_LOWER
+};
+
+enum Value {
+ VALUE_ZERO = 0,
+ VALUE_DRAW = 0,
+ VALUE_KNOWN_WIN = 15000,
+ VALUE_MATE = 30000,
+ VALUE_INFINITE = 30001,
+ VALUE_NONE = 30002,
+
+ VALUE_MATE_IN_MAX_PLY = VALUE_MATE - MAX_PLY,
+ VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + MAX_PLY,
+
+ VALUE_ENSURE_INTEGER_SIZE_P = INT_MAX,
+ VALUE_ENSURE_INTEGER_SIZE_N = INT_MIN,
+
+ PawnValueMg = 198, PawnValueEg = 258,
+ KnightValueMg = 817, KnightValueEg = 846,
+ BishopValueMg = 836, BishopValueEg = 857,
+ RookValueMg = 1270, RookValueEg = 1278,
+ QueenValueMg = 2521, QueenValueEg = 2558
+};
+
+enum PieceType {
+ NO_PIECE_TYPE = 0, ALL_PIECES = 0,
+ PAWN = 1, KNIGHT = 2, BISHOP = 3, ROOK = 4, QUEEN = 5, KING = 6,
+ PIECE_TYPE_NB = 8
+};
+
+enum Piece {
+ NO_PIECE = 0,
+ W_PAWN = 1, W_KNIGHT = 2, W_BISHOP = 3, W_ROOK = 4, W_QUEEN = 5, W_KING = 6,
+ B_PAWN = 9, B_KNIGHT = 10, B_BISHOP = 11, B_ROOK = 12, B_QUEEN = 13, B_KING = 14,
+ PIECE_NB = 16
+};
+
+enum Color {
+ WHITE, BLACK, NO_COLOR, COLOR_NB = 2
+};
+
+enum Depth {
+
+ ONE_PLY = 2,
+
+ DEPTH_ZERO = 0 * ONE_PLY,
+ DEPTH_QS_CHECKS = -1 * ONE_PLY,
+ DEPTH_QS_NO_CHECKS = -2 * ONE_PLY,
+ DEPTH_QS_RECAPTURES = -5 * ONE_PLY,
+
+ DEPTH_NONE = -127 * ONE_PLY
+};
+
+enum Square {
+ 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_NB = 64,
+
+ DELTA_N = 8,
+ DELTA_E = 1,
+ DELTA_S = -8,
+ DELTA_W = -1,
+
+ DELTA_NN = DELTA_N + DELTA_N,
+ DELTA_NE = DELTA_N + DELTA_E,
+ DELTA_SE = DELTA_S + DELTA_E,
+ DELTA_SS = DELTA_S + DELTA_S,
+ DELTA_SW = DELTA_S + DELTA_W,
+ DELTA_NW = DELTA_N + DELTA_W
+};
+
+enum File {
+ FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H, FILE_NB = 8
+};
+
+enum Rank {
+ RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8, RANK_NB = 8
+};
+
+
+/// Score enum keeps a midgame and an endgame value in a single integer (enum),
+/// first LSB 16 bits are used to store endgame value, while upper bits are used
+/// for midgame value. Compiler is free to choose the enum type as long as can
+/// keep its data, so ensure Score to be an integer type.
+enum Score {
+ SCORE_ZERO = 0,
+ SCORE_ENSURE_INTEGER_SIZE_P = INT_MAX,
+ SCORE_ENSURE_INTEGER_SIZE_N = INT_MIN
+};
+
+inline Score make_score(int mg, int eg) { return Score((mg << 16) + eg); }
+
+/// Extracting the signed lower and upper 16 bits it not so trivial because
+/// according to the standard a simple cast to short is implementation defined
+/// and so is a right shift of a signed integer.
+inline Value mg_value(Score s) { return Value(((s + 32768) & ~0xffff) / 0x10000); }
+
+/// On Intel 64 bit we have a small speed regression with the standard conforming
+/// version, so use a faster code in this case that, although not 100% standard
+/// compliant it seems to work for Intel and MSVC.
+#if defined(IS_64BIT) && (!defined(__GNUC__) || defined(__INTEL_COMPILER))
+
+inline Value eg_value(Score s) { return Value(int16_t(s & 0xffff)); }