@@ -96,7 +96,7 @@ data class GameState @JvmOverloads constructor(
96
96
actions.forEachIndexed { index, action ->
97
97
when {
98
98
board[currentShip.position] == Field .SANDBANK && index != 0 -> throw InvalidMoveException (MoveMistake .SAND_BANK_END , move)
99
- currentShip.position == otherShip.position && action !is Push -> throw InvalidMoveException (MoveMistake .PUSH_ACTION_REQUIRED , move)
99
+ mustPush && action !is Push -> throw InvalidMoveException (MoveMistake .PUSH_ACTION_REQUIRED , move)
100
100
action is Accelerate && index != 0 -> throw InvalidMoveException (MoveMistake .FIRST_ACTION_ACCELERATE , move)
101
101
else -> action.perform(this )?.let { throw InvalidMoveException (it, move) }
102
102
}
@@ -243,14 +243,17 @@ data class GameState @JvmOverloads constructor(
243
243
return actions
244
244
}
245
245
246
+ val mustPush: Boolean
247
+ get() = currentShip.position == otherShip.position
248
+
246
249
/* *
247
250
* Retrieves all possible push actions that can be performed with the available movement points.
248
251
*
249
252
* @return A list of all possible push actions.
250
253
*/
251
254
fun getPossiblePushs (): List <Push > {
252
255
if (board[currentShip.position] == Field .SANDBANK ||
253
- currentShip.position != otherShip.position ||
256
+ ! mustPush ||
254
257
currentShip.movement < 1 ) return emptyList()
255
258
return getPossiblePushs(currentShip.position, currentShip.direction)
256
259
}
@@ -268,7 +271,7 @@ data class GameState @JvmOverloads constructor(
268
271
* @return List of all turn actions
269
272
*/
270
273
fun getPossibleTurns (maxCoal : Int = currentShip.coal): List <Turn > {
271
- if (board[currentShip.position] == Field .SANDBANK || currentShip.position == otherShip.position ) return emptyList()
274
+ if (board[currentShip.position] == Field .SANDBANK || mustPush ) return emptyList()
272
275
// TODO hier sollte man vielleicht einfach die ausführbaren turns in freeTurns speichern, statt die generellen Turns
273
276
val maxTurnCount = (maxCoal + currentShip.freeTurns).coerceAtMost(3 )
274
277
return (1 .. maxTurnCount).flatMap { i ->
@@ -286,7 +289,7 @@ data class GameState @JvmOverloads constructor(
286
289
* @return List of all possible advances in the corresponding direction
287
290
*/
288
291
fun getPossibleAdvances (): List <Advance > {
289
- if (currentShip.movement <= 0 || currentShip.position == otherShip.position ) return emptyList()
292
+ if (currentShip.movement < 1 || mustPush ) return emptyList()
290
293
return getPossibleAdvances(currentShip)
291
294
}
292
295
@@ -368,7 +371,7 @@ data class GameState @JvmOverloads constructor(
368
371
* @return List of all possible Acceleration actions
369
372
*/
370
373
fun getPossibleAccelerations (maxCoal : Int = currentShip.coal): List <Accelerate > {
371
- if (currentShip.position == otherShip.position ) return emptyList()
374
+ if (mustPush ) return emptyList()
372
375
373
376
return (1 .. maxCoal + currentShip.freeAcc).flatMap { i ->
374
377
listOfNotNull(
0 commit comments