mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 19:49:14 +00:00
Simplify move_to_san()
Nicely simplify disambiguation code. No functional change.
This commit is contained in:
parent
e5bc79fb9c
commit
3f44be9baa
1 changed files with 11 additions and 20 deletions
|
@ -110,8 +110,7 @@ const string move_to_san(Position& pos, Move m) {
|
|||
|
||||
assert(MoveList<LEGAL>(pos).contains(m));
|
||||
|
||||
Bitboard attackers;
|
||||
bool ambiguousMove, ambiguousFile, ambiguousRank;
|
||||
Bitboard others, b;
|
||||
string san;
|
||||
Color us = pos.side_to_move();
|
||||
Square from = from_sq(m);
|
||||
|
@ -127,31 +126,23 @@ const string move_to_san(Position& pos, Move m) {
|
|||
{
|
||||
san = PieceToChar[WHITE][pt]; // Upper case
|
||||
|
||||
// Disambiguation if we have more then one piece with destination 'to'
|
||||
// note that for pawns is not needed because starting file is explicit.
|
||||
ambiguousMove = ambiguousFile = ambiguousRank = false;
|
||||
// Disambiguation if we have more then one piece of type 'pt' that can
|
||||
// reach 'to' with a legal move.
|
||||
others = b = (pos.attacks_from(pc, to) & pos.pieces(us, pt)) ^ from;
|
||||
|
||||
attackers = (pos.attacks_from(pc, to) & pos.pieces(us, pt)) ^ from;
|
||||
|
||||
while (attackers)
|
||||
while (b)
|
||||
{
|
||||
Square sq = pop_lsb(&attackers);
|
||||
|
||||
// If the move is illegal, the piece is not included in the sub-set
|
||||
if (!pos.pl_move_is_legal(make_move(sq, to), pos.pinned_pieces()))
|
||||
continue;
|
||||
|
||||
ambiguousFile |= file_of(sq) == file_of(from);
|
||||
ambiguousRank |= rank_of(sq) == rank_of(from);
|
||||
ambiguousMove = true;
|
||||
Move move = make_move(pop_lsb(&b), to);
|
||||
if (!pos.pl_move_is_legal(move, pos.pinned_pieces()))
|
||||
others ^= from_sq(move);
|
||||
}
|
||||
|
||||
if (ambiguousMove)
|
||||
if (others)
|
||||
{
|
||||
if (!ambiguousFile)
|
||||
if (!(others & file_bb(from)))
|
||||
san += file_to_char(file_of(from));
|
||||
|
||||
else if (!ambiguousRank)
|
||||
else if (!(others & rank_bb(from)))
|
||||
san += rank_to_char(rank_of(from));
|
||||
|
||||
else
|
||||
|
|
Loading…
Add table
Reference in a new issue