Skip to content

Commit c73bf29

Browse files
committed
fix(Game): simplify winners calculation
1 parent 340a73f commit c73bf29

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

plugin/src/server/sc/plugin2021/Game.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,11 @@ class Game(override val currentState: GameState = GameState()): AbstractGame<Pla
3131
return player
3232
}
3333

34-
override val winners: MutableList<Player>
34+
override val winners: List<Player>
3535
get() {
36-
if (players.first().hasViolated()) {
37-
if (players.last().hasViolated())
38-
return mutableListOf()
39-
return players.subList(1, 2)
40-
}
41-
if (players.last().hasViolated())
42-
return players.subList(0, 1)
36+
val compliant = players.filter { !it.hasViolated() && !it.hasLeft() }
37+
if (compliant.size < players.size)
38+
return compliant
4339

4440
val first = currentState.getPointsForPlayer(players.first().color)
4541
val second = currentState.getPointsForPlayer(players.last().color)

server/test/sc/server/gaming/GameRoomTest.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ class GameRoomTest: WordSpec({
7070
<score cause="REGULAR" reason="Game terminated">
7171
<part>0</part>
7272
</score>
73+
<winner displayName="">
74+
<color class="sc.server.helpers.TestTeam">RED</color>
75+
</winner>
76+
<winner displayName="">
77+
<color class="sc.server.helpers.TestTeam">BLUE</color>
78+
</winner>
7379
</data>
7480
</room>
7581
</protocol>

server/test/sc/server/plugins/TestGame.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ data class TestGame(
1212
override val currentState: TestGameState = TestGameState(),
1313
): AbstractGame<Player>(TestPlugin.TEST_PLUGIN_UUID) {
1414

15-
override val playerScores: List<PlayerScore> = emptyList()
16-
override val winners: List<Player> = emptyList()
15+
override val playerScores: List<PlayerScore>
16+
get() = players.map { getScoreFor(it) }
17+
18+
override val winners: List<Player>
19+
get() = players.filter { !it.hasViolated() && !it.hasLeft() }
1720

1821
override fun onRoundBasedAction(fromPlayer: Player, move: IMove) {
1922
if (move !is TestMove)

0 commit comments

Comments
 (0)