+// Define FORCE_INLINE macro to force inlining overriding compiler choice
+#if defined(_MSC_VER)
+#define FORCE_INLINE __forceinline
+#elif defined(__GNUC__)
+#define FORCE_INLINE inline __attribute__((always_inline))
+#else
+#define FORCE_INLINE inline
+#endif
+
+/// cpu_has_popcnt() detects support for popcnt instruction at runtime
+inline bool cpu_has_popcnt() {
+
+ int CPUInfo[4] = {-1};
+ __cpuid(CPUInfo, 0x00000001);
+ return (CPUInfo[2] >> 23) & 1;
+}
+
+/// CpuHasPOPCNT is a global constant initialized at startup that
+/// is set to true if CPU on which application runs supports popcnt
+/// hardware instruction. Unless USE_POPCNT is not defined.
+#if defined(USE_POPCNT)
+const bool CpuHasPOPCNT = cpu_has_popcnt();
+#else
+const bool CpuHasPOPCNT = false;
+#endif
+
+
+/// CpuIs64Bit is a global constant initialized at compile time that
+/// is set to true if CPU on which application runs is a 64 bits.
+#if defined(IS_64BIT)
+const bool CpuIs64Bit = true;
+#else
+const bool CpuIs64Bit = false;
+#endif
+
+#include <string>
+
+typedef uint64_t Key;
+typedef uint64_t Bitboard;
+
+const int PLY_MAX = 100;
+const int PLY_MAX_PLUS_2 = PLY_MAX + 2;
+
+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_PLY_MAX = VALUE_MATE - PLY_MAX,
+ VALUE_MATED_IN_PLY_MAX = -VALUE_MATE + PLY_MAX,
+
+ VALUE_ENSURE_INTEGER_SIZE_P = INT_MAX,
+ VALUE_ENSURE_INTEGER_SIZE_N = INT_MIN
+};
+
+enum PieceType {
+ PIECE_TYPE_NONE = 0,
+ PAWN = 1, KNIGHT = 2, BISHOP = 3, ROOK = 4, QUEEN = 5, KING = 6
+};
+
+enum Piece {
+ PIECE_NONE_DARK_SQ = 0, WP = 1, WN = 2, WB = 3, WR = 4, WQ = 5, WK = 6,
+ BP = 9, BN = 10, BB = 11, BR = 12, BQ = 13, BK = 14, PIECE_NONE = 16
+};
+
+enum Color {
+ WHITE, BLACK, COLOR_NONE
+};
+
+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
+};
+
+enum SquareColor {
+ DARK, LIGHT
+};
+
+enum ScaleFactor {
+ SCALE_FACTOR_ZERO = 0,
+ SCALE_FACTOR_NORMAL = 64,
+ SCALE_FACTOR_MAX = 128,
+ SCALE_FACTOR_NONE = 255
+};
+
+enum CastleRight {
+ CASTLES_NONE = 0,
+ WHITE_OO = 1,
+ BLACK_OO = 2,
+ WHITE_OOO = 4,
+ BLACK_OOO = 8,
+ ALL_CASTLES = 15
+};
+
+
+/// 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
+};