Skip to content

Commit 6704b57

Browse files
committed
refactor(plugin): move isObstructed to Board & remove Corner.asSet
1 parent c31bdc4 commit 6704b57

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

plugin/src/shared/sc/plugin2021/Board.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ class Board(
1616

1717
/** Prüft, ob alle Felder leer sind. */
1818
fun isEmpty() = gameField.all { it.all { it == FieldContent.EMPTY } }
19-
19+
20+
/** Prüft, ob auf dieser [position] bereits eine Spielerfarbe liegt. */
21+
fun isObstructed(position: Coordinates): Boolean =
22+
this[position].content != FieldContent.EMPTY
23+
2024
/**
2125
* Gibt das Feld an den gegebenen Koordinaten zurück.
2226
* @see get
@@ -88,9 +92,4 @@ enum class Corner(val position: Coordinates) {
8892

8993
/** Berechne die Koordinaten, die ein Stein haben muss, um in der entsprechenden Ecke platziert zu werden. */
9094
abstract fun align(area: Vector): Coordinates
91-
92-
companion object {
93-
/** Gib eine Sammlung der vier Ecken als [Set] zurück. */
94-
fun asSet(): Set<Coordinates> = values().map { it.position }.toSet()
95-
}
9695
}

plugin/src/shared/sc/plugin2021/util/GameRuleLogic.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ object GameRuleLogic {
138138
throw InvalidMoveException("Field $it is out of bounds", move)
139139
}
140140
// Checks if a part of the piece is obstructed
141-
if (isObstructed(board, it))
141+
if (board.isObstructed(it))
142142
throw InvalidMoveException("Field $it already belongs to ${board[it].content}", move)
143143
// Checks if a part of the piece would border on another piece of same color
144144
if (bordersOnColor(board, it, move.color))
@@ -163,11 +163,6 @@ object GameRuleLogic {
163163
throw InvalidMoveException("Can't Skip on first round", SkipMove(gameState.currentColor))
164164
}
165165

166-
/** Check if the given [position] is already obstructed by another piece. */
167-
@JvmStatic
168-
private fun isObstructed(board: Board, position: Coordinates): Boolean =
169-
board[position].content != FieldContent.EMPTY
170-
171166
/** Check if the given [position] already borders on another piece of same [color]. */
172167
@JvmStatic
173168
private fun bordersOnColor(board: Board, position: Coordinates, color: Color): Boolean = listOf(
@@ -195,7 +190,7 @@ object GameRuleLogic {
195190
/** Return true if the given [Coordinates] are a corner. */
196191
@JvmStatic
197192
private fun isOnCorner(position: Coordinates): Boolean =
198-
Corner.asSet().contains(position)
193+
Corner.values().any { it.position == position }
199194

200195
/** Gib zurück, ob sich der [GameState] noch in der ersten Runde befindet. */
201196
@JvmStatic

0 commit comments

Comments
 (0)