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

Fix SAN disambiguation bug

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2011-05-29 10:47:13 +01:00
parent 70125a3be0
commit 462a39ec49

View file

@ -115,12 +115,14 @@ const string move_to_san(Position& pos, Move m) {
// Collect all legal moves of piece type 'pt' with destination 'to'
MoveStack* last = generate<MV_LEGAL>(pos, mlist);
int f = 0, r = 0;
int f = 0, r = 0, cnt = 0;
for (MoveStack* cur = mlist; cur != last; cur++)
if ( move_to(cur->move) == to
&& pos.type_of_piece_on(move_from(cur->move)) == pt)
{
cnt++;
if (square_file(move_from(cur->move)) == square_file(from))
f++;
@ -128,15 +130,18 @@ const string move_to_san(Position& pos, Move m) {
r++;
}
assert(f > 0 && r > 0);
assert(cnt > 0 && f > 0 && r > 0);
// Disambiguation if we have more then one piece with destination 'to'
if (f == 1 && r > 1)
san += file_to_char(square_file(from));
else if (f > 1 && r == 1)
san += rank_to_char(square_rank(from));
else if (f > 1 && r > 1)
san += square_to_string(from);
if (cnt > 1)
{
if (f == 1)
san += file_to_char(square_file(from));
else if (r == 1)
san += rank_to_char(square_rank(from));
else
san += square_to_string(from);
}
}
if (pos.move_is_capture(m))