ss >> std::noskipws;
- Square sq = SQ_A1 + max_rank() * NORTH;
+ Rank r = max_rank();
+ Square sq = SQ_A1 + r * NORTH;
// 1. Piece placement
while ((ss >> token) && !isspace(token))
else if (token == '/')
{
- sq += 2 * SOUTH + (FILE_MAX - max_file()) * EAST;
+ sq = SQ_A1 + --r * NORTH;
if (!is_ok(sq))
break;
}
+ // Stop before pieces in hand
+ else if (token == '[')
+ break;
+
+ // Ignore pieces outside the board and wait for next / or [ to return to a valid state
+ else if (!is_ok(sq) || file_of(sq) > max_file() || rank_of(sq) > r)
+ continue;
+
// Wall square
else if (token == '*')
{
put_piece(make_piece(color_of(Piece(idx)), promoted_piece_type(type_of(Piece(idx)))), sq, true, Piece(idx));
++sq;
}
-
- // Stop before pieces in hand
- else if (token == '[')
- break;
}
// Pieces in hand
if (!isspace(token))