From 8789f1cae5cde84a864fee0f86e6bd94d840bc3d Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Wed, 20 Feb 2013 14:13:51 +0100 Subject: [PATCH] strictness of board validation --- app/ai/stockfish/Ai.scala | 2 +- app/controllers/Setup.scala | 3 ++- app/setup/FormFactory.scala | 4 ++-- app/setup/Mappings.scala | 4 ++-- app/views/setup/ai.scala.html | 2 +- app/views/setup/fenInput.scala.html | 4 ++-- app/views/setup/friend.scala.html | 2 +- scalachess | 2 +- todo | 1 - 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/ai/stockfish/Ai.scala b/app/ai/stockfish/Ai.scala index 0680846877..02f317f976 100644 --- a/app/ai/stockfish/Ai.scala +++ b/app/ai/stockfish/Ai.scala @@ -26,7 +26,7 @@ final class Ai(server: Server) extends lila.ai.Ai with Stockfish { server.analyse(pgn, initialFen) private def withValidSituation[A](dbGame: DbGame)(op: ⇒ Future[Valid[A]]): Future[Valid[A]] = - if (dbGame.toChess.situation.playable) op + if (dbGame.toChess.situation playable true) op else Future { !!("Invalid game situation: " + dbGame.toChess.situation) } private implicit val executor = Akka.system.dispatcher diff --git a/app/controllers/Setup.scala b/app/controllers/Setup.scala index a6e7898ac3..c18db51692 100644 --- a/app/controllers/Setup.scala +++ b/app/controllers/Setup.scala @@ -115,7 +115,8 @@ object Setup extends LilaController with TheftPrevention with RoundEventPerforme for { fen ← get("fen") parsed ← chess.format.Forsyth <<< fen - if parsed.situation.playable + strict = get("strict").isDefined + if (parsed.situation playable strict) validated = chess.format.Forsyth >> parsed } yield """
""".format( parsed.situation.color.name, validated) diff --git a/app/setup/FormFactory.scala b/app/setup/FormFactory.scala index 0e0ff7f5e0..0e20534d2a 100644 --- a/app/setup/FormFactory.scala +++ b/app/setup/FormFactory.scala @@ -47,7 +47,7 @@ private[setup] final class FormFactory( "increment" -> increment, "level" -> level, "color" -> color, - "fen" -> fen + "fen" -> fen(true) )(AiConfig.<<)(_.>>) ) @@ -69,7 +69,7 @@ private[setup] final class FormFactory( "increment" -> increment, "mode" -> mode(ctx.isAuth), "color" -> color, - "fen" -> fen + "fen" -> fen(false) )(FriendConfig.<<)(_.>>) verifying ("Invalid clock", _.validClock) ) diff --git a/app/setup/Mappings.scala b/app/setup/Mappings.scala index 8d7d1ad8e7..e857c0c25d 100644 --- a/app/setup/Mappings.scala +++ b/app/setup/Mappings.scala @@ -23,7 +23,7 @@ object Mappings { val speed = number.verifying(Config.speeds contains _) val eloDiff = number.verifying(FilterConfig.eloDiffs contains _) - val fen = optional { - nonEmptyText verifying { source ⇒ ~(Forsyth <<< source).map(_.situation.playable) } + def fen(strict: Boolean) = optional { + nonEmptyText verifying { source ⇒ ~(Forsyth <<< source).map(_.situation playable strict) } } } diff --git a/app/views/setup/ai.scala.html b/app/views/setup/ai.scala.html index 9be2dda322..2b7b7a8a15 100644 --- a/app/views/setup/ai.scala.html +++ b/app/views/setup/ai.scala.html @@ -4,7 +4,7 @@
@setup.radios(form("variant"), translatedVariantChoicesWithFen)
-@fenInput(form("fen")) +@fenInput(form("fen"), true) @setup.clock(form, lila.setup.AiConfig) @trans.level()
diff --git a/app/views/setup/fenInput.scala.html b/app/views/setup/fenInput.scala.html index 1372db2934..0157272a93 100644 --- a/app/views/setup/fenInput.scala.html +++ b/app/views/setup/fenInput.scala.html @@ -1,6 +1,6 @@ -@(field: play.api.data.Field)(implicit ctx: Context) +@(field: play.api.data.Field, strict: Boolean)(implicit ctx: Context) -
+
@base.input(field, placeholder=trans.pasteTheFenStringHere.str().some)
diff --git a/app/views/setup/friend.scala.html b/app/views/setup/friend.scala.html index 4328b64c52..d00922deab 100644 --- a/app/views/setup/friend.scala.html +++ b/app/views/setup/friend.scala.html @@ -6,7 +6,7 @@
@setup.radios(form("variant"), translatedVariantChoicesWithFen)
-@fenInput(form("fen")) +@fenInput(form("fen"), false) @setup.clock(form, lila.setup.FriendConfig) @if(ctx.isAuth) {
diff --git a/scalachess b/scalachess index 195b624927..5d7b1e1d42 160000 --- a/scalachess +++ b/scalachess @@ -1 +1 @@ -Subproject commit 195b624927560fa580daa0b54b5eb4c7c23bd582 +Subproject commit 5d7b1e1d42143c6a16cc11928ebd741c8ab4d973 diff --git a/todo b/todo index 33a15a513c..fb1b5b3362 100644 --- a/todo +++ b/todo @@ -1,4 +1,3 @@ -finish flagged game start chess960 after both player move http://fr.lichess.org/forum/lichess-feedback/clock-fairness-in-chess960-games guess friend list takeback play 2 times ?? http://en.lichess.org/analyse/nfjchnmo/black move 45