Skip to content

Commit 50d6e81

Browse files
committed
style(plugin): reformat Game
1 parent 1fafc5f commit 50d6e81

File tree

1 file changed

+23
-18
lines changed
  • plugin/src/server/sc/plugin2021

1 file changed

+23
-18
lines changed

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import sc.plugin2021.util.GameRuleLogic
99
import sc.plugin2021.util.MoveMistake
1010
import sc.plugin2021.util.WinReason
1111
import sc.protocol.responses.ProtocolMessage
12-
import sc.shared.*
12+
import sc.shared.InvalidMoveException
13+
import sc.shared.PlayerScore
14+
import sc.shared.ScoreCause
15+
import sc.shared.WinCondition
1316

1417
class Game(override val currentState: GameState = GameState()): AbstractGame<Player>(GamePlugin.PLUGIN_UUID) {
1518
companion object {
@@ -18,7 +21,7 @@ class Game(override val currentState: GameState = GameState()): AbstractGame<Pla
1821

1922
private val availableTeams = mutableListOf(Team.ONE, Team.TWO)
2023
override fun onPlayerJoined(): Player {
21-
if(availableTeams.isEmpty())
24+
if (availableTeams.isEmpty())
2225
throw IllegalStateException("Too many players joined the game!")
2326
val player = currentState.getPlayer(availableTeams.removeAt(0))
2427

@@ -36,35 +39,35 @@ class Game(override val currentState: GameState = GameState()): AbstractGame<Pla
3639
}
3740
if (players.last().hasViolated())
3841
return players.subList(0, 1)
39-
42+
4043
val first = currentState.getPointsForPlayer(players.first().color)
4144
val second = currentState.getPointsForPlayer(players.last().color)
42-
45+
4346
if (first > second)
4447
return players.subList(0, 1)
4548
if (first < second)
4649
return players.subList(1, 2)
4750
return players
4851
}
49-
52+
5053
override val playerScores: MutableList<PlayerScore>
51-
get() = players.mapTo(ArrayList(players.size)) { getScoreFor(it) }
54+
get() = players.mapTo(ArrayList(players.size)) { getScoreFor(it) }
5255

5356
val isGameOver: Boolean
5457
get() = !currentState.hasValidColors() || currentState.round > Constants.ROUND_LIMIT
55-
58+
5659
/**
5760
* Checks whether and why the game is over.
5861
*
5962
* @return null if any player can still move, otherwise a WinCondition with the winner and reason.
6063
*/
6164
override fun checkWinCondition(): WinCondition? {
6265
if (!isGameOver) return null
63-
66+
6467
val scores: Map<Team, Int> = Team.values().map {
6568
it to currentState.getPointsForPlayer(it)
6669
}.toMap()
67-
70+
6871
return when {
6972
scores.getValue(Team.ONE) > scores.getValue(Team.TWO) -> WinCondition(Team.ONE, WinReason.DIFFERING_SCORES)
7073
scores.getValue(Team.ONE) < scores.getValue(Team.TWO) -> WinCondition(Team.TWO, WinReason.DIFFERING_SCORES)
@@ -86,7 +89,7 @@ class Game(override val currentState: GameState = GameState()): AbstractGame<Pla
8689

8790
override fun getScoreFor(player: Player): PlayerScore {
8891
val team = player.color as Team
89-
logger.debug("Get score for player $team (violated: ${if(player.hasViolated()) "yes" else "no"})")
92+
logger.debug("Get score for player $team (violated: ${if (player.hasViolated()) "yes" else "no"})")
9093
val opponent = currentState.getOpponent(player)
9194
val winCondition = checkWinCondition()
9295

@@ -104,9 +107,9 @@ class Game(override val currentState: GameState = GameState()): AbstractGame<Pla
104107

105108
// Opponent did something wrong
106109
if (opponent.hasViolated() && !player.hasViolated() ||
107-
opponent.hasLeft() && !player.hasLeft() ||
108-
opponent.hasSoftTimeout() ||
109-
opponent.hasHardTimeout())
110+
opponent.hasLeft() && !player.hasLeft() ||
111+
opponent.hasSoftTimeout() ||
112+
opponent.hasHardTimeout())
110113
score = Constants.WIN_SCORE
111114
else
112115
when {
@@ -147,10 +150,12 @@ class Game(override val currentState: GameState = GameState()): AbstractGame<Pla
147150
}
148151

149152
override fun toString(): String =
150-
"Game(${when {
151-
isGameOver -> "OVER, "
152-
isPaused -> "PAUSED, "
153-
else -> ""
154-
}}players=$players, gameState=$currentState)"
153+
"Game(${
154+
when {
155+
isGameOver -> "OVER, "
156+
isPaused -> "PAUSED, "
157+
else -> ""
158+
}
159+
}players=$players, gameState=$currentState)"
155160

156161
}

0 commit comments

Comments
 (0)