@@ -62,16 +62,14 @@ object GameRuleLogic {
6262 /* * Checks if the given [move] is able to be performed for the given [gameState]. */
6363 @JvmStatic
6464 fun validateSetMove (gameState : GameState , move : SetMove ) {
65- // Check if piece has already been placed
66- gameState.undeployedPieceShapes.getValue(move.color).find { it == move.piece.kind }
67- ? : throw InvalidMoveException (" Piece #${move.piece.kind} has already been placed before" , move)
68-
65+ // Check whether the color's move is currently active
66+ validateMoveColor(gameState, move)
67+ // Check whether the shape is valid
68+ validateShape(gameState, move.piece.kind, move.color)
69+ // Check whether the piece can be placed
6970 validateSetMove(gameState.board, move)
7071
7172 if (isFirstMove(gameState)) {
72- // Check if it's the requested shape
73- if (move.piece.kind != gameState.startPiece)
74- throw InvalidMoveException (" Expected the predetermined staring piece, ${gameState.startPiece} " , move)
7573 // Check if it is placed correctly in a corner
7674 if (move.piece.coordinates.none { isOnCorner(it)})
7775 throw InvalidMoveException (" The Piece isn't located in a corner" , move)
@@ -82,7 +80,19 @@ object GameRuleLogic {
8280 }
8381 }
8482
85- /* * Validates a SetMove on a board. */
83+ /* * Validates the [PieceShape] of a [SetMove] depending on the current [GameState]. */
84+ @JvmStatic
85+ fun validateShape (gameState : GameState , shape : PieceShape , color : Color = gameState.currentColor) {
86+ if (isFirstMove(gameState)) {
87+ if (shape != gameState.startPiece)
88+ throw InvalidMoveException (" $shape is not the requested first shape, ${gameState.startPiece} " )
89+ } else {
90+ if (! gameState.undeployedPieceShapes.getValue(color).contains(shape))
91+ throw InvalidMoveException (" Piece ${shape} has already been placed before" )
92+ }
93+ }
94+
95+ /* * Validates a [SetMove] on a [board]. */
8696 @JvmStatic
8797 fun validateSetMove (board : Board , move : SetMove ) {
8898 move.piece.coordinates.forEach {
0 commit comments