Skip to content

Commit 389ee94

Browse files
committed
refactor: consistently use american english "neighbor"
1 parent 3a30041 commit 389ee94

File tree

6 files changed

+55
-55
lines changed

6 files changed

+55
-55
lines changed

.old-plugins/blokus_2020/GameState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class GameState @JvmOverloads constructor(
6969
}
7070

7171
override fun getPointsForPlayer(playerColor: PlayerColor): Int {
72-
return GameRuleLogic.freeBeeNeighbours(this.board, playerColor)
72+
return GameRuleLogic.freeBeeNeighbors(this.board, playerColor)
7373
}
7474

7575
fun getPlayerStats(p: Player): IntArray {

.old-plugins/blokus_2020/util/GameRuleLogic.kt

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import kotlin.math.abs
88

99
object 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)

.old-plugins/piranhas_2019/shared/sc/plugin2019/util/GameRuleLogic.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static Set<Field> getOwnFields(Board board, PlayerColor player) {
9797
return fields;
9898
}
9999

100-
private static Set<Field> getDirectNeighbour(Board board, Field f, Set<Field> parentSet) {
100+
private static Set<Field> getDirectNeighbor(Board board, Field f, Set<Field> parentSet) {
101101
Set<Field> returnSet = new HashSet<>();
102102
for (int i = -1; i <= 1; i++) {
103103
for (int j = -1; j <= 1; j++) {
@@ -125,8 +125,8 @@ private static Set<Field> getSwarm(Board board, Set<Field> found, Set<Field> swa
125125
// O(swarm.size()) time
126126
for (Field field : swarm) {
127127
// Constant time for both calls (max of 8 neighbors)
128-
Set<Field> neighbours = getDirectNeighbour(board, field, found);
129-
tmpSwarm.addAll(neighbours);
128+
Set<Field> neighbors = getDirectNeighbor(board, field, found);
129+
tmpSwarm.addAll(neighbors);
130130
}
131131

132132
// O(found.size()*swarm.size()) time

plugin/src/main/kotlin/sc/plugin2024/Board.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,23 +182,23 @@ data class Board(
182182
*/
183183
fun findNearestFieldTypes(startCoordinates: CubeCoordinates, field: KClass<out Field>): List<CubeCoordinates> {
184184
val visitedCoordinates = mutableSetOf<CubeCoordinates>()
185-
val neighbourCoordinatesQueue = ArrayDeque<CubeCoordinates>()
185+
val neighborCoordinatesQueue = ArrayDeque<CubeCoordinates>()
186186
val nearestFieldCoordinates: MutableList<CubeCoordinates> = mutableListOf()
187187

188188
/** Prüft das [Field] an den angegebenen [CubeCoordinates] und fügt es ggf. der [ArrayDeque] hinzu. */
189189
fun checkFieldAndAddToQueue(coordinates: CubeCoordinates) {
190-
val neighbourField = this[coordinates]
191-
if(neighbourField != null && !visitedCoordinates.contains(coordinates) && !neighbourCoordinatesQueue.contains(coordinates)) {
192-
neighbourCoordinatesQueue.add(coordinates)
190+
val neighborField = this[coordinates]
191+
if(neighborField != null && !visitedCoordinates.contains(coordinates) && !neighborCoordinatesQueue.contains(coordinates)) {
192+
neighborCoordinatesQueue.add(coordinates)
193193
}
194194
}
195195

196196
CubeDirection.values().forEach { direction ->
197197
checkFieldAndAddToQueue(startCoordinates + direction.vector)
198198
}
199199

200-
while(neighbourCoordinatesQueue.isNotEmpty()) {
201-
val currentCoordinates = neighbourCoordinatesQueue.removeFirst()
200+
while(neighborCoordinatesQueue.isNotEmpty()) {
201+
val currentCoordinates = neighborCoordinatesQueue.removeFirst()
202202

203203
if(nearestFieldCoordinates.isNotEmpty() && startCoordinates.distanceTo(currentCoordinates) > startCoordinates.distanceTo(nearestFieldCoordinates.last()))
204204
break

plugin/src/test/kotlin/sc/plugin2024/BoardTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class BoardTest: FunSpec({
109109
}
110110

111111
context("pickupPassenger") {
112-
test("should decrease passenger count of the neighbouring field and increase passenger count of the ship") {
112+
test("should decrease passenger count of the neighboring field and increase passenger count of the ship") {
113113
val ship = Ship(team = Team.ONE, position = CubeCoordinates(0, 0))
114114
val nextPassengerField = board.findNearestFieldTypes(CubeCoordinates(0, 0), Field.PASSENGER::class).first()
115115
ship.position = nextPassengerField + (board[nextPassengerField] as Field.PASSENGER).direction.vector
@@ -127,7 +127,7 @@ class BoardTest: FunSpec({
127127
.filterIsInstance<Field.PASSENGER>().first().passenger shouldBe initialFieldPassengers - 1
128128
}
129129

130-
test("should return false and not change passenger count when no neighbouring passenger fields") {
130+
test("should return false and not change passenger count when no neighboring passenger fields") {
131131
val ship = Ship(team = Team.ONE, position = CubeCoordinates(0, 0))
132132

133133
val initialShipPassengers = ship.passengers

plugin2026/src/main/kotlin/sc/plugin2026/util/GameRuleLogic.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ object GameRuleLogic {
8989
.map { direction -> Move(pos, direction)}
9090
.filter { move -> checkMove(board, move) == null }
9191

92-
private fun getDirectNeighbour(f: Coordinates, parentSet: Collection<Coordinates>): Collection<Coordinates> {
92+
private fun selectNeighbors(f: Coordinates, parentSet: Collection<Coordinates>): Collection<Coordinates> {
9393
val returnSet = ArrayList<Coordinates>(8)
9494
for(i in -1..1) {
9595
for(j in -1..1) {
@@ -111,12 +111,12 @@ object GameRuleLogic {
111111
/** Called with a single fish in [swarm] and the [looseFishes] left,
112112
* recursively calling with neighbors added to [swarm] to find the whole swarm. */
113113
private fun getSwarm(looseFishes: Collection<Coordinates>, swarm: List<Coordinates>): List<Coordinates> {
114-
val swarmNeighbours =
115-
swarm.flatMap { getDirectNeighbour(it, looseFishes) }
114+
val swarmNeighbors =
115+
swarm.flatMap { selectNeighbors(it, looseFishes) }
116116

117117
// only search on if any neighbors were added
118-
if(swarmNeighbours.isNotEmpty()) {
119-
return getSwarm(looseFishes - swarmNeighbours, swarm + swarmNeighbours)
118+
if(swarmNeighbors.isNotEmpty()) {
119+
return getSwarm(looseFishes - swarmNeighbors, swarm + swarmNeighbors)
120120
}
121121
return swarm
122122
}

0 commit comments

Comments
 (0)