Skip to content

Commit f2e2edf

Browse files
authored
Merge pull request #98 from Mind-Sports-Games/pla-827-support-sgf-download-in-analysis
support sgf format for analysis and studies
2 parents 2ee54e0 + 9d0626e commit f2e2edf

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ libraryDependencies += "io.lettuce" % "lettuce-core"
1919
libraryDependencies += "io.netty" % "netty-handler" % nettyVersion
2020
libraryDependencies += "io.netty" % "netty-codec-http" % nettyVersion
2121
libraryDependencies += "io.netty" % "netty-transport-native-epoll" % nettyVersion classifier "linux-x86_64"
22-
libraryDependencies += "org.playstrategy" %% "strategygames" % "10.2.1-pstrat124"
22+
libraryDependencies += "org.playstrategy" %% "strategygames" % "10.2.1-pstrat134"
2323
libraryDependencies += "com.typesafe.akka" %% "akka-actor-typed" % akkaVersion
2424
libraryDependencies += "com.typesafe.akka" %% "akka-slf4j" % akkaVersion
2525
libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.3"

src/main/scala/Chess.scala

+33-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import scala.util.chaining._
66
import play.api.libs.json._
77
import strategygames.format.{ FEN, Forsyth, Uci, UciCharPair }
88
import strategygames.opening.{ FullOpening, FullOpeningDB }
9-
import strategygames.{ Game, GameLogic, MoveMetrics, Pocket, PocketData, Pos, Role, Situation }
9+
import strategygames.{ Game, GameFamily, GameLogic, MoveMetrics, Pocket, PocketData, Pos, Role, Situation }
1010
import strategygames.variant.Variant
1111
import strategygames.draughts
1212
import com.typesafe.scalalogging.Logger
@@ -39,9 +39,13 @@ object Chess {
3939
captures = fullCaptureFields,
4040
partialCaptures = req.fullCapture.getOrElse(false)
4141
).toOption.flatMap { case (game, move) =>
42-
//Get the san of the last action
43-
game.actionStrs.flatten.lastOption.map { san =>
42+
//Get the game record notation (san/sgf) of the last action
43+
game.actionStrs.flatten.lastOption.map { lastAction =>
4444
{
45+
val gameRecordNotation =
46+
if (isSgf(req.variant))
47+
strategygames.format.sgf.Dumper(req.variant, Vector(Vector(lastAction)))
48+
else lastAction
4549
val movable = game.situation.playable(false)
4650
val captLen = (game.situation, req.dest) match {
4751
case (Situation.Draughts(sit), Pos.Draughts(dest)) =>
@@ -75,7 +79,7 @@ object Chess {
7579
case _ => false
7680
}
7781
),
78-
san
82+
gameRecordNotation
7983
),
8084
req.path,
8185
req.chapterId,
@@ -128,15 +132,25 @@ object Chess {
128132
g.drop(req.role, req.pos)
129133
.toOption
130134
.flatMap({ case (game, drop) =>
131-
//Get the san of the last action
132-
game.actionStrs.flatten.lastOption map { san =>
133-
makeNode(
134-
game,
135-
Uci.WithSan(req.variant.gameLogic, Uci(req.variant.gameLogic, drop), san),
136-
req.path,
137-
req.chapterId,
138-
if (game.situation.playable(false)) game.situation.destinations else Map.empty
139-
)
135+
//Get the game record notation (san/sgf) of the last action
136+
game.actionStrs.flatten.lastOption map { lastAction =>
137+
{
138+
val gameRecordNotation =
139+
if (isSgf(req.variant))
140+
strategygames.format.sgf.Dumper(req.variant, Vector(Vector(lastAction)))
141+
else lastAction
142+
makeNode(
143+
game,
144+
Uci.WithSan(
145+
req.variant.gameLogic,
146+
Uci(req.variant.gameLogic, drop),
147+
gameRecordNotation
148+
),
149+
req.path,
150+
req.chapterId,
151+
if (game.situation.playable(false)) game.situation.destinations else Map.empty
152+
)
153+
}
140154
}
141155
})
142156
.getOrElse(ClientIn.StepFailure)
@@ -274,6 +288,12 @@ object Chess {
274288
)
275289
}
276290

291+
private def isSgf(variant: Variant): Boolean = {
292+
variant.gameLogic == GameLogic.FairySF() || variant.gameLogic == GameLogic
293+
.Go() || variant.gameLogic == GameLogic
294+
.Backgammon() || (variant.gameFamily == GameFamily.LinesOfAction())
295+
}
296+
277297
//TODO: push this into strategygames. So much copy/paste from lila.socket.AnaDests
278298
//this continues until `object json`
279299
private val initialChessDests = "iqy muC gvx ltB bqs pxF jrz nvD ksA owE"

src/main/scala/ipc/ClientIn.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ object ClientIn {
182182
"node" -> Json
183183
.obj(
184184
"ply" -> ply,
185-
//TODO verify if this is actually being used and where receives this
185+
//This is used within analysis actions
186186
"turnCount" -> turnCount,
187187
"fen" -> fen,
188188
"id" -> id,

0 commit comments

Comments
 (0)