1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-07-11 19:49:14 +00:00

Better castle move detector in move_to_san()

Merged from iPhone Glaurung.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2009-03-22 14:32:00 +01:00
parent b82c3021fa
commit 66d165921d

View file

@ -70,23 +70,28 @@ const std::string move_to_san(const Position& pos, Move m) {
assert(pos.is_ok()); assert(pos.is_ok());
assert(move_is_ok(m)); assert(move_is_ok(m));
Square from, to;
PieceType pt;
from = move_from(m);
to = move_to(m);
pt = type_of_piece(pos.piece_on(move_from(m)));
std::string san = ""; std::string san = "";
if (m == MOVE_NONE) if (m == MOVE_NONE)
return "(none)"; return "(none)";
else if (m == MOVE_NULL) else if (m == MOVE_NULL)
return "(null)"; return "(null)";
else if (move_is_long_castle(m)) else if (move_is_long_castle(m) || (int(to - from) == -2 && pt == KING))
san = "O-O-O"; san = "O-O-O";
else if (move_is_short_castle(m)) else if (move_is_short_castle(m) || (int(to - from) == 2 && pt == KING))
san = "O-O"; san = "O-O";
else else
{ {
Piece pc = pos.piece_on(move_from(m)); if (pt != PAWN)
if (type_of_piece(pc) != PAWN)
{ {
san += piece_type_to_char(type_of_piece(pc), true); san += piece_type_to_char(pt, true);
Square from = move_from(m);
switch (move_ambiguity(pos, m)) { switch (move_ambiguity(pos, m)) {
case AMBIGUITY_NONE: case AMBIGUITY_NONE:
break; break;
@ -105,7 +110,7 @@ const std::string move_to_san(const Position& pos, Move m) {
} }
if (pos.move_is_capture(m)) if (pos.move_is_capture(m))
{ {
if (type_of_piece(pc) == PAWN) if (pt == PAWN)
san += file_to_char(square_file(move_from(m))); san += file_to_char(square_file(move_from(m)));
san += "x"; san += "x";
} }