feat(game): add GET /{gameId}/fen-history endpoint
Build & Test (NowChessSystems) TeamCity build finished
Build & Test (NowChessSystems) TeamCity build finished
Returns a FEN string for every ply of the game (initial position + one per move) by replaying moves via ruleSet.applyMove and exporting each GameContext to FEN. Enables full per-move engine analysis from clients without requiring a chess library on their side. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
package de.nowchess.api.dto
|
||||||
|
|
||||||
|
final case class FenHistoryDto(fens: List[String])
|
||||||
@@ -339,6 +339,18 @@ class GameResource:
|
|||||||
log.infof("Imported PGN game %s", entry.gameId)
|
log.infof("Imported PGN game %s", entry.gameId)
|
||||||
created(GameDtoMapper.toGameFullDto(entry, ioClient))
|
created(GameDtoMapper.toGameFullDto(entry, ioClient))
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/{gameId}/fen-history")
|
||||||
|
@Produces(Array(MediaType.APPLICATION_JSON))
|
||||||
|
def getFenHistory(@PathParam("gameId") gameId: String): Response =
|
||||||
|
val entry = registry.get(gameId).getOrElse(throw GameNotFoundException(gameId))
|
||||||
|
val engine = entry.engine
|
||||||
|
val initial = engine.initialContext
|
||||||
|
val moves = engine.context.moves
|
||||||
|
val contexts = moves.scanLeft(initial)((ctx, move) => engine.ruleSet.applyMove(ctx)(move))
|
||||||
|
val fens = contexts.map(ctx => ioClient.exportFen(ctx))
|
||||||
|
ok(FenHistoryDto(fens))
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/{gameId}/export/fen")
|
@Path("/{gameId}/export/fen")
|
||||||
@Produces(Array(MediaType.TEXT_PLAIN))
|
@Produces(Array(MediaType.TEXT_PLAIN))
|
||||||
|
|||||||
Reference in New Issue
Block a user