Skip to content

Commit

Permalink
Merge pull request #220 from Mind-Sports-Games/pla-1159-fix-loading-o…
Browse files Browse the repository at this point in the history
…f-analysis-pages-for-multipoint-backgammon

Fix UciCharPair, Binary read and SGF for CubeActions
  • Loading branch information
JamesHeppell authored Feb 13, 2025
2 parents 5faf40d + 6b9780c commit b88914d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name := "strategygames"

organization := "org.playstrategy"

version := "10.2.1-pstrat171"
version := "10.2.1-pstrat173"

scalaVersion := "2.13.10"

Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/backgammon/CubeAction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,28 @@ case class CubeAction(
sealed trait CubeInteraction {
val index: Int
val name: String
val sgf: String
val char: Char
}

case object OfferDouble extends CubeInteraction {
val index = 0
val name = "offer"
val sgf = "double"
val char = 'o'
}

case object AcceptDouble extends CubeInteraction {
val index = 1
val name = "accept"
val sgf = "take"
val char = 'y'
}

case object RejectDouble extends CubeInteraction {
val index = 2
val name = "reject"
val sgf = "drop"
val char = 'n'
}

Expand Down
11 changes: 6 additions & 5 deletions src/main/scala/backgammon/format/Sgf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ object Sgf {
actionStrs.map { turnActions =>
turnActions
.flatMap(Uci.apply(_).flatMap {
case uci: Uci.Drop => Some("y" + uci.pos.sgf)
case uci: Uci.Move => Some(uci.orig.sgf + uci.dest.sgf)
case uci: Uci.Lift => Some(uci.pos.sgf + "z")
case uci: Uci.DiceRoll => Some(uci.dice.take(2).sorted.reverse.mkString(""))
case _ => None
case uci: Uci.Drop => Some("y" + uci.pos.sgf)
case uci: Uci.Move => Some(uci.orig.sgf + uci.dest.sgf)
case uci: Uci.Lift => Some(uci.pos.sgf + "z")
case uci: Uci.DiceRoll => Some(uci.dice.take(2).sorted.reverse.mkString(""))
case uci: Uci.CubeAction => Some(uci.interaction.sgf)
case _ => None
})
.toList
.mkString("")
Expand Down
10 changes: 7 additions & 3 deletions src/main/scala/backgammon/format/UciCharPair.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ object UciCharPair {
dice2char(dice(0)),
dice2char(dice(1))
)
case Uci.Undo() => stratUciCharPair(toChar(Pos.C1), toChar(Pos.C1))
case Uci.DoRoll() => stratUciCharPair(toChar(Pos.B1), toChar(Pos.B1))
case Uci.EndTurn() => stratUciCharPair(toChar(Pos.A1), toChar(Pos.A1))
case Uci.Undo() => uciCharToCharPair(toChar(Pos.C1))
case Uci.DoRoll() => uciCharToCharPair(toChar(Pos.B1))
case Uci.EndTurn() => uciCharToCharPair(toChar(Pos.A1))
// OfferDouble => L1, AcceptDouble => K1, RejectDouble => J1
case Uci.CubeAction(ci) => uciCharToCharPair(toChar(Pos(ci.index).getOrElse(Pos.D1)))
case _ => sys.error(s"Not implemented UciCharPair for $uci")
}

private def uciCharToCharPair(c: Char) = stratUciCharPair(c, c)

private[format] object implementation {

val charShift = 35 // Start at Char(35) == '#'
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/backgammon/format/pgn/Binary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ object Binary {
plies
.map { ply =>
ply match {
case Uci.EndTurn.endTurnR() | Uci.CubeAction.cubeActionR() => s"${ply}#"
case _ => s"${ply},"
case Uci.EndTurn.endTurnR() | Uci.CubeAction.cubeActionR(_) => s"${ply}#"
case _ => s"${ply},"
}
}
.mkString
Expand Down

0 comments on commit b88914d

Please sign in to comment.