Skip to content

Commit 8239c52

Browse files
authored
Merge pull request #93 from Mind-Sports-Games/dev
Dev to master studies
2 parents 2b507e6 + 03210a1 commit 8239c52

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
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-pstrat121"
22+
libraryDependencies += "org.playstrategy" %% "strategygames" % "10.2.1-pstrat122"
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"

project/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.5.2
1+
sbt.version=1.7.2

src/main/scala/Chess.scala

+27-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package lila.ws
22

33
import scala.collection.MapView
4+
import scala.util.chaining._
45

56
import play.api.libs.json._
67
import strategygames.format.{ FEN, Forsyth, Uci, UciCharPair }
78
import strategygames.opening.{ FullOpening, FullOpeningDB }
8-
import strategygames.{ Game, GameLogic, Pocket, PocketData, Pos, Role, Situation }
9+
import strategygames.{ Game, GameLogic, MoveMetrics, Pocket, PocketData, Pos, Role, Situation }
910
import strategygames.variant.Variant
1011
import strategygames.draughts
1112
import com.typesafe.scalalogging.Logger
@@ -37,7 +38,7 @@ object Chess {
3738
finalSquare = fullCaptureFields.isDefined,
3839
captures = fullCaptureFields,
3940
partialCaptures = req.fullCapture.getOrElse(false)
40-
).toOption flatMap { case (game, move) =>
41+
).toOption.flatMap { case (game, move) =>
4142
//Get the san of the last action
4243
game.actionStrs.flatten.lastOption.map { san =>
4344
{
@@ -112,22 +113,33 @@ object Chess {
112113
def apply(req: ClientOut.AnaDrop): ClientIn =
113114
Monitor.time(_.chessMoveTime) {
114115
try {
115-
Game(
116+
val baseGame = Game(
116117
req.variant.gameLogic,
117118
req.variant.some,
118119
Some(req.fen)
119-
).drop(req.role, req.pos).toOption flatMap { case (game, drop) =>
120-
//Get the san of the last action
121-
game.actionStrs.flatten.lastOption map { san =>
122-
makeNode(
123-
game,
124-
Uci.WithSan(req.variant.gameLogic, Uci(req.variant.gameLogic, drop), san),
125-
req.path,
126-
req.chapterId,
127-
if (game.situation.playable(false)) game.situation.destinations else Map.empty
128-
)
129-
}
130-
} getOrElse ClientIn.StepFailure
120+
)
121+
val g: Game = req.halfMove
122+
.flatMap(m => {
123+
Uci(req.variant, s"${m.orig}${m.dest}")
124+
})
125+
.flatMap(u => baseGame.applyUci(u, MoveMetrics()).toOption)
126+
.map(_._1)
127+
.getOrElse(baseGame)
128+
g.drop(req.role, req.pos)
129+
.toOption
130+
.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+
)
140+
}
141+
})
142+
.getOrElse(ClientIn.StepFailure)
131143
} catch {
132144
case e: java.lang.ArrayIndexOutOfBoundsException =>
133145
logger.warn(s"${req.fen} ${req.variant} ${req.role}@${req.pos}", e)

src/main/scala/ipc/ClientOut.scala

+11-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ object ClientOut {
4040

4141
case class Opening(variant: Variant, path: Path, fen: FEN) extends ClientOutSite
4242

43+
case class Move(orig: Pos, dest: Pos)
44+
4345
case class AnaMove(
4446
orig: Pos,
4547
dest: Pos,
@@ -60,7 +62,8 @@ object ClientOut {
6062
path: Path,
6163
variant: Variant,
6264
chapterId: Option[ChapterId],
63-
payload: JsObject
65+
payload: JsObject,
66+
halfMove: Option[Move] = None
6467
) extends ClientOutSite
6568

6669
case class AnaPass(
@@ -231,7 +234,13 @@ object ClientOut {
231234
Path(path),
232235
variant,
233236
chapterId,
234-
o
237+
o,
238+
(d obj "halfMove").flatMap(halfMove => {
239+
for {
240+
orig <- halfMove str "orig" flatMap (p => Pos.fromKey(lib, p))
241+
dest <- halfMove str "dest" flatMap (p => Pos.fromKey(lib, p))
242+
} yield Move(orig, dest)
243+
})
235244
)
236245
case "anaPass" =>
237246
for {

0 commit comments

Comments
 (0)