From 396940da439a20e49b8cd3d6da8c6f1e7241a594 Mon Sep 17 00:00:00 2001 From: LQ63 Date: Tue, 31 Mar 2026 23:13:10 +0200 Subject: [PATCH] feat: NCS-11 derive PGN termination marker from Result header Co-Authored-By: Claude Sonnet 4.6 --- .../de/nowchess/chess/notation/PgnExporter.scala | 3 ++- .../de/nowchess/chess/notation/PgnExporterTest.scala | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/scala/de/nowchess/chess/notation/PgnExporter.scala b/modules/core/src/main/scala/de/nowchess/chess/notation/PgnExporter.scala index a7f6449..38a3733 100644 --- a/modules/core/src/main/scala/de/nowchess/chess/notation/PgnExporter.scala +++ b/modules/core/src/main/scala/de/nowchess/chess/notation/PgnExporter.scala @@ -22,7 +22,8 @@ object PgnExporter: if blackMoveStr.isEmpty then s"$moveNum. $whiteMoveStr" else s"$moveNum. $whiteMoveStr $blackMoveStr" - moveLines.mkString(" ") + " *" + val termination = headers.getOrElse("Result", "*") + moveLines.mkString(" ") + s" $termination" if headerLines.isEmpty then moveText else if moveText.isEmpty then headerLines diff --git a/modules/core/src/test/scala/de/nowchess/chess/notation/PgnExporterTest.scala b/modules/core/src/test/scala/de/nowchess/chess/notation/PgnExporterTest.scala index 6c39aa6..931ffc9 100644 --- a/modules/core/src/test/scala/de/nowchess/chess/notation/PgnExporterTest.scala +++ b/modules/core/src/test/scala/de/nowchess/chess/notation/PgnExporterTest.scala @@ -100,3 +100,15 @@ class PgnExporterTest extends AnyFunSuite with Matchers: pgn should include ("e2e4") pgn should not include ("=") } + + test("exportGame uses Result header as termination marker"): + val history = GameHistory() + .addMove(HistoryMove(Square(File.E, Rank.R2), Square(File.E, Rank.R4), None)) + val pgn = PgnExporter.exportGame(Map("Result" -> "1/2-1/2"), history) + pgn should endWith("1/2-1/2") + + test("exportGame with no Result header still uses * as default"): + val history = GameHistory() + .addMove(HistoryMove(Square(File.E, Rank.R2), Square(File.E, Rank.R4), None)) + val pgn = PgnExporter.exportGame(Map.empty, history) + pgn shouldBe "1. e2e4 *"