better decline PGNs with ambiguous moves

chess.com still produces PGN with ambiguous moves, that can't be read:

[Site "Chess.com"]
[Date "2021.09.15"]
[Round "?"]
[White "Heiko_Schmitz"]
[Black "Vostoro"]
[Result "0-1"]
[ECO "B06"]
[WhiteElo "1117"]
[BlackElo "812"]
[TimeControl "180+2"]
[EndTime "10:43:14 PDT"]
[Termination "Vostoro won by resignation"]

1. e4 g6 2. d4 Bg7 3. c3 d6 4. f4 a6 5. e5 dxe5 6. fxe5 b5 7. Na3 Bb7 8. Nf3 Nd7
9. Ng5 h6 10. Nf3 f6 11. Qe2 Nb6 12. g4 Nc4 13. Bg2 Nxa3 14. bxa3 Bxf3 15. Bxf3
Rc8 16. Bb7 Rb8 17. Bxa6 Qd5 18. c4 bxc4 19. Kd2 Qxh1 20. Qxc4 Qxh2+ 21. Kd3
fxe5 22. Bb5+ Kf8 23. Rb1 exd4 24. Bb2 Nf6 25. Bxd4 c6 26. Qxc6 Nxg4 27. Qxg6
Bxd4 28. Kxd4 Rg8 29. Qf5+ Nf6 30. Re1 Qd2+ 31. Bd3 Qxe1 32. Qc5 Qf2+ 33. Kc4
Qxc5+ 34. Kxc5 Rb2 35. Bc4 Ne4+ 36. Kd4 Nd2 37. Bxg8 Kxg8 38. Kc3 Rxa2 39. Kb4
h5 40. a4 h4 41. a5 Rxa5 42. Kxa5 h3 43. Kb6 h2 44. Kc7 h1=Q 45. Kd7 Qd5+ 46.
Ke8 Qe4 47. Kd7 Qd3+ 48. Ke8 e5 49. Ke7 e4 50. Ke6 e3 51. Kf6 e2 52. Kg5 e1=$146
53. Kg4 Kf8 54. Kf4 Ke8 55. Kg4 Qe3 56. Kf5 Nc2 57. Kg6 Qf4 58. Kh5 Qg3 59. Kh6
Qg4 60. Kh7 Qg5 61. Kh8 Kf7 0-1

55... Qe3 is ambiguous, both black queens go to e3.
This commit is contained in:
Thibault Duplessis 2021-09-16 08:55:47 +02:00
parent 078d346909
commit 74c251fe7e
2 changed files with 10 additions and 11 deletions

View file

@ -1,6 +1,7 @@
package controllers
import play.api.libs.json.Json
import scala.util.{ Either, Left, Right }
import play.api.mvc._
import scala.concurrent.duration._
import views._
@ -41,7 +42,7 @@ final class Importer(env: Env) extends LilaController(env) {
data =>
ImportRateLimitPerIP(ctx.ip, cost = 1) {
doImport(data, req, ctx.me) flatMap {
case Some(game) =>
case Right(game) =>
ctx.me.ifTrue(data.analyse.isDefined && game.analysable) ?? { me =>
env.fishnet.analyser(
game,
@ -53,7 +54,7 @@ final class Importer(env: Env) extends LilaController(env) {
)
)
} inject Redirect(routes.Round.watcher(game.id, "white"))
case None => Redirect(routes.Importer.importGame).fuccess
case Left(error) => Redirect(routes.Importer.importGame).flashFailure(error).fuccess
}
}(rateLimitedFu)
)
@ -68,14 +69,14 @@ final class Importer(env: Env) extends LilaController(env) {
err => BadRequest(apiFormError(err)).fuccess,
data =>
doImport(data, req, me) map {
_.fold(BadRequest(jsonError("The PGN could not be replayed"))) { game =>
case Left(error) => BadRequest(jsonError(error))
case Right(game) =>
JsonOk {
Json.obj(
"id" -> game.id,
"url" -> s"${env.net.baseUrl}/${game.id}"
)
}
}
}
)
}(rateLimitedFu)
@ -89,14 +90,11 @@ final class Importer(env: Env) extends LilaController(env) {
data: lila.importer.ImportData,
req: RequestHeader,
me: Option[lila.user.User]
): Fu[Option[lila.game.Game]] =
): Fu[Either[String, lila.game.Game]] =
env.importer.importer(data, me.map(_.id)) flatMap { game =>
me.map(_.id).??(env.game.cached.clearNbImportedByCache) inject game.some
} recover { case e: Exception =>
lila
.log("importer")
.warn(s"Imported game validates but can't be replayed:\n${data.pgn}", e)
none
me.map(_.id).??(env.game.cached.clearNbImportedByCache) inject Right(game)
} recover { case _: Exception =>
Left("The PGN contains illegal and/or ambiguous moves.")
}
def masterGame(id: String, orientation: String) =

View file

@ -28,6 +28,7 @@ object importGame {
main(cls := "importer page-small box box-pad")(
h1(trans.importGame()),
p(cls := "explanation")(trans.importGameExplanation()),
standardFlash(),
postForm(cls := "form3 import", action := routes.Importer.sendGame)(
form3.group(form("pgn"), trans.pasteThePgnStringHere())(form3.textarea(_)()),
form("pgn").value flatMap { pgn =>