Skip to content

Commit

Permalink
Merge pull request #224 from Mind-Sports-Games/pla-1178-fix-sgf-impor…
Browse files Browse the repository at this point in the history
…t-for-backgammon

update tag model for sgf backgammon
  • Loading branch information
JamesHeppell authored Feb 26, 2025
2 parents 5172b6e + 234d30e commit 5f2d7a1
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 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-pstrat174"
version := "10.2.1-pstrat175"

scalaVersion := "2.13.10"

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/backgammon/Pos.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ case class Pos private (index: Int) extends AnyVal {
def piotr: Char = Piotr.lookup.get(index).getOrElse('?')
def piotrStr = piotr.toString

def sgf = (97 + (23 - index)).toChar.toString()
def sgf = (97 + index).toChar.toString()

def last: Boolean = (index + 1) % File.all.size == 0

Expand Down
7 changes: 5 additions & 2 deletions src/main/scala/format/sgf/tagModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ object Tags {

val importantTagRoster = List(
Tag.FF,
Tag.CA,
Tag.GM,
Tag.CA,
Tag.AP,
Tag.DT,
Tag.EV,
Tag.TM,
Expand All @@ -59,6 +60,7 @@ object Tag {
case object FF extends TagType // File Format
case object CA extends TagType // Character
case object GN extends TagType // Game Name
case object AP extends TagType // Application
case object DT extends TagType { // Date time
val format = DateTimeFormat forPattern "yyyy.MM.dd" withZone DateTimeZone.UTC
}
Expand Down Expand Up @@ -94,8 +96,9 @@ object Tag {

val tagTypes = List(
FF,
CA,
GN,
CA,
AP,
DT,
PC,
EV,
Expand Down
10 changes: 5 additions & 5 deletions src/test/scala/format/sgf/DumperTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,23 @@ class DumperTest extends Specification with ValidatedMatchers {
// https://www.red-bean.com/sgf/backgammon.html
"Backgammon drop=> s@l1 actionStrsToOutput" should {
"have an sgf output" in {
val output = ";W[ya]"
val output = ";W[yx]"
val actionStrs: ActionStrs = Vector(Vector("s@l2"))
Dumper.apply(Backgammon, actionStrs) must_== output
}
}

"Backgammon lift=> ^h1 actionStrsToOutput" should {
"have an sgf output" in {
val output = ";W[tz]"
val output = ";W[ez]"
val actionStrs: ActionStrs = Vector(Vector("^h1"))
Dumper.apply(Backgammon, actionStrs) must_== output
}
}

"Backgammon move=> ^h1 actionStrsToOutput" should {
"have an sgf output" in {
val output = ";W[lr]"
val output = ";W[mg]"
val actionStrs: ActionStrs = Vector(Vector("a2f1"))
Dumper.apply(Backgammon, actionStrs) must_== output
}
Expand All @@ -156,7 +156,7 @@ class DumperTest extends Specification with ValidatedMatchers {

"Backgammon part of game actionStrsToOutput" should {
"have an sgf output" in {
val output = ";W[31qtst]\n;B[66]"
val output = ";W[31hefe]\n;B[66]"
val actionStrs: ActionStrs =
Vector(Vector("1/3", "e1h1", "g1h1", "endTurn"), Vector("6/6"))
Dumper.apply(Backgammon, actionStrs) must_== output
Expand All @@ -165,7 +165,7 @@ class DumperTest extends Specification with ValidatedMatchers {

"Backgammon p2 starts actionStrsToOutput" should {
"have an sgf output" in {
val output = ";W[]\n;B[44xtxtmimi]\n;W[43]"
val output = ";W[]\n;B[44aeaelplp]\n;W[43]"
val actionStrs: ActionStrs =
Vector(Vector("endTurn"), Vector("4/4", "l1h1", "l1h1", "a1d2", "a1d2", "endTurn"), Vector("3/4"))
Dumper.apply(Backgammon, actionStrs) must_== output
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/format/sgf/TagTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class TagTest extends Specification with ValidatedMatchers {
)
).sorted.value.map(_.name) must_== List(
Tag.FF,
Tag.CA,
Tag.GM,
Tag.CA,
Tag.DT,
Tag.EV,
Tag.PW,
Expand Down

0 comments on commit 5f2d7a1

Please sign in to comment.