File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed
main/kotlin/sc/plugin2025
test/kotlin/sc/plugin2025
sdk/src/main/framework/sc/shared Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import sc.plugin2025.util.HuIConstants
11
11
import sc.plugin2025.util.HuIWinReason
12
12
import sc.shared.InvalidMoveException
13
13
import sc.shared.WinCondition
14
+ import sc.shared.WinReasonTie
14
15
import kotlin.math.pow
15
16
import kotlin.math.sqrt
16
17
@@ -70,7 +71,16 @@ data class GameState @JvmOverloads constructor(
70
71
get() = players.any { it.inGoal } && turn.mod(2 ) == 0 || turn / 2 >= HuIConstants .ROUND_LIMIT
71
72
72
73
override val winCondition: WinCondition ?
73
- get() = players.filter { it.inGoal }.maxByNoEqual { - it.carrots }?.team?.let { WinCondition (it, HuIWinReason .DIFFERING_CARROTS ) }
74
+ get() {
75
+ val goalies = players.filter { it.inGoal }
76
+ return when (goalies.size) {
77
+ 0 -> null
78
+ 1 -> WinCondition (goalies.single().team, HuIWinReason .GOAL )
79
+ else -> goalies.maxByNoEqual { - it.carrots }?.team?.let {
80
+ WinCondition (it, HuIWinReason .DIFFERING_CARROTS )
81
+ } ? : WinCondition (null , WinReasonTie )
82
+ }
83
+ }
74
84
75
85
val Hare .inGoal
76
86
get() = position == board.size - 1
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import sc.helpers.shouldSerializeTo
8
8
import sc.plugin2025.util.HuIWinReason
9
9
import sc.shared.InvalidMoveException
10
10
import sc.shared.WinCondition
11
+ import sc.shared.WinReasonTie
11
12
12
13
class GameStateTest : FunSpec ({
13
14
test("clone correctly") {
@@ -20,7 +21,7 @@ class GameStateTest: FunSpec({
20
21
test("let lower carrots win on tie") {
21
22
val state = GameState (Board (arrayOf(Field .GOAL )))
22
23
state.isOver shouldBe true
23
- state.winCondition shouldBe null
24
+ state.winCondition shouldBe WinCondition ( null, WinReasonTie )
24
25
state.players.first().carrots = 5
25
26
state.winCondition shouldBe WinCondition (Team .ONE , HuIWinReason .DIFFERING_CARROTS )
26
27
state.players.last().carrots = 4
@@ -70,7 +71,7 @@ class GameStateTest: FunSpec({
70
71
state.performMoveDirectly(Advance (2))
71
72
state.turn shouldBe 2
72
73
state.isOver shouldBe true
73
- state.winCondition shouldBe null
74
+ state.winCondition shouldBe WinCondition ( null, WinReasonTie )
74
75
}
75
76
test("round limit") {
76
77
state.turn = 59
Original file line number Diff line number Diff line change @@ -20,5 +20,8 @@ data class WinCondition(
20
20
override fun toString (): String =
21
21
reason.getMessage((if (reason.isRegular) winner else winner?.opponent()).toString())
22
22
23
- override fun equals (other : Any? ): Boolean = other is WinCondition && other.winner == winner
23
+ override fun equals (other : Any? ): Boolean =
24
+ other is WinCondition &&
25
+ other.winner == winner &&
26
+ other.reason == reason
24
27
}
You can’t perform that action at this time.
0 commit comments