Skip to content

Commit 2a075b9

Browse files
TomekRDxeruf
authored andcommitted
feat(plugin26): Replaced PlayerColor with Team and BOARD_SIZE with BOARD_LENGTH
1 parent c0b5697 commit 2a075b9

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sc.plugin2026
22

33
import sc.api.plugins.Direction
44
import sc.api.plugins.Team
5+
import sc.framework.plugins.Constants
56
import sc.plugin2026.util.PiranhaConstants
67

78
class GameRuleLogic private constructor() {
@@ -17,7 +18,7 @@ class GameRuleLogic private constructor() {
1718
*/
1819
fun getPossibleMoves(state: sc.plugin2026.GameState): java.util.ArrayList<Move> {
1920
val possibleMoves = java.util.ArrayList<Move>()
20-
val fields: Collection<Field> = getOwnFields(state.board, state.getCurrentPlayerColor())
21+
val fields: Collection<Field> = getOwnFields(state.board, state.getCurrentTeam())
2122
for(field in fields) {
2223
for(direction in Direction.values()) {
2324
val x = field.x
@@ -32,7 +33,7 @@ class GameRuleLogic private constructor() {
3233
} catch(ignore: InvalidMoveException) {
3334
/**TODO PiranhaMoveMistake for InvalidMoveException? because InvalidMoveException
3435
* is missing in skd shared
35-
* /
36+
*/
3637
}
3738
}
3839
}
@@ -47,11 +48,11 @@ class GameRuleLogic private constructor() {
4748
direction: Direction,
4849
distance: Int
4950
): Boolean {
50-
if(x >= Constants.BOARD_SIZE || y >= Constants.BOARD_SIZE || x < 0 || y < 0) throw InvalidMoveException("x or y are not within the field range")
51+
if(x >= PiranhaConstants.BOARD_LENGTH || y >= PiranhaConstants.BOARD_LENGTH || x < 0 || y < 0) throw InvalidMoveException("x or y are not within the field range")
5152
val board = state.board
5253
val curField: Field = board.getField(x, y)
53-
val curFieldPlayer: java.util.Optional<PlayerColor> = curField.piranha
54-
if(!curFieldPlayer.isPresent() || curFieldPlayer.get() !== state.getCurrentPlayerColor()) {
54+
val curFieldPlayer: java.util.Optional<Team> = curField.piranha
55+
if(!curFieldPlayer.isPresent() || curFieldPlayer.get() !== state.getCurrentTeam()) {
5556
throw InvalidMoveException("Field does not belong to the current player")
5657
}
5758

@@ -73,16 +74,16 @@ class GameRuleLogic private constructor() {
7374

7475
val fieldsInDirection = getFieldsInDirection(board, x, y, direction)
7576

76-
val opponentFieldColor = FieldState.from(state.getCurrentPlayerColor().opponent())
77+
val opponentFieldColor = FieldState.from(state.getCurrentTeam().opponent())
7778

7879
for(f in fieldsInDirection) {
7980
if(f.state == opponentFieldColor) {
8081
throw InvalidMoveException("Path to the new position is not clear")
8182
}
8283
}
8384

84-
val nextFieldPlayer: java.util.Optional<PlayerColor> = nextField.piranha
85-
if(nextFieldPlayer.isPresent() && nextFieldPlayer.get() === state.getCurrentPlayerColor()) {
85+
val nextFieldPlayer: java.util.Optional<Team> = nextField.piranha
86+
if(nextFieldPlayer.isPresent() && nextFieldPlayer.get() === state.getCurrentTeam()) {
8687
throw InvalidMoveException("Field obstructed with own piranha")
8788
}
8889
if(nextField.isObstructed) {
@@ -91,13 +92,13 @@ class GameRuleLogic private constructor() {
9192
return true
9293
}
9394

94-
fun getOwnFields(board: Board, player: PlayerColor?): Set<Field> {
95+
fun getOwnFields(board: Board, player: Team?): Set<Field> {
9596
val fields: MutableSet<Field> = java.util.HashSet()
9697
var size = 0
9798
var i = 0
98-
while(i < BOARD_LENGTH && MAX_FISH > size) {
99+
while(i < PiranhaConstants.BOARD_LENGTH && MAX_FISH > size) {
99100
var j = 0
100-
while(j < BOARD_SIZE && MAX_FISH > size) {
101+
while(j < PiranhaConstants.BOARD_LENGTH && MAX_FISH > size) {
101102
val curField: Field = board.getField(i, j)
102103
if(curField.piranha.isPresent() && curField.piranha.get().equals(player)) {
103104
fields.add(curField)
@@ -116,7 +117,7 @@ class GameRuleLogic private constructor() {
116117
for(j in -1..1) {
117118
val x = f.x + i
118119
val y = f.y + j
119-
if(x < 0 || x >= Constants.BOARD_SIZE || y < 0 || y >= Constants.BOARD_SIZE || (i == 0 && j == 0)) continue
120+
if(x < 0 || x >= PiranhaConstants.BOARD_LENGTH || y < 0 || y >= PiranhaConstants.BOARD_LENGTH || (i == 0 && j == 0)) continue
120121

121122
val field: Field = board.getField(x, y)
122123
if(parentSet.contains(field)) {
@@ -170,20 +171,20 @@ class GameRuleLogic private constructor() {
170171
return greatestSwarm
171172
}
172173

173-
fun greatestSwarm(board: Board, player: PlayerColor?): Set<Field> {
174+
fun greatestSwarm(board: Board, player: Team?): Set<Field> {
174175
val occupiedFields = getOwnFields(board, player)
175176
return greatestSwarm(board, occupiedFields)
176177
}
177178

178-
fun greatestSwarmSize(board: Board, player: PlayerColor?): Int {
179+
fun greatestSwarmSize(board: Board, player: Team?): Int {
179180
return greatestSwarm(board, player).size
180181
}
181182

182183
fun greatestSwarmSize(board: Board, set: Set<Field?>): Int {
183184
return greatestSwarm(board, set).size
184185
}
185186

186-
fun isSwarmConnected(board: Board, player: PlayerColor?): Boolean {
187+
fun isSwarmConnected(board: Board, player: Team?): Boolean {
187188
val fieldsWithFish = getOwnFields(board, player)
188189
val numGreatestSwarm: Int = greatestSwarmSize(board, fieldsWithFish)
189190
return numGreatestSwarm == fieldsWithFish.size

0 commit comments

Comments
 (0)