Skip to content

Commit

Permalink
write half-point as ½
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Sep 22, 2024
1 parent a54cf53 commit 31beccc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions core/src/main/scala/Outcome.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ case class Outcome(winner: Option[Color]):
override def toString = winner match
case Some(White) => "1-0"
case Some(Black) => "0-1"
case None => "1/2-1/2"
case None => "½-½"

object Outcome:

Expand All @@ -28,6 +28,10 @@ object Outcome:
case Zero => 0f
case Half => 0.5f
case One => 1f
def show: String = p match
case Zero => "0"
case Half => "½"
case One => "1"

import Points.*
type GamePoints = ByColor[Points]
Expand All @@ -47,12 +51,8 @@ object Outcome:
case Outcome(None) => ByColor(Half, Half)

def showPoints(points: Option[GamePoints]): String =
points.fold("*"): ps =>
ps.mapList: p =>
if p == Zero then "0"
else if p == One then "1"
else "1/2"
.mkString("-")
points.fold("*"):
_.mapList(_.show).mkString("-")

def guessPointsFromStatusAndPosition(status: Status, positionWinner: Option[Color]): Option[GamePoints] =
import Status.*
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/format/pgn/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ object Parser:
val numberSuffix = (P.char('.') | whitespace).rep0.void

// 10. or 10... but not 0 or 1-0 or 1/2
val number = (positiveIntString <* !P.charIn('‑', '–', '-', '/') ~ numberSuffix).string
val number = (positiveIntString <* !P.charIn('‑', '–', '-', '/', '½') ~ numberSuffix).string

val forbidNullMove = P
.stringIn(List("--", "Z0", "null", "pass", "@@@@"))
Expand Down
6 changes: 3 additions & 3 deletions test-kit/src/test/scala/OutcomeTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class OutcomeTest extends ScalaCheckSuite:
assertEquals(normalize("1-0"), "1-0")
assertEquals(normalize("0-1"), "0-1")
assertEquals(normalize("—:—"), "0-0")
assertEquals(normalize("1/2_0"), "1/2-0")
assertEquals(normalize("0-½"), "0-1/2")
assertEquals(normalize("0.5-0"), "1/2-0")
assertEquals(normalize("1/2_0"), "½-0")
assertEquals(normalize("0-½"), "0-½")
assertEquals(normalize("0.5-0"), "½-0")
assertEquals(normalize("*"), "*")

0 comments on commit 31beccc

Please sign in to comment.