@@ -8,12 +8,12 @@ import kotlin.math.abs
88
99object GameRuleLogic {
1010
11- /* * @return all (up to 6) neighbouring fields of [coords]. */
11+ /* * @return all (up to 6) neighboring fields of [coords]. */
1212 @JvmStatic
13- fun getNeighbours (board : Board , coords : CubeCoordinates ): List <Field > =
13+ fun getNeighbors (board : Board , coords : CubeCoordinates ): List <Field > =
1414 Direction .values().mapNotNull {
1515 try {
16- getNeighbourInDirection (board, coords, it)
16+ getNeighborInDirection (board, coords, it)
1717 } catch (ex: IndexOutOfBoundsException ) {
1818 null
1919 }
@@ -22,7 +22,7 @@ object GameRuleLogic {
2222 /* * Gets the [Field] adjacent to [coords] in [direction].
2323 * @throws IndexOutOfBoundsException if there is no field in that direction. */
2424 @JvmStatic
25- fun getNeighbourInDirection (board : Board , coords : CubeCoordinates , direction : Direction ): Field {
25+ fun getNeighborInDirection (board : Board , coords : CubeCoordinates , direction : Direction ): Field {
2626 return board.getField(CubeCoordinates (coords.x + direction.shift(1 ).x, coords.y + direction.shift(1 ).y, coords.z + direction.shift(1 ).z))
2727 }
2828
@@ -51,16 +51,16 @@ object GameRuleLogic {
5151 }
5252
5353 /* * Whether the Bee is completely blocked.
54- * @return true iff [freeBeeNeighbours ] returns 0 */
54+ * @return true iff [freeBeeNeighbors ] returns 0 */
5555 @JvmStatic
5656 fun isBeeBlocked (board : Board , color : PlayerColor ): Boolean =
57- freeBeeNeighbours (board, color) == 0
57+ freeBeeNeighbors (board, color) == 0
5858
5959 /* * @return number of free (empty & not obstructed) fields around the Bee - -1 if no Bee has been placed. */
6060 @JvmStatic
61- fun freeBeeNeighbours (board : Board , color : PlayerColor ): Int =
61+ fun freeBeeNeighbors (board : Board , color : PlayerColor ): Int =
6262 board.fields.find { it.pieces.contains(Piece (color, PieceType .BEE )) }
63- ?.let { getNeighbours (board, it) }?.count { field -> field.isEmpty }
63+ ?.let { getNeighbors (board, it) }?.count { field -> field.isEmpty }
6464 ? : - 1
6565
6666 /* * @return true iff the given [coords] are within the Board size. */
@@ -108,7 +108,7 @@ object GameRuleLogic {
108108 if (ownedFields.isEmpty()) {
109109 val otherPlayerFields = gameState.board.fields.filter { it.owner == gameState.otherPlayerColor }
110110 if (otherPlayerFields.isNotEmpty()) {
111- if (move.destination !in otherPlayerFields.flatMap { getNeighbours (gameState.board, it.coordinates) })
111+ if (move.destination !in otherPlayerFields.flatMap { getNeighbors (gameState.board, it.coordinates) })
112112 throw InvalidMoveException (" Your first piece has to touch the piece of the other player" , move)
113113 }
114114 } else {
@@ -118,11 +118,11 @@ object GameRuleLogic {
118118 if (gameState.round >= 3 && ! gameState.hasPlayerPlacedBee() && move.piece.type != PieceType .BEE )
119119 throw InvalidMoveException (" The bee must be placed in fourth round latest" , move)
120120
121- val destinationNeighbours = getNeighbours (gameState.board, move.destination)
122- if (! destinationNeighbours .any { it.owner == gameState.currentPlayerColor })
121+ val destinationNeighbors = getNeighbors (gameState.board, move.destination)
122+ if (! destinationNeighbors .any { it.owner == gameState.currentPlayerColor })
123123 throw InvalidMoveException (" A newly placed piece must touch an own piece" , move)
124124
125- if (destinationNeighbours .any { it.owner == gameState.otherPlayerColor })
125+ if (destinationNeighbors .any { it.owner == gameState.otherPlayerColor })
126126 throw InvalidMoveException (" A newly placed piece must not touch a piece of the other player" , move)
127127 }
128128 }
@@ -174,7 +174,7 @@ object GameRuleLogic {
174174 var index = 0
175175 do {
176176 val currentField = visitedFields[index]
177- val newFields = getAccessibleNeighbours (board, currentField).filterNot { it in visitedFields }
177+ val newFields = getAccessibleNeighbors (board, currentField).filterNot { it in visitedFields }
178178 if (move.destination in newFields)
179179 return
180180 visitedFields.addAll(newFields)
@@ -189,24 +189,24 @@ object GameRuleLogic {
189189 var index = 0
190190 do {
191191 val currentField = visitedFields[index]
192- val occupiedNeighbours = getNeighbours (board, currentField.coordinates)
192+ val occupiedNeighbors = getNeighbors (board, currentField.coordinates)
193193 .filterTo(ArrayList ()) { it.pieces.isNotEmpty() }
194- occupiedNeighbours .removeAll(visitedFields)
195- visitedFields.addAll(occupiedNeighbours )
194+ occupiedNeighbors .removeAll(visitedFields)
195+ visitedFields.addAll(occupiedNeighbors )
196196 if (visitedFields.sumBy { it.pieces.size } == totalPieces)
197197 return true
198198 } while (++ index < visitedFields.size)
199199 return false
200200 }
201201
202202 @JvmStatic
203- fun getAccessibleNeighbours (board : Board , start : CubeCoordinates ) =
204- getAccessibleNeighboursExcept (board, start, null )
203+ fun getAccessibleNeighbors (board : Board , start : CubeCoordinates ) =
204+ getAccessibleNeighborsExcept (board, start, null )
205205
206206 @JvmStatic
207- fun getAccessibleNeighboursExcept (board : Board , start : CubeCoordinates , except : CubeCoordinates ? ) =
208- getNeighbours (board, start).filter { neighbour ->
209- neighbour .isEmpty && canMoveBetweenExcept(board, start, neighbour , except) && neighbour .coordinates != except
207+ fun getAccessibleNeighborsExcept (board : Board , start : CubeCoordinates , except : CubeCoordinates ? ) =
208+ getNeighbors (board, start).filter { neighbor ->
209+ neighbor .isEmpty && canMoveBetweenExcept(board, start, neighbor , except) && neighbor .coordinates != except
210210 }
211211
212212 @Throws(InvalidMoveException ::class )
@@ -221,7 +221,7 @@ object GameRuleLogic {
221221 @JvmStatic
222222 fun validateBeetleMove (board : Board , move : DragMove ) {
223223 validateDestinationNextToStart(move)
224- if ((sharedNeighboursOfTwoCoords (board, move.start, move.destination) + board.getField(move.destination) + board.getField(move.start)).all { it.pieces.isEmpty() })
224+ if ((sharedNeighborsOfTwoCoords (board, move.start, move.destination) + board.getField(move.destination) + board.getField(move.start)).all { it.pieces.isEmpty() })
225225 throw InvalidMoveException (" Beetle has to move along swarm" , move)
226226 }
227227
@@ -231,7 +231,7 @@ object GameRuleLogic {
231231 if (! twoFieldsOnOneStraight(move.start, move.destination)) {
232232 throw InvalidMoveException (" Grasshopper can only move in straight lines" , move)
233233 }
234- if (isNeighbour (move.start, move.destination)) {
234+ if (isNeighbor (move.start, move.destination)) {
235235 throw InvalidMoveException (" Grasshopper has to jump over at least one piece" , move)
236236 }
237237 if (getLineBetweenCoords(board, move.start, move.destination).any { ! it.hasOwner }) {
@@ -246,7 +246,7 @@ object GameRuleLogic {
246246 paths.add(arrayOf(move.start))
247247 do {
248248 val currentPath = paths.removeFirst()
249- val newFields = getAccessibleNeighbours (board, currentPath.last()).filterNot { it in currentPath }
249+ val newFields = getAccessibleNeighbors (board, currentPath.last()).filterNot { it in currentPath }
250250 if (currentPath.size < 3 )
251251 paths.addAll(newFields.map { currentPath + it })
252252 else if (move.destination in newFields)
@@ -282,32 +282,32 @@ object GameRuleLogic {
282282
283283 @JvmStatic
284284 fun canMoveBetweenExcept (board : Board , coords1 : CubeCoordinates , coords2 : CubeCoordinates , except : CubeCoordinates ? ): Boolean =
285- sharedNeighboursOfTwoCoords (board, coords1, coords2).filterNot { it.pieces.size == 1 && except == it.coordinates }.let { shared ->
285+ sharedNeighborsOfTwoCoords (board, coords1, coords2).filterNot { it.pieces.size == 1 && except == it.coordinates }.let { shared ->
286286 (shared.size == 1 || shared.any { it.isEmpty && ! it.isObstructed }) && shared.any { it.pieces.isNotEmpty() }
287287 }
288288
289- /* * Checks that start and destination of this [DragMove] are neighbours .
290- * @throws InvalidMoveException if start and destination are not neighbours */
289+ /* * Checks that start and destination of this [DragMove] are neighbors .
290+ * @throws InvalidMoveException if start and destination are not neighbors */
291291 @Throws(InvalidMoveException ::class )
292292 @JvmStatic
293293 fun validateDestinationNextToStart (move : DragMove ) {
294- if (! this .isNeighbour (move.start, move.destination))
294+ if (! this .isNeighbor (move.start, move.destination))
295295 throw InvalidMoveException (" Destination field is not next to start field" , move)
296296 }
297297
298298 @JvmStatic
299- fun isNeighbour (start : CubeCoordinates , destination : CubeCoordinates ): Boolean =
299+ fun isNeighbor (start : CubeCoordinates , destination : CubeCoordinates ): Boolean =
300300 start.distanceTo(destination) == 1
301301
302302 /* * @return true iff the two fields have an axis in common. */
303303 @JvmStatic
304304 fun twoFieldsOnOneStraight (coords1 : CubeCoordinates , coords2 : CubeCoordinates ): Boolean =
305305 coords1.x == coords2.x || coords1.y == coords2.y || coords1.z == coords2.z
306306
307- /* * @return the Fields (up to 2) that are neighbours of both fields. */
307+ /* * @return the Fields (up to 2) that are neighbors of both fields. */
308308 @JvmStatic
309- fun sharedNeighboursOfTwoCoords (board : Board , coords1 : CubeCoordinates , coords2 : CubeCoordinates ): Collection <Field > =
310- getNeighbours (board, coords1).intersect(getNeighbours (board, coords2))
309+ fun sharedNeighborsOfTwoCoords (board : Board , coords1 : CubeCoordinates , coords2 : CubeCoordinates ): Collection <Field > =
310+ getNeighbors (board, coords1).intersect(getNeighbors (board, coords2))
311311
312312 /* * @return true iff the current Player has to place the Bee in this round. */
313313 @JvmStatic
@@ -340,8 +340,8 @@ object GameRuleLogic {
340340
341341 return gameState.board.getFieldsOwnedBy(gameState.currentPlayerColor).flatMap { startField ->
342342 when (startField.topPiece?.type) {
343- PieceType .BEE -> this .getAccessibleNeighbours (gameState.board, startField)
344- PieceType .BEETLE -> this .getNeighbours (gameState.board, startField)
343+ PieceType .BEE -> this .getAccessibleNeighbors (gameState.board, startField)
344+ PieceType .BEETLE -> this .getNeighbors (gameState.board, startField)
345345 else -> this .getEmptyFieldsConnectedToSwarm(gameState.board)
346346 }.mapNotNull { destination: CubeCoordinates ->
347347 val move = DragMove (startField, destination)
@@ -358,16 +358,16 @@ object GameRuleLogic {
358358 @JvmStatic
359359 fun getEmptyFieldsConnectedToSwarm (board : Board ): Set <CubeCoordinates > =
360360 board.fields.filter { it.hasOwner }
361- .flatMap { this .getNeighbours (board, it).filter { it.isEmpty } }
361+ .flatMap { this .getNeighbors (board, it).filter { it.isEmpty } }
362362 .toSet()
363363
364364 @JvmStatic
365365 fun getPossibleSetMoveDestinations (board : Board , owner : PlayerColor ): Collection <CubeCoordinates > =
366366 board.getFieldsOwnedBy(owner)
367367 .asSequence()
368- .flatMap { this .getNeighbours (board, it).asSequence() }
368+ .flatMap { this .getNeighbors (board, it).asSequence() }
369369 .filter { it.isEmpty }
370- .filter { this .getNeighbours (board, it).all { it.owner != owner.opponent() } }
370+ .filter { this .getNeighbors (board, it).all { it.owner != owner.opponent() } }
371371 .toSet()
372372
373373 @JvmStatic
@@ -380,7 +380,7 @@ object GameRuleLogic {
380380 gameState.board.fields.filter { it.isEmpty }
381381 } else {
382382 gameState.board.getFieldsOwnedBy(gameState.otherPlayerColor)
383- .flatMap { getNeighbours (gameState.board, it).filter { it.isEmpty } }
383+ .flatMap { getNeighbors (gameState.board, it).filter { it.isEmpty } }
384384 }
385385 } else {
386386 this .getPossibleSetMoveDestinations(gameState.board, gameState.currentPlayerColor)
0 commit comments