Skip to content

Commit

Permalink
Outcome code golf
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Dec 28, 2023
1 parent 5a39238 commit cfcfc01
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/scala/Outcome.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ object Outcome:
def fromResult(result: String): Option[Outcome] =
normalizationMap.get(result)

val white = Outcome(Some(White))
val black = Outcome(Some(Black))
val draw = Outcome(None)

lazy val knownResultStrings = "*" :: normalizationMap.keys.toList

private val normalizationMap: Map[String, Outcome] =
Expand Down Expand Up @@ -40,14 +44,14 @@ object Outcome:
loss <- losses
yield s"$loss$separator$win"

val pairs = allDraws.map(_ -> Outcome(None)) :::
allWins.map(_ -> Outcome(Some(White))) :::
allLosses.map(_ -> Outcome(Some(Black)))
val pairs = allDraws.map(_ -> draw) :::
allWins.map(_ -> white) :::
allLosses.map(_ -> black)

val lccResults = Map(
"WHITEWIN" -> Outcome(Some(White)),
"BLACKWIN" -> Outcome(Some(Black)),
"DRAW" -> Outcome(None) // ? not sure
"WHITEWIN" -> white,
"BLACKWIN" -> black,
"DRAW" -> draw // ? not sure
)

pairs.toMap ++ lccResults

0 comments on commit cfcfc01

Please sign in to comment.