@@ -19,7 +19,7 @@ data class GameState @JvmOverloads constructor(
1919 override var turn : Int = 0 ,
2020 private val undeployedRedPieces : MutableList <Piece > = parsePiecesString(Constants .STARTING_PIECES , PlayerColor .RED ),
2121 private val undeployedBluePieces : MutableList <Piece > = parsePiecesString(Constants .STARTING_PIECES , PlayerColor .BLUE )
22- ): TwoPlayerGameState<Player, IMove>(), Cloneable {
22+ ): TwoPlayerGameState<Player, IMove>() {
2323
2424 @XStreamOmitField
2525 private var allPieces: Collection <Piece > = undeployedBluePieces + undeployedRedPieces + board.getPieces()
@@ -32,6 +32,12 @@ data class GameState @JvmOverloads constructor(
3232 return this
3333 }
3434
35+ /* * Copy constructor to create a new deeply copied state from the given [state]. */
36+ constructor (state: GameState ): this (state.red.clone(), state.blue.clone(), state.board.clone(), state.turn, ArrayList (state.undeployedRedPieces), ArrayList (state.undeployedBluePieces))
37+
38+ /* * Creates a deep copy of this [GameState]. */
39+ public override fun clone () = GameState (this )
40+
3541 fun getUndeployedPieces (owner : PlayerColor ): MutableList <Piece > {
3642 return when (owner) {
3743 PlayerColor .RED -> undeployedRedPieces
@@ -40,9 +46,9 @@ data class GameState @JvmOverloads constructor(
4046 }
4147
4248 fun getDeployedPieces (owner : PlayerColor ): List <Piece > {
43- val ownerPieces = allPieces.filterTo(ArrayList ()) { it.owner == owner }
44- getUndeployedPieces(owner).forEach { ownerPieces .remove(it) }
45- return ownerPieces
49+ val ownedPieces = allPieces.filterTo(ArrayList ()) { it.owner == owner }
50+ getUndeployedPieces(owner).forEach { ownedPieces .remove(it) }
51+ return ownedPieces
4652 }
4753
4854 fun addPlayer (player : Player ) {
0 commit comments