Skip to content

Commit 92d19f7

Browse files
committed
enhance: general cleanups
1 parent 3adb70f commit 92d19f7

File tree

7 files changed

+22
-8
lines changed

7 files changed

+22
-8
lines changed

plugin/src/main/kotlin/sc/plugin2023/GameState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ data class GameState @JvmOverloads constructor(
3636
if(board[move.from].penguin != currentTeam)
3737
throw InvalidMoveException(MoveMistake.WRONG_COLOR, move)
3838
if(currentPieces.size < PenguinConstants.PENGUINS)
39-
throw InvalidMoveException(PenguinsMoveMistake.PENGUINS, move)
39+
throw InvalidMoveException(PenguinsMoveMistake.PLACE_PENGUINS_FIRST, move)
4040
if(!move.to.minus(move.from).straightHex)
4141
throw InvalidMoveException(MoveMistake.INVALID_MOVE, move)
4242
// TODO avoid this check

plugin/src/main/kotlin/sc/plugin2023/util/PenguinsMoveMistake.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import sc.shared.IMoveMistake
1010
*/
1111
enum class PenguinsMoveMistake(override val message: String): IMoveMistake {
1212
SINGLE_FISH("Pinguine können nur auf einzelne Fische gesetzt werden"),
13-
PENGUINS("Setze zuerst alle Pinguine"),
13+
PLACE_PENGUINS_FIRST("Setze zuerst alle Pinguine"),
1414
MAX_PENGUINS("Bereits alle Pinguine gesetzt");
1515
override fun toString() = message
1616
}

plugin2025/src/main/kotlin/sc/plugin2025/GameRuleLogic.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ object GameRuleLogic {
1010
* @param moveCount Anzahl der Felder, um die bewegt wird
1111
* @return Anzahl der benötigten Karotten
1212
*/
13+
@JvmStatic
1314
fun calculateCarrots(moveCount: Int): Int =
1415
(moveCount * (moveCount + 1)) / 2
1516

@@ -19,6 +20,7 @@ object GameRuleLogic {
1920
* @param carrots maximal ausgegebene Karotten
2021
* @return Felder um die maximal bewegt werden kann
2122
*/
23+
@JvmStatic
2224
fun calculateMoveableFields(carrots: Int): Int {
2325
return when {
2426
carrots >= 990 -> 44

plugin2025/src/main/kotlin/sc/plugin2025/GameState.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ data class GameState @JvmOverloads constructor(
9292
fun clonePlayer(team: Team = currentTeam, transform: (Hare) -> Unit = {}) =
9393
copy(players = players.map { if(it.team == team) it.clone().apply(transform) else it })
9494

95-
override fun getSensibleMoves(): List<Move> = getSensibleMoves(currentPlayer)
95+
override fun getSensibleMoves(): List<Move> =
96+
getSensibleMoves(currentPlayer)
9697

9798
fun getSensibleMoves(player: Hare): List<Move> {
9899
if(mustEatSalad(player))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package sc;
2+
3+
import sc.plugin2026.util.GameRuleLogic;
4+
5+
public class GameRuleLogicTest {
6+
public static void main(String[] args) {
7+
GameRuleLogic.possibleMovesFor(null, null).iterator();
8+
}
9+
}

sdk/src/main/server-api/sc/api/plugins/RectangularBoard.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ open class RectangularBoard<FIELD: IField<FIELD>>(
5353
/** Vergleicht zwei Spielfelder und gibt eine Liste aller Felder zurück, die sich unterscheiden. */
5454
fun compare(other: RectangularBoard<FIELD>): Collection<FIELD> {
5555
val entries = this.entries
56-
return other.entries.filter {
57-
it !in entries
58-
}.map { it.value }
56+
return other.entries
57+
.filter { it !in entries }
58+
.map { it.value }
5959
}
6060

6161
override fun toString() =
6262
gameField.joinToString(separator = "\n") { row ->
6363
row.joinToString(separator = "") { it.toString() }
6464
}.ifEmpty { "Empty Board@" + System.identityHashCode(this) }
6565

66-
override val entries: Set<Map.Entry<Coordinates, FIELD>>
66+
override val entries: Set<Positioned<FIELD>>
6767
get() = gameField.flatMapIndexedTo(HashSet()) { y, row ->
6868
row.mapIndexed { x, field ->
6969
Positioned(Coordinates(x, y), field)

sdk/src/main/server-api/sc/framework/plugins/Game.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,10 @@ abstract class AbstractGame<M : IMove>(protected val plugin: IGamePlugin<M>): IG
217217
* @return WinCondition, or null if game is not regularly over yet
218218
*/
219219
fun checkWinCondition(): WinCondition? =
220-
currentWinner().takeIf { currentState.isOver }
220+
currentState.winCondition
221221

222+
// TODO this function is useless cause it is only used when the game is over
223+
// in which case currentState.winCondition is not null anyway
222224
fun currentWinner(): WinCondition {
223225
val teams = Team.values()
224226
val scores = teams.map { currentState.getPointsForTeam(it) }

0 commit comments

Comments
 (0)