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 *"