@@ -80,7 +80,7 @@ object GameRuleLogic {
8080 if (bordersOnColor(gameState.board, it, move.color))
8181 throw InvalidMoveException (" Field $it already borders on ${move.color} " , move)
8282 }
83- if (gameState.deployedPieces?.getValue(move.color).isNullOrEmpty( )) {
83+ if (isFirstMove(gameState )) {
8484 // Check if it's the requested shape
8585 if (move.piece.kind != gameState.startPiece)
8686 throw InvalidMoveException (" Expected the predetermined staring piece, ${gameState.startPiece} " , move)
@@ -154,6 +154,11 @@ object GameRuleLogic {
154154 fun getPossibleMoves (gameState : GameState ) =
155155 streamPossibleMoves(gameState).toSet()
156156
157+ /* * Returns a list of all possible SetMoves, regardless of whether it's the first round. */
158+ @JvmStatic
159+ fun getAllPossibleMoves (gameState : GameState ) =
160+ streamAllPossibleMoves(gameState).toSet()
161+
157162 /* * Returns a list of possible SetMoves if it's the first round. */
158163 @JvmStatic
159164 fun getPossibleStartMoves (gameState : GameState ) =
@@ -196,16 +201,22 @@ object GameRuleLogic {
196201 fun streamPossibleMoves (gameState : GameState ) =
197202 if (isFirstMove(gameState))
198203 streamPossibleStartMoves(gameState)
199- else sequence<SetMove > {
200- val color = gameState.currentColor
201- gameState.undeployedPieceShapes.getValue(color).map {
202- val area = it.coordinates.area()
203- for (y in 0 until Constants .BOARD_SIZE - area.dy)
204- for (x in 0 until Constants .BOARD_SIZE - area.dx)
205- for (variant in it.variants)
206- yield (SetMove (Piece (color, it, variant.key, Coordinates (x, y))))
207- }
208- }.filter { isValidSetMove(gameState, it) }
204+ else
205+ streamAllPossibleMoves(gameState)
206+
207+ /* * Streams all possible moves regardless of whether it's the first turn. */
208+ @JvmStatic
209+ fun streamAllPossibleMoves (gameState : GameState ) = sequence<SetMove > {
210+ val color = gameState.currentColor
211+ gameState.undeployedPieceShapes.getValue(color).map {
212+ val area = it.coordinates.area()
213+ for (y in 0 until Constants .BOARD_SIZE - area.dy)
214+ for (x in 0 until Constants .BOARD_SIZE - area.dx)
215+ for (variant in it.variants) {
216+ yield (SetMove (Piece (color, it, variant.key, Coordinates (x, y))))
217+ }
218+ }
219+ }.filter { isValidSetMove(gameState, it) }
209220
210221 /* * Streams all possible moves if it's the first turn of [gameState]. */
211222 @JvmStatic
0 commit comments