Skip to content

Commit 3b1331b

Browse files
committed
feat(plugin24/GameState): mustPush check
1 parent d14e5c2 commit 3b1331b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

plugin/src/main/kotlin/sc/plugin2024/GameState.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ data class GameState @JvmOverloads constructor(
9696
actions.forEachIndexed { index, action ->
9797
when {
9898
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)
100100
action is Accelerate && index != 0 -> throw InvalidMoveException(MoveMistake.FIRST_ACTION_ACCELERATE, move)
101101
else -> action.perform(this)?.let { throw InvalidMoveException(it, move) }
102102
}
@@ -243,14 +243,17 @@ data class GameState @JvmOverloads constructor(
243243
return actions
244244
}
245245

246+
val mustPush: Boolean
247+
get() = currentShip.position == otherShip.position
248+
246249
/**
247250
* Retrieves all possible push actions that can be performed with the available movement points.
248251
*
249252
* @return A list of all possible push actions.
250253
*/
251254
fun getPossiblePushs(): List<Push> {
252255
if(board[currentShip.position] == Field.SANDBANK ||
253-
currentShip.position != otherShip.position ||
256+
!mustPush ||
254257
currentShip.movement < 1) return emptyList()
255258
return getPossiblePushs(currentShip.position, currentShip.direction)
256259
}
@@ -268,7 +271,7 @@ data class GameState @JvmOverloads constructor(
268271
* @return List of all turn actions
269272
*/
270273
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()
272275
// TODO hier sollte man vielleicht einfach die ausführbaren turns in freeTurns speichern, statt die generellen Turns
273276
val maxTurnCount = (maxCoal + currentShip.freeTurns).coerceAtMost(3)
274277
return (1..maxTurnCount).flatMap { i ->
@@ -286,7 +289,7 @@ data class GameState @JvmOverloads constructor(
286289
* @return List of all possible advances in the corresponding direction
287290
*/
288291
fun getPossibleAdvances(): List<Advance> {
289-
if(currentShip.movement <= 0 || currentShip.position == otherShip.position) return emptyList()
292+
if(currentShip.movement < 1 || mustPush) return emptyList()
290293
return getPossibleAdvances(currentShip)
291294
}
292295

@@ -368,7 +371,7 @@ data class GameState @JvmOverloads constructor(
368371
* @return List of all possible Acceleration actions
369372
*/
370373
fun getPossibleAccelerations(maxCoal: Int = currentShip.coal): List<Accelerate> {
371-
if(currentShip.position == otherShip.position) return emptyList()
374+
if(mustPush) return emptyList()
372375

373376
return (1..maxCoal + currentShip.freeAcc).flatMap { i ->
374377
listOfNotNull(

0 commit comments

Comments
 (0)