mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Fix SAN disambiguation bug
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
70125a3be0
commit
462a39ec49
1 changed files with 13 additions and 8 deletions
15
src/move.cpp
15
src/move.cpp
|
@ -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,16 +130,19 @@ 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)
|
||||
if (cnt > 1)
|
||||
{
|
||||
if (f == 1)
|
||||
san += file_to_char(square_file(from));
|
||||
else if (f > 1 && r == 1)
|
||||
else if (r == 1)
|
||||
san += rank_to_char(square_rank(from));
|
||||
else if (f > 1 && r > 1)
|
||||
else
|
||||
san += square_to_string(from);
|
||||
}
|
||||
}
|
||||
|
||||
if (pos.move_is_capture(m))
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue