Memorize dead pieces
This commit is contained in:
parent
ef1e0a02ac
commit
a7b4ee2873
|
@ -3,17 +3,25 @@ package lila.chess
|
||||||
import format.PgnDump
|
import format.PgnDump
|
||||||
|
|
||||||
case class Game(
|
case class Game(
|
||||||
board: Board,
|
board: Board = Board(),
|
||||||
player: Color,
|
player: Color = White,
|
||||||
pgnMoves: String = "",
|
pgnMoves: String = "",
|
||||||
clock: Option[Clock] = None) {
|
clock: Option[Clock] = None,
|
||||||
|
deads: Map[Pos, Piece] = Map.empty) {
|
||||||
|
|
||||||
def playMove(from: Pos, to: Pos, promotion: PromotableRole = Queen): Valid[Game] = for {
|
def playMove(
|
||||||
move ← situation.move(from, to, promotion)
|
orig: Pos,
|
||||||
|
dest: Pos,
|
||||||
|
promotion: PromotableRole = Queen): Valid[Game] = for {
|
||||||
|
move ← situation.move(orig, dest, promotion)
|
||||||
} yield {
|
} yield {
|
||||||
val newGame = copy(
|
val newGame = copy(
|
||||||
board = move.afterWithPositionHashesUpdated,
|
board = move.afterWithPositionHashesUpdated,
|
||||||
player = !player
|
player = !player,
|
||||||
|
deads = (for {
|
||||||
|
cpos ← move.capture
|
||||||
|
cpiece ← board(cpos)
|
||||||
|
} yield deads + ((cpos, cpiece))) getOrElse deads
|
||||||
)
|
)
|
||||||
val pgnMove = PgnDump.move(situation, move, newGame.situation)
|
val pgnMove = PgnDump.move(situation, move, newGame.situation)
|
||||||
newGame.copy(pgnMoves = (pgnMoves + " " + pgnMove).trim)
|
newGame.copy(pgnMoves = (pgnMoves + " " + pgnMove).trim)
|
||||||
|
@ -23,10 +31,3 @@ case class Game(
|
||||||
|
|
||||||
def pgnMovesList = pgnMoves.split(' ').toList
|
def pgnMovesList = pgnMoves.split(' ').toList
|
||||||
}
|
}
|
||||||
|
|
||||||
object Game {
|
|
||||||
|
|
||||||
def apply(): Game = Game(
|
|
||||||
board = Board(),
|
|
||||||
player = White)
|
|
||||||
}
|
|
||||||
|
|
19
chess/src/test/scala/GameTest.scala
Normal file
19
chess/src/test/scala/GameTest.scala
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package lila.chess
|
||||||
|
|
||||||
|
import Pos._
|
||||||
|
import format.Visual.addNewLines
|
||||||
|
|
||||||
|
class GameTest extends ChessTest {
|
||||||
|
|
||||||
|
"capture a piece" should {
|
||||||
|
"add it to the dead pieces" in {
|
||||||
|
val game = Game().playMoves(
|
||||||
|
E2 -> E4,
|
||||||
|
D7 -> D5,
|
||||||
|
E4 -> D5)
|
||||||
|
game must beSuccess.like {
|
||||||
|
case g ⇒ g.deads must_== Map(D5 -> Black.pawn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue