Skip to content

Commit

Permalink
fix(sdk): remove confusing round numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
xeruf committed Jun 27, 2024
1 parent 8f18737 commit 3e8b3ba
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 27 deletions.
17 changes: 0 additions & 17 deletions plugin/src/test/kotlin/sc/plugin2023/GameStateTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,6 @@ class GameStateTest: FunSpec({
// TODO
}
}
context("state detection") {
test("isOver") {
val state = GameState()
state.round shouldBe 0
state.isOver shouldBe false
val state60 = GameState(turn = 58)
state60.round shouldBe 29
state60.isOver shouldBe false
state60.turn++
state60.round shouldBe 30
state60.isOver shouldBe false
state60.turn++
state60.round shouldBe 30
state60.isOver shouldBe false
//state60.isOver shouldBe true
}
}
context("move calculation") {
context("initial placement") {
val emptyBoard = makeBoard()
Expand Down
2 changes: 1 addition & 1 deletion plugin2025/src/main/kotlin/sc/plugin2025/GameState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ data class GameState @JvmOverloads constructor(
get() = currentTeamFromTurn()

override val isOver: Boolean
get() = players.any { it.inGoal } && turn.mod(2) == 0 || round >= HuIConstants.ROUND_LIMIT
get() = players.any { it.inGoal } && turn.mod(2) == 0 || turn / 2 >= HuIConstants.ROUND_LIMIT

override val winCondition: WinCondition?
get() = players.singleOrNull { it.inGoal }?.team?.let { WinCondition(it, HuIWinReason.GOAL) }
Expand Down
6 changes: 6 additions & 0 deletions plugin2025/src/test/kotlin/sc/plugin2025/GameStateTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ class GameStateTest: FunSpec({
state.isOver shouldBe true
state.winCondition shouldBe null
}
test("round limit") {
state.turn = 59
state.isOver shouldBe false
state.turn++
state.isOver shouldBe true
}
}
test("produce nice XML") {
Hare(Team.TWO, lastAction = EatSalad) shouldSerializeTo """
Expand Down
5 changes: 1 addition & 4 deletions sdk/src/main/server-api/sc/api/plugins/IGameState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ import sc.shared.WinCondition
* Teilinformationen abgefragt werden.
*/
interface IGameState: RoomMessage, PublicCloneable<IGameState> {
/** Aktuelle Zugzahl */
/** Aktuelle Zugzahl. */
val turn: Int

/** Aktuelle Rundenzahl */
val round: Int

/** Das Team am Zug. */
val currentTeam: ITeam

Expand Down
3 changes: 0 additions & 3 deletions sdk/src/main/server-api/sc/api/plugins/TwoPlayerGameState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ abstract class TwoPlayerGameState<M: IMove>(

abstract val board: IBoard

override val round: Int
get() = (turn+1)/2

/** @return das Team, das am Zug ist. */
override val currentTeam
get() = currentTeamFromTurn()
Expand Down
2 changes: 0 additions & 2 deletions server/src/test/java/sc/server/plugins/TestGameState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ data class TestGameState(
override fun teamStats(team: ITeam) =
throw NotImplementedError("TestGame has no teamStats")

override val round get() = turn / 2

val red = Player(Team.ONE, "Fred")
val blue = Player(Team.TWO, "Marta")

Expand Down

0 comments on commit 3e8b3ba

Please sign in to comment.