From cb9478ff97b36e0be68b573230aa0fecc845f93c Mon Sep 17 00:00:00 2001 From: Gordon Martin Date: Thu, 15 Jan 2015 20:39:18 +0000 Subject: [PATCH] Adding modules/chess antichess improvements based on the chess antichess_improvements branch. We no longer have an AntiKing which was a bit of a hack. --- modules/chess | 2 +- modules/game/src/main/BinaryFormat.scala | 11 ++++++----- modules/game/src/main/Game.scala | 2 +- modules/game/src/test/BinaryPieceTest.scala | 3 ++- ui/round/src/ground.js | 5 ----- ui/round/src/promotion.js | 6 ++---- 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/modules/chess b/modules/chess index e7d8b3f644fdf..9df6557953527 160000 --- a/modules/chess +++ b/modules/chess @@ -1 +1 @@ -Subproject commit e7d8b3f644fdfa876e416e1221a64d6db311991c +Subproject commit 9df65579535274f3aee66c08c64097f9702ccdf2 diff --git a/modules/game/src/main/BinaryFormat.scala b/modules/game/src/main/BinaryFormat.scala index 7a036d3bb306a..1537d12fe2008 100644 --- a/modules/game/src/main/BinaryFormat.scala +++ b/modules/game/src/main/BinaryFormat.scala @@ -2,6 +2,7 @@ package lila.game import org.joda.time.DateTime import scala.util.{ Try, Success, Failure } +import chess.variant.Variant import chess._ @@ -163,13 +164,13 @@ object BinaryFormat { } toArray) } - def read(ba: ByteArray): PieceMap = { + def read(ba: ByteArray, variant: Variant): PieceMap = { def splitInts(b: Byte) = { val int = b.toInt Array(int >> 4, int & 0x0F) } def intPiece(int: Int): Option[Piece] = - intToRole(int & 7) map { role => Piece(Color((int & 8) == 0), role) } + intToRole(int & 7, variant) map { role => Piece(Color((int & 8) == 0), role) } val pieceInts = ba.value flatMap splitInts (Pos.all zip pieceInts flatMap { case (pos, int) => intPiece(int) map (pos -> _) @@ -179,14 +180,15 @@ object BinaryFormat { // cache standard start position val standard = write(Board.init(chess.variant.Standard).pieces) - private def intToRole(int: Int): Option[Role] = int match { + private def intToRole(int: Int, variant: Variant): Option[Role] = int match { case 6 => Some(Pawn) case 1 => Some(King) case 2 => Some(Queen) case 3 => Some(Rook) case 4 => Some(Knight) case 5 => Some(Bishop) - case 7 => Some(Antiking) + // Legacy from when we used to have an 'Antiking' piece + case 7 if variant.antichess => Some(King) case _ => None } private def roleToInt(role: Role): Int = role match { @@ -196,7 +198,6 @@ object BinaryFormat { case Rook => 3 case Knight => 4 case Bishop => 5 - case Antiking => 7 } } diff --git a/modules/game/src/main/Game.scala b/modules/game/src/main/Game.scala index dd53cfebf5e0f..a20ca2a60eb98 100644 --- a/modules/game/src/main/Game.scala +++ b/modules/game/src/main/Game.scala @@ -113,7 +113,7 @@ case class Game( lazy val toChess: ChessGame = { - val pieces = BinaryFormat.piece read binaryPieces + val pieces = BinaryFormat.piece.read(binaryPieces, variant) ChessGame( board = Board(pieces, toChessHistory, variant), diff --git a/modules/game/src/test/BinaryPieceTest.scala b/modules/game/src/test/BinaryPieceTest.scala index 623dfb1096195..648615af96dd5 100644 --- a/modules/game/src/test/BinaryPieceTest.scala +++ b/modules/game/src/test/BinaryPieceTest.scala @@ -8,6 +8,7 @@ import org.specs2.mutable._ import org.specs2.specification._ import lila.db.ByteArray +import chess.variant.Standard class BinaryPieceTest extends Specification { @@ -15,7 +16,7 @@ class BinaryPieceTest extends Specification { def write(all: PieceMap): List[String] = (BinaryFormat.piece write all).showBytes.split(',').toList def read(bytes: List[String]): PieceMap = - BinaryFormat.piece read ByteArray.parseBytes(bytes) + BinaryFormat.piece.read(ByteArray.parseBytes(bytes), Standard) "binary pieces" should { "write" should { diff --git a/ui/round/src/ground.js b/ui/round/src/ground.js index 127de43ef25ef..40904a07e3d92 100644 --- a/ui/round/src/ground.js +++ b/ui/round/src/ground.js @@ -62,11 +62,6 @@ function reload(ground, data, fen, flip) { function promote(ground, key, role) { - // If the player has promoted to a king in the antichess mode, we treat - // the piece like a king - if (role === "antiking") - role = "king"; - var pieces = {}; var piece = ground.data.pieces[key]; if (piece && piece.role == 'pawn') { diff --git a/ui/round/src/promotion.js b/ui/round/src/promotion.js index d3853af4a870e..69ae6655f4c5e 100644 --- a/ui/round/src/promotion.js +++ b/ui/round/src/promotion.js @@ -39,15 +39,13 @@ module.exports = { view: function(ctrl) { var pieces = ctrl.data.game.variant.key != "antichess" ? - ['queen', 'knight', 'rook', 'bishop'] : ['queen', 'knight', 'rook', 'bishop', 'antiking'] + ['queen', 'knight', 'rook', 'bishop'] : ['queen', 'knight', 'rook', 'bishop', 'king'] return promoting ? m('div#promotion_choice', { onclick: partial(cancel, ctrl) }, pieces.map(function(serverRole) { - // We display the piece for the antiking the same way we would for a normal king - var internalPiece = serverRole == "antiking" ? "king" : serverRole; - return m('div.cg-piece.' + internalPiece + '.' + ctrl.data.player.color, { + return m('div.cg-piece.' + serverRole + '.' + ctrl.data.player.color, { onclick: function(e) { e.stopPropagation(); finish(ctrl, serverRole);