Skip to content

Commit

Permalink
Remove head.option
Browse files Browse the repository at this point in the history
  • Loading branch information
lenguyenthanh committed Oct 10, 2023
1 parent 1e9d9d6 commit 37c7630
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/main/scala/Replay.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,17 @@ object Replay:
val init = makeGame(variant, initialFen.some)
val emptyGames = List.empty[(Game, Uci.WithSan)]
sans
.foldM(emptyGames):
case (games, str) =>
.foldM((init, emptyGames)):
case ((head, games), str) =>
Parser
.sanOnly(str)
.flatMap: san =>
val game = games.headOption.fold(init)(_._1)
san(game.situation)
.map(m => (m.applyGame(game), Uci.WithSan(m.toUci, str)) :: games)
san(head.situation)
.map: move =>
val newGame = move.applyGame(head)
(newGame, (newGame, Uci.WithSan(move.toUci, str)) :: games)
.leftMap(err => (init, games.reverse, err.some))
.map(gs => (init, gs.reverse, none))
.map(gs => (init, gs._2.reverse, none))
.merge

private def computeSituations[M](
Expand Down

0 comments on commit 37c7630

Please sign in to comment.