mirror of
https://github.com/official-stockfish/Stockfish.git
synced 2026-07-23 21:27:14 +00:00
Strict FEN parsing. Exit on setting invalid position via UCI.
fixes #6663, #6664, and a million others issues raised over the years. This is similar to https://github.com/official-stockfish/Stockfish/pull/4563/changes but more conservative and errors are split between "Unsupported position" and "Invalid FEN". The FEN parser needs to be strict as a foundation for safety. It does not specify much of the semantics, so this step is fairly simple. Parts after the ep square are optional, however, since it's common, for example in EPD notation. Errors arising from positional semantics that were previously bucketed under invalid FENs are now reported as "Unsupported position". Only positions that are potentially problematic are designated as unsupported. It is NOT guided by illegality of the position, but instead by the ability of the engine to handle them correctly. This means that some checks from the previous PR were removed. std::exit is used instead of std::terminate so atexit handles will be called. Probably wise to run copilot on this or smth because I scribbled it without much thought. With these small changes and reduced, less controversial, scope I hope this PR will finally make it and we will be done with these weekly issues. I'll wait with putting it on fishtest until there's approval. closes https://github.com/official-stockfish/Stockfish/pull/6665 No functional change
This commit is contained in:
committed by
Disservin
parent
415f2ef11c
commit
e38f5b2f53
+9
-4
@@ -195,21 +195,26 @@ void Engine::set_on_verify_networks(std::function<void(std::string_view)>&& f) {
|
||||
|
||||
void Engine::wait_for_search_finished() { threads.main_thread()->wait_for_search_finished(); }
|
||||
|
||||
void Engine::set_position(const std::string& fen, const std::vector<std::string>& moves) {
|
||||
std::optional<PositionSetError> Engine::set_position(const std::string& fen,
|
||||
const std::vector<std::string>& moves) {
|
||||
// Drop the old state and create a new one
|
||||
states = StateListPtr(new std::deque<StateInfo>(1));
|
||||
pos.set(fen, options["UCI_Chess960"], &states->back());
|
||||
states = StateListPtr(new std::deque<StateInfo>(1));
|
||||
auto err = pos.set(fen, options["UCI_Chess960"], &states->back());
|
||||
if (err.has_value())
|
||||
return err;
|
||||
|
||||
for (const auto& move : moves)
|
||||
{
|
||||
auto m = UCIEngine::to_move(pos, move);
|
||||
|
||||
if (m == Move::none())
|
||||
break;
|
||||
return PositionSetError("Illegal move: " + move);
|
||||
|
||||
states->emplace_back();
|
||||
pos.do_move(m, states->back());
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// modifiers
|
||||
|
||||
Reference in New Issue
Block a user