|
1 | 1 | package lila.ws
|
2 | 2 |
|
3 | 3 | import scala.collection.MapView
|
| 4 | +import scala.util.chaining._ |
4 | 5 |
|
5 | 6 | import play.api.libs.json._
|
6 | 7 | import strategygames.format.{ FEN, Forsyth, Uci, UciCharPair }
|
7 | 8 | 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 } |
9 | 10 | import strategygames.variant.Variant
|
10 | 11 | import strategygames.draughts
|
11 | 12 | import com.typesafe.scalalogging.Logger
|
@@ -37,7 +38,7 @@ object Chess {
|
37 | 38 | finalSquare = fullCaptureFields.isDefined,
|
38 | 39 | captures = fullCaptureFields,
|
39 | 40 | partialCaptures = req.fullCapture.getOrElse(false)
|
40 |
| - ).toOption flatMap { case (game, move) => |
| 41 | + ).toOption.flatMap { case (game, move) => |
41 | 42 | //Get the san of the last action
|
42 | 43 | game.actionStrs.flatten.lastOption.map { san =>
|
43 | 44 | {
|
@@ -112,22 +113,33 @@ object Chess {
|
112 | 113 | def apply(req: ClientOut.AnaDrop): ClientIn =
|
113 | 114 | Monitor.time(_.chessMoveTime) {
|
114 | 115 | try {
|
115 |
| - Game( |
| 116 | + val baseGame = Game( |
116 | 117 | req.variant.gameLogic,
|
117 | 118 | req.variant.some,
|
118 | 119 | 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) |
131 | 143 | } catch {
|
132 | 144 | case e: java.lang.ArrayIndexOutOfBoundsException =>
|
133 | 145 | logger.warn(s"${req.fen} ${req.variant} ${req.role}@${req.pos}", e)
|
|
0 commit comments