mirror of
https://github.com/sockspls/badfish
synced 2025-07-12 03:59:15 +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));
|
assert(MoveList<LEGAL>(pos).contains(m));
|
||||||
|
|
||||||
Bitboard attackers;
|
Bitboard others, b;
|
||||||
bool ambiguousMove, ambiguousFile, ambiguousRank;
|
|
||||||
string san;
|
string san;
|
||||||
Color us = pos.side_to_move();
|
Color us = pos.side_to_move();
|
||||||
Square from = from_sq(m);
|
Square from = from_sq(m);
|
||||||
|
@ -127,31 +126,23 @@ const string move_to_san(Position& pos, Move m) {
|
||||||
{
|
{
|
||||||
san = PieceToChar[WHITE][pt]; // Upper case
|
san = PieceToChar[WHITE][pt]; // Upper case
|
||||||
|
|
||||||
// Disambiguation if we have more then one piece with destination 'to'
|
// Disambiguation if we have more then one piece of type 'pt' that can
|
||||||
// note that for pawns is not needed because starting file is explicit.
|
// reach 'to' with a legal move.
|
||||||
ambiguousMove = ambiguousFile = ambiguousRank = false;
|
others = b = (pos.attacks_from(pc, to) & pos.pieces(us, pt)) ^ from;
|
||||||
|
|
||||||
attackers = (pos.attacks_from(pc, to) & pos.pieces(us, pt)) ^ from;
|
while (b)
|
||||||
|
|
||||||
while (attackers)
|
|
||||||
{
|
{
|
||||||
Square sq = pop_lsb(&attackers);
|
Move move = make_move(pop_lsb(&b), to);
|
||||||
|
if (!pos.pl_move_is_legal(move, pos.pinned_pieces()))
|
||||||
// If the move is illegal, the piece is not included in the sub-set
|
others ^= from_sq(move);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ambiguousMove)
|
if (others)
|
||||||
{
|
{
|
||||||
if (!ambiguousFile)
|
if (!(others & file_bb(from)))
|
||||||
san += file_to_char(file_of(from));
|
san += file_to_char(file_of(from));
|
||||||
|
|
||||||
else if (!ambiguousRank)
|
else if (!(others & rank_bb(from)))
|
||||||
san += rank_to_char(rank_of(from));
|
san += rank_to_char(rank_of(from));
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue