@@ -57,17 +57,18 @@ class GameState @JvmOverloads constructor(
5757 }
5858
5959 /* * @return Liste der noch nicht von [Color] gesetzten Steine. */
60- fun undeployedPieceShapes (color : Color = currentColor): Collection <PieceShape > = mutableUndeployedPieceShapes(color)
60+ fun undeployedPieceShapes (color : Color = currentColor): Collection <PieceShape > =
61+ mutableUndeployedPieceShapes(color)
6162
6263 fun removeUndeployedPiece (piece : Piece ) =
6364 mutableUndeployedPieceShapes(piece.color).remove(piece.kind)
6465
65- fun roundFromTurn (turn : Int ) = 1 + turn / orderedColors.size
66+ fun roundFromTurn (turn : Int ) = 1 + turn / Constants . COLORS
6667
6768 /* * Die Anzahl an bereits getätigten Zügen. */
6869 @XStreamAsAttribute
6970 override var turn: Int = turn
70- set(value) {
71+ private set(value) {
7172 if (value < 0 ) throw IndexOutOfBoundsException (" Can't go back in turns (request was $turn to $value )" )
7273 field = value
7374 round = roundFromTurn(value)
@@ -97,25 +98,27 @@ class GameState @JvmOverloads constructor(
9798 /* * Liste der Farben, die noch im Spiel sind. */
9899 private val validColors = validColors
99100
100- /* * Beendet das Spiel, indem alle Farben entfernt werden. */
101- internal fun clearValidColors () = validColors.clear()
102-
103101 /* * @return true, wenn noch Farben im Spiel sind. */
104- fun hasValidColors () = validColors.isNotEmpty()
102+ fun hasValidColors () =
103+ validColors.isNotEmpty()
105104
106- /* * Prüfe, ob die gegebene Farbe noch im Spiel ist. */
107- fun isValid (color : Color = currentColor) = validColors.contains(color)
105+ /* * @param color zu prüfende Farbe, standardmäßig die Farbe am Zug
106+ * @return ob die gegebene Farbe noch im Spiel ist. */
107+ @JvmOverloads
108+ fun isValidColor (color : Color = currentColor) =
109+ validColors.contains(color)
108110
109- /* *
110- * Versuche, zum nächsten Zug überzugehen.
111- * Schlägt fehl, wenn das Spiel bereits zu ende ist.
112- * @return Ob es erfolgreich war.
113- */
114- fun tryAdvance (turns : Int = 1): Boolean = try {
111+ /* * Geht zum Zug der nächsten noch im Spiel befindlichen Farbe über.
112+ * @param turns wie viele Züge mindestens weiter gerückt werden soll
113+ * @return ob das Spiel vorgerückt oder bereits zu Ende ist. */
114+ @JvmOverloads
115+ fun advance (turns : Int = 1): Boolean {
116+ if (! hasValidColors())
117+ return false
115118 turn + = turns
116- true
117- } catch (e : Exception ) {
118- false
119+ while ( ! isValidColor())
120+ turn ++
121+ return true
119122 }
120123
121124 fun addPlayer (player : Player ) {
@@ -135,16 +138,12 @@ class GameState @JvmOverloads constructor(
135138 return GameRuleLogic .getPointsFromUndeployed(pieces, lastMono)
136139 }
137140
138- /* *
139- * Entferne die Farbe, die momentan am Zug ist.
140- * Die resultierende aktive Farbe wird dann die des letzten Zuges sein.
141- *
142- * Diese Funktion wird von der [GameRuleLogic] benötigt und sollte nie so aufgerufen werden.
143- */
144- internal fun removeColor (color : Color = currentColor) {
145- logger.info(" Removing $color from the game" )
146- validColors.remove(color)
147- logger.debug(" Remaining Colors: $validColors " )
141+ /* * Entferne die Farbe, die momentan am Zug ist.
142+ * @return ob noch Farben im Spiel sind */
143+ internal fun removeActiveColor (): Boolean {
144+ validColors.remove(currentColor)
145+ logger.info(" Removed ${currentColor.name} from the game - remaining: [${validColors.joinToString { it.name }} ]" )
146+ return advance()
148147 }
149148
150149 override fun clone () = GameState (this )
0 commit comments