Fix flip command for FENs with pockets (#930)
authorFabian Fichter <ianfab@users.noreply.github.com>
Sun, 9 Nov 2025 21:38:13 +0000 (22:38 +0100)
committerGitHub <noreply@github.com>
Sun, 9 Nov 2025 21:38:13 +0000 (22:38 +0100)
Closes #924.

src/position.cpp

index 609441d..f2b82a9 100644 (file)
@@ -3232,8 +3232,16 @@ void Position::flip() {
   for (Rank r = max_rank(); r >= RANK_1; --r) // Piece placement
   {
       std::getline(ss, token, r > RANK_1 ? '/' : ' ');
-      f.insert(0, token + (f.empty() ? " " : "/"));
+      size_t bracketPos = token.find('[');
+      if (bracketPos != string::npos)
+      {
+          f.insert(0, token.substr(0, bracketPos) + (f.empty() ? "" : "/"));
+          f += token.substr(bracketPos);
+      }
+      else
+          f.insert(0, token + (f.empty() ? "" : "/"));
   }
+  f += " ";
 
   ss >> token; // Active color
   f += (token == "w" ? "B " : "W "); // Will be lowercased later