Key Position::zobMaterial[2][8][16];
Key Position::zobSideToMove;
-Value Position::MgPieceSquareTable[16][64];
-Value Position::EgPieceSquareTable[16][64];
+Score Position::PieceSquareTable[16][64];
static bool RequestPending = false;
st->key = compute_key();
st->pawnKey = compute_pawn_key();
st->materialKey = compute_material_key();
- st->mgValue = compute_value<MidGame>();
- st->egValue = compute_value<EndGame>();
+ st->value = compute_value();
st->npMaterial[WHITE] = compute_non_pawn_material(WHITE);
st->npMaterial[BLACK] = compute_non_pawn_material(BLACK);
}
}
+/// Position::pl_move_is_evasion() tests whether a pseudo-legal move is a legal evasion
+
+bool Position::pl_move_is_evasion(Move m, Bitboard pinned) const
+{
+ assert(is_check());
+
+ Color us = side_to_move();
+ Square from = move_from(m);
+ Square to = move_to(m);
+
+ // King moves and en-passant captures are verified in pl_move_is_legal()
+ if (type_of_piece_on(from) == KING || move_is_ep(m))
+ return pl_move_is_legal(m, pinned);
+
+ Bitboard target = checkers();
+ Square checksq = pop_1st_bit(&target);
+
+ if (target) // double check ?
+ return false;
+
+ // Our move must be a blocking evasion or a capture of the checking piece
+ target = squares_between(checksq, king_square(us)) | checkers();
+ return bit_is_set(target, to) && pl_move_is_legal(m, pinned);
+}
+
+
/// Position::move_is_check() tests whether a pseudo-legal move is a check
bool Position::move_is_check(Move m) const {
Key key, pawnKey, materialKey;
int castleRights, rule50, pliesFromNull;
Square epSquare;
- Value mgValue, egValue;
+ Value value;
Value npMaterial[2];
};
}
// Update incremental scores
- st->mgValue += pst_delta<MidGame>(piece, from, to);
- st->egValue += pst_delta<EndGame>(piece, from, to);
+ st->value += pst_delta(piece, from, to);
if (pm) // promotion ?
{
st->pawnKey ^= zobrist[us][PAWN][to];
// Partially revert and update incremental scores
- st->mgValue -= pst<MidGame>(us, PAWN, to);
- st->mgValue += pst<MidGame>(us, promotion, to);
- st->egValue -= pst<EndGame>(us, PAWN, to);
- st->egValue += pst<EndGame>(us, promotion, to);
+ st->value -= pst(us, PAWN, to);
+ st->value += pst(us, promotion, to);
// Update material
st->npMaterial[us] += piece_value_midgame(promotion);
// Finish
sideToMove = opposite_color(sideToMove);
-
- st->mgValue += (sideToMove == WHITE)? TempoValueMidgame : -TempoValueMidgame;
- st->egValue += (sideToMove == WHITE)? TempoValueEndgame : -TempoValueEndgame;
+ st->value += (sideToMove == WHITE ? TempoValue : -TempoValue);
assert(is_ok());
}
key ^= zobrist[them][capture][capsq];
// Update incremental scores
- st->mgValue -= pst<MidGame>(them, capture, capsq);
- st->egValue -= pst<EndGame>(them, capture, capsq);
+ st->value -= pst(them, capture, capsq);
// If the captured piece was a pawn, update pawn hash key,
// otherwise update non-pawn material.
index[rto] = tmp;
// Update incremental scores
- st->mgValue += pst_delta<MidGame>(king, kfrom, kto);
- st->egValue += pst_delta<EndGame>(king, kfrom, kto);
- st->mgValue += pst_delta<MidGame>(rook, rfrom, rto);
- st->egValue += pst_delta<EndGame>(rook, rfrom, rto);
+ st->value += pst_delta(king, kfrom, kto);
+ st->value += pst_delta(rook, rfrom, rto);
// Update hash key
st->key ^= zobrist[us][KING][kfrom] ^ zobrist[us][KING][kto];
// Finish
sideToMove = opposite_color(sideToMove);
-
- st->mgValue += (sideToMove == WHITE)? TempoValueMidgame : -TempoValueMidgame;
- st->egValue += (sideToMove == WHITE)? TempoValueEndgame : -TempoValueEndgame;
+ st->value += (sideToMove == WHITE ? TempoValue : -TempoValue);
assert(is_ok());
}
// a backup storage not as a new state to be used.
backupSt.key = st->key;
backupSt.epSquare = st->epSquare;
- backupSt.mgValue = st->mgValue;
- backupSt.egValue = st->egValue;
+ backupSt.value = st->value;
backupSt.previous = st->previous;
backupSt.pliesFromNull = st->pliesFromNull;
st->previous = &backupSt;
st->epSquare = SQ_NONE;
st->rule50++;
st->pliesFromNull = 0;
+ st->value += (sideToMove == WHITE) ? TempoValue : -TempoValue;
gamePly++;
-
- st->mgValue += (sideToMove == WHITE)? TempoValueMidgame : -TempoValueMidgame;
- st->egValue += (sideToMove == WHITE)? TempoValueEndgame : -TempoValueEndgame;
}
StateInfo* backupSt = st->previous;
st->key = backupSt->key;
st->epSquare = backupSt->epSquare;
- st->mgValue = backupSt->mgValue;
- st->egValue = backupSt->egValue;
+ st->value = backupSt->value;
st->previous = backupSt->previous;
st->pliesFromNull = backupSt->pliesFromNull;
/// game and the endgame. These functions are used to initialize the incremental
/// scores when a new position is set up, and to verify that the scores are correctly
/// updated by do_move and undo_move when the program is running in debug mode.
-template<Position::GamePhase Phase>
-Value Position::compute_value() const {
+Score Position::compute_value() const {
- Value result = Value(0);
+ Score result = make_score(0, 0);
Bitboard b;
Square s;
{
s = pop_1st_bit(&b);
assert(piece_on(s) == piece_of_color_and_type(c, pt));
- result += pst<Phase>(c, pt, s);
+ result += pst(c, pt, s);
}
}
- const Value TempoValue = (Phase == MidGame ? TempoValueMidgame : TempoValueEndgame);
- result += (side_to_move() == WHITE)? TempoValue / 2 : -TempoValue / 2;
+ result += (side_to_move() == WHITE ? TempoValue / 2 : -TempoValue / 2);
return result;
}
for (Piece p = WP; p <= WK; p++)
{
i = (r == 0)? 0 : (genrand_int32() % (r*2) - r);
- MgPieceSquareTable[p][s] = Value(MgPST[p][s] + i);
- EgPieceSquareTable[p][s] = Value(EgPST[p][s] + i);
+ PieceSquareTable[p][s] = make_score(MgPST[p][s] + i, EgPST[p][s] + i);
}
for (Square s = SQ_A1; s <= SQ_H8; s++)
for (Piece p = BP; p <= BK; p++)
- {
- MgPieceSquareTable[p][s] = -MgPieceSquareTable[p-8][flip_square(s)];
- EgPieceSquareTable[p][s] = -EgPieceSquareTable[p-8][flip_square(s)];
- }
+ PieceSquareTable[p][s] = -PieceSquareTable[p-8][flip_square(s)];
}
st->materialKey = compute_material_key();
// Incremental scores
- st->mgValue = compute_value<MidGame>();
- st->egValue = compute_value<EndGame>();
+ st->value = compute_value();
// Material
st->npMaterial[WHITE] = compute_non_pawn_material(WHITE);
// Incremental eval OK?
if (failedStep) (*failedStep)++;
- if (debugIncrementalEval)
- {
- if (st->mgValue != compute_value<MidGame>())
- return false;
-
- if (st->egValue != compute_value<EndGame>())
- return false;
- }
+ if (debugIncrementalEval && st->value != compute_value())
+ return false;
// Non-pawn material OK?
if (failedStep) (*failedStep)++;