diff --git a/plugin2025/src/main/kotlin/sc/plugin2025/GameState.kt b/plugin2025/src/main/kotlin/sc/plugin2025/GameState.kt index a1b22cabb..8414fa19c 100644 --- a/plugin2025/src/main/kotlin/sc/plugin2025/GameState.kt +++ b/plugin2025/src/main/kotlin/sc/plugin2025/GameState.kt @@ -7,7 +7,9 @@ import sc.api.plugins.* import sc.plugin2025.GameRuleLogic.calculateCarrots import sc.plugin2025.GameRuleLogic.calculateMoveableFields import sc.plugin2025.util.HuIConstants +import sc.plugin2025.util.HuIWinReason import sc.shared.InvalidMoveException +import sc.shared.WinCondition import kotlin.math.pow import kotlin.math.sqrt @@ -66,6 +68,9 @@ data class GameState @JvmOverloads constructor( override val isOver: Boolean get() = players.any { it.inGoal } && turn.mod(2) == 0 || round >= HuIConstants.ROUND_LIMIT + override val winCondition: WinCondition? + get() = players.singleOrNull { it.inGoal }?.team?.let { WinCondition(it, HuIWinReason.GOAL) } + val Hare.inGoal get() = position == board.size - 1 diff --git a/plugin2025/src/test/kotlin/sc/plugin2025/GameStateTest.kt b/plugin2025/src/test/kotlin/sc/plugin2025/GameStateTest.kt index f60f97cb3..a278957d5 100644 --- a/plugin2025/src/test/kotlin/sc/plugin2025/GameStateTest.kt +++ b/plugin2025/src/test/kotlin/sc/plugin2025/GameStateTest.kt @@ -5,7 +5,9 @@ import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.* import sc.api.plugins.Team import sc.helpers.shouldSerializeTo +import sc.plugin2025.util.HuIWinReason import sc.shared.InvalidMoveException +import sc.shared.WinCondition class GameStateTest: FunSpec({ test("clone correctly") { @@ -48,6 +50,7 @@ class GameStateTest: FunSpec({ state.performMoveDirectly(EatSalad) state.turn shouldBe 2 state.isOver shouldBe true + state.winCondition shouldBe WinCondition(Team.TWO, HuIWinReason.GOAL) } test("tie") { state.currentPlayer.run { @@ -58,6 +61,7 @@ class GameStateTest: FunSpec({ state.performMoveDirectly(Advance(2)) state.turn shouldBe 2 state.isOver shouldBe true + state.winCondition shouldBe null } } test("produce nice XML") { diff --git a/sdk/src/main/server-api/sc/api/plugins/IGameState.kt b/sdk/src/main/server-api/sc/api/plugins/IGameState.kt index 2ac221a9c..aeb2b4bbb 100644 --- a/sdk/src/main/server-api/sc/api/plugins/IGameState.kt +++ b/sdk/src/main/server-api/sc/api/plugins/IGameState.kt @@ -47,9 +47,8 @@ interface IGameState: RoomMessage, PublicCloneable { val isOver: Boolean /** Falls es einen klaren Sieger anhand der Spielregeln unabhängig von der Punktzahl gibt. - * Wenn dieser Wert nicht null ist, sollte [isOver] true zurückgeben. */ + * Wenn dieser Wert nicht null ist, muss [isOver] true zurückgeben. */ val winCondition: WinCondition? - get() = null /** Gibt Punktzahlen des Teams passend zur ScoreDefinition des aktuellen Spielplugins zurück. */ fun getPointsForTeam(team: ITeam): IntArray