diff --git a/plugin2025/src/main/kotlin/sc/plugin2025/GameState.kt b/plugin2025/src/main/kotlin/sc/plugin2025/GameState.kt index f3f7fe173..052fb2e89 100644 --- a/plugin2025/src/main/kotlin/sc/plugin2025/GameState.kt +++ b/plugin2025/src/main/kotlin/sc/plugin2025/GameState.kt @@ -122,6 +122,14 @@ data class GameState @JvmOverloads constructor( ExchangeCarrots(-10).takeIf { mayExchangeCarrots(-10, player) }, ) + /** Checks which cards of the given player are usable from its current position. + * Does not check validity of a whole move. + * + * Usable means playable on a hare field + * and buyable on a market field. + * + * @return empty array means no cards are usable, + * null means not on a field where cards can be used. */ fun nextCards(player: Hare = currentPlayer): Collection>? = when(player.field) { Field.HARE -> { diff --git a/plugin2025/src/test/kotlin/sc/plugin2025/CardTest.kt b/plugin2025/src/test/kotlin/sc/plugin2025/CardTest.kt index 8fdb1669f..ea4906235 100644 --- a/plugin2025/src/test/kotlin/sc/plugin2025/CardTest.kt +++ b/plugin2025/src/test/kotlin/sc/plugin2025/CardTest.kt @@ -2,6 +2,7 @@ package sc.plugin2025 import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.* +import io.kotest.matchers.collections.* import sc.plugin2025.util.HuIConstants class CardTest: FunSpec({ @@ -13,10 +14,13 @@ class CardTest: FunSpec({ lastSalad shouldBe HuIConstants.LAST_SALAD state.currentPlayer.position = lastSalad!! Card.SWAP_CARROTS.check(state) shouldBe HuIMoveMistake.CANNOT_PLAY_SWAP_CARROTS_BEYOND_LAST_SALAD - state.currentPlayer.position = lastSalad - 1 + state.currentPlayer.position = state.board.getPreviousField(Field.HARE, lastSalad)!! Card.SWAP_CARROTS.check(state) shouldBe null + state.currentPlayer.addCard(Card.SWAP_CARROTS) + state.nextCards() shouldContainExactly listOf(arrayOf(Card.SWAP_CARROTS)) state.otherPlayer.position = lastSalad Card.SWAP_CARROTS.check(state) shouldBe HuIMoveMistake.CANNOT_PLAY_SWAP_CARROTS_BEYOND_LAST_SALAD + state.nextCards().shouldBeEmpty() } state.currentPlayer.addCard(Card.SWAP_CARROTS) test("not repeatable") {