+
+enum CastleRight {
+ CASTLES_NONE = 0,
+ WHITE_OO = 1,
+ BLACK_OO = 2,
+ WHITE_OOO = 4,
+ BLACK_OOO = 8,
+ ALL_CASTLES = 15
+};
+
+enum ScaleFactor {
+ SCALE_FACTOR_DRAW = 0,
+ SCALE_FACTOR_NORMAL = 64,
+ SCALE_FACTOR_MAX = 128,
+ SCALE_FACTOR_NONE = 255
+};
+
+enum ValueType {
+ VALUE_TYPE_NONE = 0,
+ VALUE_TYPE_UPPER = 1,
+ VALUE_TYPE_LOWER = 2,
+ VALUE_TYPE_EXACT = VALUE_TYPE_UPPER | VALUE_TYPE_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
+};
+
+enum PieceType {
+ NO_PIECE_TYPE = 0,
+ PAWN = 1, KNIGHT = 2, BISHOP = 3, ROOK = 4, QUEEN = 5, KING = 6
+};
+
+enum Piece {
+ NO_PIECE = 16, // color_of(NO_PIECE) == NO_COLOR
+ 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
+};
+
+enum Color {
+ WHITE, BLACK, NO_COLOR
+};
+
+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 = -4 * 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,
+
+ 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
+};
+
+enum Rank {
+ RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_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)); }
+