1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

Use self-describing constants instead of numbers

And remove now useless comments.

No functional change.
This commit is contained in:
Marco Costalba 2012-10-21 10:41:23 +02:00
parent 6b909b2343
commit e304db9d1e
16 changed files with 123 additions and 117 deletions

View file

@ -28,31 +28,31 @@
CACHE_LINE_ALIGNMENT CACHE_LINE_ALIGNMENT
Bitboard RMasks[64]; Bitboard RMasks[SQUARE_NB];
Bitboard RMagics[64]; Bitboard RMagics[SQUARE_NB];
Bitboard* RAttacks[64]; Bitboard* RAttacks[SQUARE_NB];
unsigned RShifts[64]; unsigned RShifts[SQUARE_NB];
Bitboard BMasks[64]; Bitboard BMasks[SQUARE_NB];
Bitboard BMagics[64]; Bitboard BMagics[SQUARE_NB];
Bitboard* BAttacks[64]; Bitboard* BAttacks[SQUARE_NB];
unsigned BShifts[64]; unsigned BShifts[SQUARE_NB];
Bitboard SquareBB[64]; Bitboard SquareBB[SQUARE_NB];
Bitboard FileBB[8]; Bitboard FileBB[FILE_NB];
Bitboard RankBB[8]; Bitboard RankBB[RANK_NB];
Bitboard AdjacentFilesBB[8]; Bitboard AdjacentFilesBB[FILE_NB];
Bitboard ThisAndAdjacentFilesBB[8]; Bitboard ThisAndAdjacentFilesBB[FILE_NB];
Bitboard InFrontBB[2][8]; Bitboard InFrontBB[COLOR_NB][RANK_NB];
Bitboard StepAttacksBB[16][64]; Bitboard StepAttacksBB[PIECE_NB][SQUARE_NB];
Bitboard BetweenBB[64][64]; Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
Bitboard DistanceRingsBB[64][8]; Bitboard DistanceRingsBB[SQUARE_NB][8];
Bitboard ForwardBB[2][64]; Bitboard ForwardBB[COLOR_NB][SQUARE_NB];
Bitboard PassedPawnMask[2][64]; Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
Bitboard AttackSpanMask[2][64]; Bitboard AttackSpanMask[COLOR_NB][SQUARE_NB];
Bitboard PseudoAttacks[6][64]; Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
int SquareDistance[64][64]; int SquareDistance[SQUARE_NB][SQUARE_NB];
namespace { namespace {
@ -63,7 +63,7 @@ namespace {
CACHE_LINE_ALIGNMENT CACHE_LINE_ALIGNMENT
int MS1BTable[256]; int MS1BTable[256];
Square BSFTable[64]; Square BSFTable[SQUARE_NB];
Bitboard RTable[0x19000]; // Storage space for rook attacks Bitboard RTable[0x19000]; // Storage space for rook attacks
Bitboard BTable[0x1480]; // Storage space for bishop attacks Bitboard BTable[0x1480]; // Storage space for bishop attacks

View file

@ -39,29 +39,29 @@ uint32_t probe_kpk(Square wksq, Square wpsq, Square bksq, Color stm);
CACHE_LINE_ALIGNMENT CACHE_LINE_ALIGNMENT
extern Bitboard RMasks[64]; extern Bitboard RMasks[SQUARE_NB];
extern Bitboard RMagics[64]; extern Bitboard RMagics[SQUARE_NB];
extern Bitboard* RAttacks[64]; extern Bitboard* RAttacks[SQUARE_NB];
extern unsigned RShifts[64]; extern unsigned RShifts[SQUARE_NB];
extern Bitboard BMasks[64]; extern Bitboard BMasks[SQUARE_NB];
extern Bitboard BMagics[64]; extern Bitboard BMagics[SQUARE_NB];
extern Bitboard* BAttacks[64]; extern Bitboard* BAttacks[SQUARE_NB];
extern unsigned BShifts[64]; extern unsigned BShifts[SQUARE_NB];
extern Bitboard SquareBB[64]; extern Bitboard SquareBB[SQUARE_NB];
extern Bitboard FileBB[8]; extern Bitboard FileBB[FILE_NB];
extern Bitboard RankBB[8]; extern Bitboard RankBB[RANK_NB];
extern Bitboard AdjacentFilesBB[8]; extern Bitboard AdjacentFilesBB[FILE_NB];
extern Bitboard ThisAndAdjacentFilesBB[8]; extern Bitboard ThisAndAdjacentFilesBB[FILE_NB];
extern Bitboard InFrontBB[2][8]; extern Bitboard InFrontBB[COLOR_NB][RANK_NB];
extern Bitboard StepAttacksBB[16][64]; extern Bitboard StepAttacksBB[PIECE_NB][SQUARE_NB];
extern Bitboard BetweenBB[64][64]; extern Bitboard BetweenBB[SQUARE_NB][SQUARE_NB];
extern Bitboard DistanceRingsBB[64][8]; extern Bitboard DistanceRingsBB[SQUARE_NB][8];
extern Bitboard ForwardBB[2][64]; extern Bitboard ForwardBB[COLOR_NB][SQUARE_NB];
extern Bitboard PassedPawnMask[2][64]; extern Bitboard PassedPawnMask[COLOR_NB][SQUARE_NB];
extern Bitboard AttackSpanMask[2][64]; extern Bitboard AttackSpanMask[COLOR_NB][SQUARE_NB];
extern Bitboard PseudoAttacks[6][64]; extern Bitboard PseudoAttacks[PIECE_TYPE_NB][SQUARE_NB];
/// Overloads of bitwise operators between a Bitboard and a Square for testing /// Overloads of bitwise operators between a Bitboard and a Square for testing

View file

@ -31,7 +31,7 @@ namespace {
// Table used to drive the defending king towards the edge of the board // Table used to drive the defending king towards the edge of the board
// in KX vs K and KQ vs KR endgames. // in KX vs K and KQ vs KR endgames.
const int MateTable[64] = { const int MateTable[SQUARE_NB] = {
100, 90, 80, 70, 70, 80, 90, 100, 100, 90, 80, 70, 70, 80, 90, 100,
90, 70, 60, 50, 50, 60, 70, 90, 90, 70, 60, 50, 50, 60, 70, 90,
80, 60, 40, 30, 30, 40, 60, 80, 80, 60, 40, 30, 30, 40, 60, 80,
@ -44,7 +44,7 @@ namespace {
// Table used to drive the defending king towards a corner square of the // Table used to drive the defending king towards a corner square of the
// right color in KBN vs K endgames. // right color in KBN vs K endgames.
const int KBNKMateTable[64] = { const int KBNKMateTable[SQUARE_NB] = {
200, 190, 180, 170, 160, 150, 140, 130, 200, 190, 180, 170, 160, 150, 140, 130,
190, 180, 170, 160, 150, 140, 130, 140, 190, 180, 170, 160, 150, 140, 130, 140,
180, 170, 155, 140, 140, 125, 140, 150, 180, 170, 155, 140, 140, 125, 140, 150,

View file

@ -42,7 +42,7 @@ namespace {
// attackedBy[color][piece type] is a bitboard representing all squares // attackedBy[color][piece type] is a bitboard representing all squares
// attacked by a given color and piece type, attackedBy[color][0] contains // attacked by a given color and piece type, attackedBy[color][0] contains
// all squares attacked by the given color. // all squares attacked by the given color.
Bitboard attackedBy[2][8]; Bitboard attackedBy[COLOR_NB][PIECE_TYPE_NB];
// kingRing[color] is the zone around the king which is considered // kingRing[color] is the zone around the king which is considered
// by the king safety evaluation. This consists of the squares directly // by the king safety evaluation. This consists of the squares directly
@ -50,25 +50,25 @@ namespace {
// squares two ranks in front of the king. For instance, if black's king // squares two ranks in front of the king. For instance, if black's king
// is on g8, kingRing[BLACK] is a bitboard containing the squares f8, h8, // is on g8, kingRing[BLACK] is a bitboard containing the squares f8, h8,
// f7, g7, h7, f6, g6 and h6. // f7, g7, h7, f6, g6 and h6.
Bitboard kingRing[2]; Bitboard kingRing[COLOR_NB];
// kingAttackersCount[color] is the number of pieces of the given color // kingAttackersCount[color] is the number of pieces of the given color
// which attack a square in the kingRing of the enemy king. // which attack a square in the kingRing of the enemy king.
int kingAttackersCount[2]; int kingAttackersCount[COLOR_NB];
// kingAttackersWeight[color] is the sum of the "weight" of the pieces of the // kingAttackersWeight[color] is the sum of the "weight" of the pieces of the
// given color which attack a square in the kingRing of the enemy king. The // given color which attack a square in the kingRing of the enemy king. The
// weights of the individual piece types are given by the variables // weights of the individual piece types are given by the variables
// QueenAttackWeight, RookAttackWeight, BishopAttackWeight and // QueenAttackWeight, RookAttackWeight, BishopAttackWeight and
// KnightAttackWeight in evaluate.cpp // KnightAttackWeight in evaluate.cpp
int kingAttackersWeight[2]; int kingAttackersWeight[COLOR_NB];
// kingAdjacentZoneAttacksCount[color] is the number of attacks to squares // kingAdjacentZoneAttacksCount[color] is the number of attacks to squares
// directly adjacent to the king of the given color. Pieces which attack // directly adjacent to the king of the given color. Pieces which attack
// more than one square are counted multiple times. For instance, if black's // more than one square are counted multiple times. For instance, if black's
// king is on g8 and there's a white knight on g5, this knight adds // king is on g8 and there's a white knight on g5, this knight adds
// 2 to kingAdjacentZoneAttacksCount[BLACK]. // 2 to kingAdjacentZoneAttacksCount[BLACK].
int kingAdjacentZoneAttacksCount[2]; int kingAdjacentZoneAttacksCount[COLOR_NB];
}; };
// Evaluation grain size, must be a power of 2 // Evaluation grain size, must be a power of 2
@ -114,7 +114,7 @@ namespace {
// OutpostBonus[PieceType][Square] contains outpost bonuses of knights and // OutpostBonus[PieceType][Square] contains outpost bonuses of knights and
// bishops, indexed by piece type and square (from white's point of view). // bishops, indexed by piece type and square (from white's point of view).
const Value OutpostBonus[][64] = { const Value OutpostBonus[][SQUARE_NB] = {
{ {
// A B C D E F G H // A B C D E F G H
V(0), V(0), V(0), V(0), V(0), V(0), V(0), V(0), // Knights V(0), V(0), V(0), V(0), V(0), V(0), V(0), V(0), // Knights
@ -134,7 +134,7 @@ namespace {
// ThreatBonus[attacking][attacked] contains threat bonuses according to // ThreatBonus[attacking][attacked] contains threat bonuses according to
// which piece type attacks which one. // which piece type attacks which one.
const Score ThreatBonus[][8] = { const Score ThreatBonus[][PIECE_TYPE_NB] = {
{}, {}, {}, {},
{ S(0, 0), S( 7, 39), S( 0, 0), S(24, 49), S(41,100), S(41,100) }, // KNIGHT { S(0, 0), S( 7, 39), S( 0, 0), S(24, 49), S(41,100), S(41,100) }, // KNIGHT
{ S(0, 0), S( 7, 39), S(24, 49), S( 0, 0), S(41,100), S(41,100) }, // BISHOP { S(0, 0), S( 7, 39), S(24, 49), S( 0, 0), S(41,100), S(41,100) }, // BISHOP
@ -221,11 +221,11 @@ namespace {
// KingDangerTable[Color][attackUnits] contains the actual king danger // KingDangerTable[Color][attackUnits] contains the actual king danger
// weighted scores, indexed by color and by a calculated integer number. // weighted scores, indexed by color and by a calculated integer number.
Score KingDangerTable[2][128]; Score KingDangerTable[COLOR_NB][128];
// TracedTerms[Color][PieceType || TracedType] contains a breakdown of the // TracedTerms[Color][PieceType || TracedType] contains a breakdown of the
// evaluation terms, used when tracing. // evaluation terms, used when tracing.
Score TracedScores[2][16]; Score TracedScores[COLOR_NB][16];
std::stringstream TraceStream; std::stringstream TraceStream;
enum TracedType { enum TracedType {
@ -364,7 +364,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
assert(!pos.in_check()); assert(!pos.in_check());
EvalInfo ei; EvalInfo ei;
Value margins[2]; Value margins[COLOR_NB];
Score score, mobilityWhite, mobilityBlack; Score score, mobilityWhite, mobilityBlack;
// margins[] store the uncertainty estimation of position's evaluation // margins[] store the uncertainty estimation of position's evaluation

View file

@ -44,8 +44,8 @@ public:
static const Value MaxValue = Value(2000); static const Value MaxValue = Value(2000);
private: private:
Value history[16][64]; // [piece][to_square] Value history[PIECE_NB][SQUARE_NB];
Value maxGains[16][64]; // [piece][to_square] Value maxGains[PIECE_NB][SQUARE_NB];
}; };
inline void History::clear() { inline void History::clear() {

View file

@ -40,11 +40,11 @@ namespace {
const int LinearCoefficients[6] = { 1617, -162, -1172, -190, 105, 26 }; const int LinearCoefficients[6] = { 1617, -162, -1172, -190, 105, 26 };
const int QuadraticCoefficientsSameColor[][8] = { const int QuadraticCoefficientsSameColor[][PIECE_TYPE_NB] = {
{ 7, 7, 7, 7, 7, 7 }, { 39, 2, 7, 7, 7, 7 }, { 35, 271, -4, 7, 7, 7 }, { 7, 7, 7, 7, 7, 7 }, { 39, 2, 7, 7, 7, 7 }, { 35, 271, -4, 7, 7, 7 },
{ 7, 25, 4, 7, 7, 7 }, { -27, -2, 46, 100, 56, 7 }, { 58, 29, 83, 148, -3, -25 } }; { 7, 25, 4, 7, 7, 7 }, { -27, -2, 46, 100, 56, 7 }, { 58, 29, 83, 148, -3, -25 } };
const int QuadraticCoefficientsOppositeColor[][8] = { const int QuadraticCoefficientsOppositeColor[][PIECE_TYPE_NB] = {
{ 41, 41, 41, 41, 41, 41 }, { 37, 41, 41, 41, 41, 41 }, { 10, 62, 41, 41, 41, 41 }, { 41, 41, 41, 41, 41, 41 }, { 37, 41, 41, 41, 41, 41 }, { 10, 62, 41, 41, 41, 41 },
{ 57, 64, 39, 41, 41, 41 }, { 50, 40, 23, -22, 41, 41 }, { 106, 101, 3, 151, 171, 41 } }; { 57, 64, 39, 41, 41, 41 }, { 50, 40, 23, -22, 41, 41 }, { 106, 101, 3, 151, 171, 41 } };
@ -215,7 +215,7 @@ MaterialEntry* MaterialTable::probe(const Position& pos) {
// Evaluate the material imbalance. We use PIECE_TYPE_NONE as a place holder // Evaluate the material imbalance. We use PIECE_TYPE_NONE as a place holder
// for the bishop pair "extended piece", this allow us to be more flexible // for the bishop pair "extended piece", this allow us to be more flexible
// in defining bishop pair bonuses. // in defining bishop pair bonuses.
const int pieceCount[2][8] = { const int pieceCount[COLOR_NB][PIECE_TYPE_NB] = {
{ pos.piece_count(WHITE, BISHOP) > 1, pos.piece_count(WHITE, PAWN), pos.piece_count(WHITE, KNIGHT), { pos.piece_count(WHITE, BISHOP) > 1, pos.piece_count(WHITE, PAWN), pos.piece_count(WHITE, KNIGHT),
pos.piece_count(WHITE, BISHOP) , pos.piece_count(WHITE, ROOK), pos.piece_count(WHITE, QUEEN) }, pos.piece_count(WHITE, BISHOP) , pos.piece_count(WHITE, ROOK), pos.piece_count(WHITE, QUEEN) },
{ pos.piece_count(BLACK, BISHOP) > 1, pos.piece_count(BLACK, PAWN), pos.piece_count(BLACK, KNIGHT), { pos.piece_count(BLACK, BISHOP) > 1, pos.piece_count(BLACK, PAWN), pos.piece_count(BLACK, KNIGHT),
@ -230,7 +230,7 @@ MaterialEntry* MaterialTable::probe(const Position& pos) {
/// piece type for both colors. /// piece type for both colors.
template<Color Us> template<Color Us>
int MaterialTable::imbalance(const int pieceCount[][8]) { int MaterialTable::imbalance(const int pieceCount[][PIECE_TYPE_NB]) {
const Color Them = (Us == WHITE ? BLACK : WHITE); const Color Them = (Us == WHITE ? BLACK : WHITE);

View file

@ -52,9 +52,9 @@ public:
private: private:
Key key; Key key;
int16_t value; int16_t value;
uint8_t factor[2]; uint8_t factor[COLOR_NB];
EndgameBase<Value>* evaluationFunction; EndgameBase<Value>* evaluationFunction;
EndgameBase<ScaleFactor>* scalingFunction[2]; EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB];
int spaceWeight; int spaceWeight;
Phase gamePhase; Phase gamePhase;
}; };
@ -67,7 +67,7 @@ struct MaterialTable {
MaterialEntry* probe(const Position& pos); MaterialEntry* probe(const Position& pos);
static Phase game_phase(const Position& pos); static Phase game_phase(const Position& pos);
template<Color Us> static int imbalance(const int pieceCount[][8]); template<Color Us> static int imbalance(const int pieceCount[][PIECE_TYPE_NB]);
HashTable<MaterialEntry, MaterialTableSize> entries; HashTable<MaterialEntry, MaterialTableSize> entries;
Endgames endgames; Endgames endgames;

View file

@ -28,7 +28,7 @@
using namespace std; using namespace std;
static const char* PieceToChar = " PNBRQK pnbrqk"; static const char* PieceToChar[COLOR_NB] = { "PNBRQK", "pnbrqk" };
/// score_to_uci() converts a value to a string suitable for use with the UCI /// score_to_uci() converts a value to a string suitable for use with the UCI
@ -75,7 +75,7 @@ const string move_to_uci(Move m, bool chess960) {
string move = square_to_string(from) + square_to_string(to); string move = square_to_string(from) + square_to_string(to);
if (type_of(m) == PROMOTION) if (type_of(m) == PROMOTION)
move += PieceToChar[make_piece(BLACK, promotion_type(m))]; // Lower case move += PieceToChar[BLACK][promotion_type(m)]; // Lower case
return move; return move;
} }
@ -125,7 +125,7 @@ const string move_to_san(Position& pos, Move m) {
{ {
if (pt != PAWN) if (pt != PAWN)
{ {
san = PieceToChar[pt]; // Upper case san = PieceToChar[WHITE][pt]; // Upper case
// Disambiguation if we have more then one piece with destination 'to' // Disambiguation if we have more then one piece with destination 'to'
// note that for pawns is not needed because starting file is explicit. // note that for pawns is not needed because starting file is explicit.
@ -167,7 +167,7 @@ const string move_to_san(Position& pos, Move m) {
san += square_to_string(to); san += square_to_string(to);
if (type_of(m) == PROMOTION) if (type_of(m) == PROMOTION)
san += string("=") + PieceToChar[promotion_type(m)]; san += string("=") + PieceToChar[WHITE][promotion_type(m)];
} }
if (pos.move_gives_check(m, CheckInfo(pos))) if (pos.move_gives_check(m, CheckInfo(pos)))

View file

@ -30,34 +30,34 @@ namespace {
#define S(mg, eg) make_score(mg, eg) #define S(mg, eg) make_score(mg, eg)
// Doubled pawn penalty by opposed flag and file // Doubled pawn penalty by opposed flag and file
const Score DoubledPawnPenalty[2][8] = { const Score DoubledPawnPenalty[2][FILE_NB] = {
{ S(13, 43), S(20, 48), S(23, 48), S(23, 48), { S(13, 43), S(20, 48), S(23, 48), S(23, 48),
S(23, 48), S(23, 48), S(20, 48), S(13, 43) }, S(23, 48), S(23, 48), S(20, 48), S(13, 43) },
{ S(13, 43), S(20, 48), S(23, 48), S(23, 48), { S(13, 43), S(20, 48), S(23, 48), S(23, 48),
S(23, 48), S(23, 48), S(20, 48), S(13, 43) }}; S(23, 48), S(23, 48), S(20, 48), S(13, 43) }};
// Isolated pawn penalty by opposed flag and file // Isolated pawn penalty by opposed flag and file
const Score IsolatedPawnPenalty[2][8] = { const Score IsolatedPawnPenalty[2][FILE_NB] = {
{ S(37, 45), S(54, 52), S(60, 52), S(60, 52), { S(37, 45), S(54, 52), S(60, 52), S(60, 52),
S(60, 52), S(60, 52), S(54, 52), S(37, 45) }, S(60, 52), S(60, 52), S(54, 52), S(37, 45) },
{ S(25, 30), S(36, 35), S(40, 35), S(40, 35), { S(25, 30), S(36, 35), S(40, 35), S(40, 35),
S(40, 35), S(40, 35), S(36, 35), S(25, 30) }}; S(40, 35), S(40, 35), S(36, 35), S(25, 30) }};
// Backward pawn penalty by opposed flag and file // Backward pawn penalty by opposed flag and file
const Score BackwardPawnPenalty[2][8] = { const Score BackwardPawnPenalty[2][FILE_NB] = {
{ S(30, 42), S(43, 46), S(49, 46), S(49, 46), { S(30, 42), S(43, 46), S(49, 46), S(49, 46),
S(49, 46), S(49, 46), S(43, 46), S(30, 42) }, S(49, 46), S(49, 46), S(43, 46), S(30, 42) },
{ S(20, 28), S(29, 31), S(33, 31), S(33, 31), { S(20, 28), S(29, 31), S(33, 31), S(33, 31),
S(33, 31), S(33, 31), S(29, 31), S(20, 28) }}; S(33, 31), S(33, 31), S(29, 31), S(20, 28) }};
// Pawn chain membership bonus by file // Pawn chain membership bonus by file
const Score ChainBonus[8] = { const Score ChainBonus[FILE_NB] = {
S(11,-1), S(13,-1), S(13,-1), S(14,-1), S(11,-1), S(13,-1), S(13,-1), S(14,-1),
S(14,-1), S(13,-1), S(13,-1), S(11,-1) S(14,-1), S(13,-1), S(13,-1), S(11,-1)
}; };
// Candidate passed pawn bonus by rank // Candidate passed pawn bonus by rank
const Score CandidateBonus[8] = { const Score CandidateBonus[RANK_NB] = {
S( 0, 0), S( 6, 13), S(6,13), S(14,29), S( 0, 0), S( 6, 13), S(6,13), S(14,29),
S(34,68), S(83,166), S(0, 0), S( 0, 0) S(34,68), S(83,166), S(0, 0), S( 0, 0)
}; };
@ -65,12 +65,12 @@ namespace {
const Score PawnStructureWeight = S(233, 201); const Score PawnStructureWeight = S(233, 201);
// Weakness of our pawn shelter in front of the king indexed by [king pawn][rank] // Weakness of our pawn shelter in front of the king indexed by [king pawn][rank]
const Value ShelterWeakness[2][8] = const Value ShelterWeakness[2][RANK_NB] =
{ { V(141), V(0), V(38), V(102), V(128), V(141), V(141) }, { { V(141), V(0), V(38), V(102), V(128), V(141), V(141) },
{ V( 61), V(0), V(16), V( 44), V( 56), V( 61), V( 61) } }; { V( 61), V(0), V(16), V( 44), V( 56), V( 61), V( 61) } };
// Danger of enemy pawns moving toward our king indexed by [pawn blocked][rank] // Danger of enemy pawns moving toward our king indexed by [pawn blocked][rank]
const Value StormDanger[2][8] = const Value StormDanger[2][RANK_NB] =
{ { V(26), V(0), V(128), V(51), V(26) }, { { V(26), V(0), V(128), V(51), V(26) },
{ V(13), V(0), V( 64), V(25), V(13) } }; { V(13), V(0), V( 64), V(25), V(13) } };

View file

@ -56,14 +56,14 @@ private:
Value shelter_storm(const Position& pos, Square ksq); Value shelter_storm(const Position& pos, Square ksq);
Key key; Key key;
Bitboard passedPawns[2]; Bitboard passedPawns[COLOR_NB];
Bitboard pawnAttacks[2]; Bitboard pawnAttacks[COLOR_NB];
Square kingSquares[2]; Square kingSquares[COLOR_NB];
int minKPdistance[2]; int minKPdistance[COLOR_NB];
int castleRights[2]; int castleRights[COLOR_NB];
Score value; Score value;
int halfOpenFiles[2]; int halfOpenFiles[COLOR_NB];
Score kingSafety[2]; Score kingSafety[COLOR_NB];
}; };

View file

@ -40,16 +40,16 @@ static const string PieceToChar(" PNBRQK pnbrqk");
CACHE_LINE_ALIGNMENT CACHE_LINE_ALIGNMENT
Score pieceSquareTable[16][64]; // [piece][square] Score pieceSquareTable[PIECE_NB][SQUARE_NB];
Value PieceValue[2][18] = { // [Mg / Eg][piece / pieceType] Value PieceValue[2][18] = { // [Mg / Eg][piece / pieceType]
{ VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg }, { VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg },
{ VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg } }; { VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg } };
namespace Zobrist { namespace Zobrist {
Key psq[2][8][64]; // [color][pieceType][square / piece count] Key psq[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
Key enpassant[8]; // [file] Key enpassant[FILE_NB];
Key castle[16]; // [castleRight] Key castle[CASTLE_RIGHT_NB];
Key side; Key side;
Key exclusion; Key exclusion;
@ -1593,7 +1593,7 @@ bool Position::pos_is_ok(int* failedStep) const {
if ((*step)++, debugKingCount) if ((*step)++, debugKingCount)
{ {
int kingCount[2] = {}; int kingCount[COLOR_NB] = {};
for (Square s = SQ_A1; s <= SQ_H8; s++) for (Square s = SQ_A1; s <= SQ_H8; s++)
if (type_of(piece_on(s)) == KING) if (type_of(piece_on(s)) == KING)

View file

@ -37,7 +37,7 @@ struct CheckInfo {
Bitboard dcCandidates; Bitboard dcCandidates;
Bitboard pinned; Bitboard pinned;
Bitboard checkSq[8]; Bitboard checkSq[PIECE_TYPE_NB];
Square ksq; Square ksq;
}; };
@ -49,7 +49,7 @@ struct CheckInfo {
struct StateInfo { struct StateInfo {
Key pawnKey, materialKey; Key pawnKey, materialKey;
Value npMaterial[2]; Value npMaterial[COLOR_NB];
int castleRights, rule50, pliesFromNull; int castleRights, rule50, pliesFromNull;
Score psqScore; Score psqScore;
Square epSquare; Square epSquare;
@ -62,7 +62,7 @@ struct StateInfo {
struct ReducedStateInfo { struct ReducedStateInfo {
Key pawnKey, materialKey; Key pawnKey, materialKey;
Value npMaterial[2]; Value npMaterial[COLOR_NB];
int castleRights, rule50, pliesFromNull; int castleRights, rule50, pliesFromNull;
Score psqScore; Score psqScore;
Square epSquare; Square epSquare;
@ -209,17 +209,17 @@ private:
Value compute_non_pawn_material(Color c) const; Value compute_non_pawn_material(Color c) const;
// Board and pieces // Board and pieces
Piece board[64]; // [square] Piece board[SQUARE_NB];
Bitboard byTypeBB[8]; // [pieceType] Bitboard byTypeBB[PIECE_TYPE_NB];
Bitboard byColorBB[2]; // [color] Bitboard byColorBB[COLOR_NB];
int pieceCount[2][8]; // [color][pieceType] int pieceCount[COLOR_NB][PIECE_TYPE_NB];
Square pieceList[2][8][16]; // [color][pieceType][index] Square pieceList[COLOR_NB][PIECE_TYPE_NB][16];
int index[64]; // [square] int index[SQUARE_NB];
// Other info // Other info
int castleRightsMask[64]; // [square] int castleRightsMask[SQUARE_NB];
Square castleRookSquare[2][2]; // [color][side] Square castleRookSquare[COLOR_NB][CASTLING_SIDE_NB];
Bitboard castlePath[2][2]; // [color][side] Bitboard castlePath[COLOR_NB][CASTLING_SIDE_NB];
StateInfo startState; StateInfo startState;
int64_t nodes; int64_t nodes;
int startPosPly; int startPosPly;

View file

@ -29,7 +29,7 @@
/// a given square a (midgame, endgame) score pair is assigned. PSQT is defined /// a given square a (midgame, endgame) score pair is assigned. PSQT is defined
/// for white side, for black side the tables are symmetric. /// for white side, for black side the tables are symmetric.
static const Score PSQT[][64] = { static const Score PSQT[][SQUARE_NB] = {
{ }, { },
{ // Pawn { // Pawn
S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0), S(0, 0), S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0), S(0, 0), S( 0, 0), S( 0, 0), S( 0, 0),

View file

@ -92,7 +92,7 @@ namespace {
int BestMoveChanges; int BestMoveChanges;
int SkillLevel; int SkillLevel;
bool SkillLevelEnabled, Chess960; bool SkillLevelEnabled, Chess960;
Value DrawValue[2]; Value DrawValue[COLOR_NB];
History H; History H;
template <NodeType NT> template <NodeType NT>

View file

@ -82,7 +82,7 @@ struct LimitsType {
LimitsType() { memset(this, 0, sizeof(LimitsType)); } LimitsType() { memset(this, 0, sizeof(LimitsType)); }
bool use_time_management() const { return !(movetime | depth | nodes | infinite); } bool use_time_management() const { return !(movetime | depth | nodes | infinite); }
int time[2], inc[2], movestogo, depth, nodes, movetime, infinite, ponder; int time[COLOR_NB], inc[COLOR_NB], movestogo, depth, nodes, movetime, infinite, ponder;
}; };

View file

@ -136,12 +136,14 @@ enum CastleRight { // Defined as in PolyGlot book hash key
WHITE_OOO = 2, WHITE_OOO = 2,
BLACK_OO = 4, BLACK_OO = 4,
BLACK_OOO = 8, BLACK_OOO = 8,
ALL_CASTLES = 15 ALL_CASTLES = 15,
CASTLE_RIGHT_NB = 16
}; };
enum CastlingSide { enum CastlingSide {
KING_SIDE, KING_SIDE,
QUEEN_SIDE QUEEN_SIDE,
CASTLING_SIDE_NB = 2
}; };
enum Phase { enum Phase {
@ -188,17 +190,19 @@ enum Value {
enum PieceType { enum PieceType {
NO_PIECE_TYPE = 0, ALL_PIECES = 0, NO_PIECE_TYPE = 0, ALL_PIECES = 0,
PAWN = 1, KNIGHT = 2, BISHOP = 3, ROOK = 4, QUEEN = 5, KING = 6 PAWN = 1, KNIGHT = 2, BISHOP = 3, ROOK = 4, QUEEN = 5, KING = 6,
PIECE_TYPE_NB = 8
}; };
enum Piece { enum Piece {
NO_PIECE = 16, // color_of(NO_PIECE) == NO_COLOR 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, 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 B_PAWN = 9, B_KNIGHT = 10, B_BISHOP = 11, B_ROOK = 12, B_QUEEN = 13, B_KING = 14,
PIECE_NB = 16
}; };
enum Color { enum Color {
WHITE, BLACK, NO_COLOR WHITE, BLACK, NO_COLOR, COLOR_NB = 2
}; };
enum Depth { enum Depth {
@ -224,6 +228,8 @@ enum Square {
SQ_A8, SQ_B8, SQ_C8, SQ_D8, SQ_E8, SQ_F8, SQ_G8, SQ_H8, SQ_A8, SQ_B8, SQ_C8, SQ_D8, SQ_E8, SQ_F8, SQ_G8, SQ_H8,
SQ_NONE, SQ_NONE,
SQUARE_NB = 64,
DELTA_N = 8, DELTA_N = 8,
DELTA_E = 1, DELTA_E = 1,
DELTA_S = -8, DELTA_S = -8,
@ -238,11 +244,11 @@ enum Square {
}; };
enum File { enum File {
FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H, FILE_NB = 8
}; };
enum Rank { enum Rank {
RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8 RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8, RANK_NB = 8
}; };
@ -329,9 +335,9 @@ inline Score apply_weight(Score v, Score w) {
namespace Zobrist { namespace Zobrist {
extern Key psq[2][8][64]; // [color][pieceType][square / piece count] extern Key psq[COLOR_NB][PIECE_TYPE_NB][SQUARE_NB];
extern Key enpassant[8]; // [file] extern Key enpassant[FILE_NB];
extern Key castle[16]; // [castleRight] extern Key castle[CASTLE_RIGHT_NB];
extern Key side; extern Key side;
extern Key exclusion; extern Key exclusion;
@ -340,9 +346,9 @@ namespace Zobrist {
CACHE_LINE_ALIGNMENT CACHE_LINE_ALIGNMENT
extern Score pieceSquareTable[16][64]; // [piece][square] extern Score pieceSquareTable[PIECE_NB][SQUARE_NB];
extern Value PieceValue[2][18]; // [Mg / Eg][piece / pieceType] extern Value PieceValue[2][18]; // [Mg / Eg][piece / pieceType]
extern int SquareDistance[64][64]; // [square][square] extern int SquareDistance[SQUARE_NB][SQUARE_NB];
struct MoveStack { struct MoveStack {
Move move; Move move;