mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 16:53:09 +00:00
Fixed a bug in PV extraction from the transposition table: The
previous used move_is_legal to verify that the move from the TT was legal, and the old version of move_is_legal only works when the side to move is not in check. Fixed this by adding a separate, slower version of move_is_legal which works even when the side to move is in check.
This commit is contained in:
parent
2fff532f4e
commit
ae49677446
3 changed files with 25 additions and 1 deletions
|
@ -567,6 +567,29 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) {
|
|||
}
|
||||
|
||||
|
||||
/// Another version of move_is_legal(), which takes only a position and a move
|
||||
/// as input. This function does not require that the side to move is not in
|
||||
/// check. It is not optimized for speed, and is only used for verifying move
|
||||
/// legality when building a PV from the transposition table.
|
||||
|
||||
bool move_is_legal(const Position& pos, const Move m) {
|
||||
|
||||
Bitboard pinned = pos.pinned_pieces(pos.side_to_move());
|
||||
if (!pos.is_check())
|
||||
return move_is_legal(pos, m, pinned);
|
||||
else
|
||||
{
|
||||
Position p(pos);
|
||||
MoveStack moves[64];
|
||||
int n = generate_evasions(p, moves, pinned);
|
||||
for (int i = 0; i < n; i++)
|
||||
if (moves[i].move == m)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
template<PieceType Piece>
|
||||
|
|
|
@ -38,6 +38,7 @@ extern int generate_non_capture_checks(const Position& pos, MoveStack* mlist, Bi
|
|||
extern int generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pinned);
|
||||
extern int generate_legal_moves(const Position& pos, MoveStack* mlist);
|
||||
extern bool move_is_legal(const Position& pos, const Move m, Bitboard pinned);
|
||||
extern bool move_is_legal(const Position& pos, const Move m);
|
||||
|
||||
|
||||
#endif // !defined(MOVEGEN_H_INCLUDED)
|
||||
|
|
|
@ -207,7 +207,7 @@ void TranspositionTable::extract_pv(const Position& pos, Move pv[]) {
|
|||
tte && tte->move() != MOVE_NONE && !stop;
|
||||
tte = retrieve(p.get_key()), ply++)
|
||||
{
|
||||
if (!move_is_legal(p, tte->move(), p.pinned_pieces(p.side_to_move())))
|
||||
if (!move_is_legal(p, tte->move()))
|
||||
break;
|
||||
pv[ply] = tte->move();
|
||||
p.do_move(pv[ply], st[ply]);
|
||||
|
|
Loading…
Add table
Reference in a new issue