Skip to content

Commit

Permalink
prevent negative relay clocks
Browse files Browse the repository at this point in the history
when using %emt a lot because there are few %clk,
the lack of increment causes the clock to deviate

we still don't know what the actual clock value is
  • Loading branch information
ornicar committed Dec 28, 2024
1 parent 9f7dd5e commit 73d62bc
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions modules/study/src/main/StudyPgnImport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ object StudyPgnImport:
(shapes ++ s),
c.orElse(clock),
e.orElse(emt),
(str.trim match
str.trim match
case "" => comments
case com =>
comments + Comment(Comment.Id.make, Comment.Text(com), annotator | Comment.Author.Lichess)
)
)
}

Expand All @@ -129,27 +128,27 @@ object StudyPgnImport:
.fold(
_ => none, // illegal move; stop here.
moveOrDrop =>
val game = moveOrDrop.applyGame(context.currentGame)
val uci = moveOrDrop.toUci
val sanStr = moveOrDrop.toSanStr
parseComments(node.value.metas.comments, annotator) match
case (shapes, clock, emt, comments) =>
val computedClock = clock.orElse((context.previousClock, emt).mapN(_ - _))
Branch(
id = UciCharPair(uci),
ply = game.ply,
move = Uci.WithSan(uci, sanStr),
fen = Fen.write(game),
check = game.situation.check,
shapes = shapes,
comments = comments,
glyphs = node.value.metas.glyphs,
clock = computedClock,
crazyData = game.situation.board.crazyData,
children = node.child.fold(Branches.empty)(
makeBranches(Context(game, computedClock, context.currentClock), _, annotator)
)
).some
val game = moveOrDrop.applyGame(context.currentGame)
val uci = moveOrDrop.toUci
val sanStr = moveOrDrop.toSanStr
val (shapes, clock, emt, comments) = parseComments(node.value.metas.comments, annotator)
val computedClock = clock
.orElse((context.previousClock, emt).mapN(_ - _))
.filter(_ > Centis(0))
Branch(
id = UciCharPair(uci),
ply = game.ply,
move = Uci.WithSan(uci, sanStr),
fen = Fen.write(game),
check = game.situation.check,
shapes = shapes,
comments = comments,
glyphs = node.value.metas.glyphs,
clock = computedClock,
crazyData = game.situation.board.crazyData,
children = node.child.fold(Branches.empty):
makeBranches(Context(game, computedClock, context.currentClock), _, annotator)
).some
)
catch
case _: StackOverflowError =>
Expand Down

0 comments on commit 73d62bc

Please sign in to comment.