using std::cout;
using std::endl;
-// To convert a Piece to and from a FEN char
static const string PieceToChar(" PNBRQK pnbrqk");
-// Material values arrays, indexed by Piece
-const Value PieceValueMidgame[17] = {
- VALUE_ZERO,
- PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
- RookValueMidgame, QueenValueMidgame,
- VALUE_ZERO, VALUE_ZERO, VALUE_ZERO,
- PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
- RookValueMidgame, QueenValueMidgame
-};
-
-const Value PieceValueEndgame[17] = {
- VALUE_ZERO,
- PawnValueEndgame, KnightValueEndgame, BishopValueEndgame,
- RookValueEndgame, QueenValueEndgame,
- VALUE_ZERO, VALUE_ZERO, VALUE_ZERO,
- PawnValueEndgame, KnightValueEndgame, BishopValueEndgame,
- RookValueEndgame, QueenValueEndgame
-};
-
CACHE_LINE_ALIGNMENT
-Score pieceSquareTable[16][64];
+Score pieceSquareTable[16][64]; // [piece][square]
+Value PieceValue[2][18] = { // [Mg / Eg][piece / pieceType]
+{ VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg },
+{ VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg } };
namespace Zobrist {
-Key psq[2][8][64]; // [color][pieceType][square]/[piece count]
+Key psq[2][8][64]; // [color][pieceType][square / piece count]
Key enpassant[8]; // [file]
Key castle[16]; // [castleRight]
Key side;
for (PieceType pt = PAWN; pt <= KING; pt++)
{
- Score v = make_score(PieceValueMidgame[pt], PieceValueEndgame[pt]);
+ PieceValue[Mg][make_piece(BLACK, pt)] = PieceValue[Mg][pt];
+ PieceValue[Eg][make_piece(BLACK, pt)] = PieceValue[Eg][pt];
+
+ Score v = make_score(PieceValue[Mg][pt], PieceValue[Eg][pt]);
for (Square s = SQ_A1; s <= SQ_H8; s++)
{
st->pawnKey ^= Zobrist::psq[them][PAWN][capsq];
}
else
- st->npMaterial[them] -= PieceValueMidgame[capture];
+ st->npMaterial[them] -= PieceValue[Mg][capture];
// Remove the captured piece
byTypeBB[ALL_PIECES] ^= capsq;
- pieceSquareTable[make_piece(us, PAWN)][to];
// Update material
- st->npMaterial[us] += PieceValueMidgame[promotion];
+ st->npMaterial[us] += PieceValue[Mg][promotion];
}
// Update pawn hash key
// Early return if SEE cannot be negative because captured piece value
// is not less then capturing one. Note that king moves always return
// here because king midgame value is set to 0.
- if (PieceValueMidgame[piece_on(to_sq(m))] >= PieceValueMidgame[piece_moved(m)])
+ if (PieceValue[Mg][piece_on(to_sq(m))] >= PieceValue[Mg][piece_moved(m)])
return 1;
return see(m);
stm = ~color_of(piece_on(from));
stmAttackers = attackers & pieces(stm);
if (!stmAttackers)
- return PieceValueMidgame[capturedType];
+ return PieceValue[Mg][capturedType];
// The destination square is defended, which makes things rather more
// difficult to compute. We proceed by building up a "swap list" containing
// destination square, where the sides alternately capture, and always
// capture with the least valuable piece. After each capture, we look for
// new X-ray attacks from behind the capturing piece.
- swapList[0] = PieceValueMidgame[capturedType];
+ swapList[0] = PieceValue[Mg][capturedType];
capturedType = type_of(piece_on(from));
do {
// Locate the least valuable attacker for the side to move. The loop
// below looks like it is potentially infinite, but it isn't. We know
// that the side to move still has at least one attacker left.
- for (pt = PAWN; !(stmAttackers & pieces(pt)); pt++)
+ for (pt = PAWN; (b = stmAttackers & pieces(pt)) == 0; pt++)
assert(pt < KING);
// Remove the attacker we just found from the 'occupied' bitboard,
// and scan for new X-ray attacks behind the attacker.
- b = stmAttackers & pieces(pt);
occ ^= (b & (~b + 1));
attackers |= (attacks_bb<ROOK>(to, occ) & pieces(ROOK, QUEEN))
| (attacks_bb<BISHOP>(to, occ) & pieces(BISHOP, QUEEN));
// Add the new entry to the swap list
assert(slIndex < 32);
- swapList[slIndex] = -swapList[slIndex - 1] + PieceValueMidgame[capturedType];
+ swapList[slIndex] = -swapList[slIndex - 1] + PieceValue[Mg][capturedType];
slIndex++;
// Remember the value of the capturing piece, and change the side to
if (capturedType == KING && stmAttackers)
{
assert(slIndex < 32);
- swapList[slIndex++] = QueenValueMidgame*10;
+ swapList[slIndex++] = QueenValueMg * 16;
break;
}
} while (stmAttackers);
Value value = VALUE_ZERO;
for (PieceType pt = KNIGHT; pt <= QUEEN; pt++)
- value += piece_count(c, pt) * PieceValueMidgame[pt];
+ value += piece_count(c, pt) * PieceValue[Mg][pt];
return value;
}
// Draw by material?
if ( !pieces(PAWN)
- && (non_pawn_material(WHITE) + non_pawn_material(BLACK) <= BishopValueMidgame))
+ && (non_pawn_material(WHITE) + non_pawn_material(BLACK) <= BishopValueMg))
return true;
// Draw by the 50 moves rule?