Skip to content

Commit e436db0

Browse files
TomekRDxeruf
authored andcommitted
feat(plugin26): Corrected Directions
1 parent 2a075b9 commit e436db0

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import sc.api.plugins.Team
55
import sc.framework.plugins.Constants
66
import sc.plugin2026.util.PiranhaConstants
77

8+
89
class GameRuleLogic private constructor() {
910
init {
1011
throw java.lang.IllegalStateException("Can't be instantiated.")
@@ -218,17 +219,17 @@ class GameRuleLogic private constructor() {
218219
*/
219220
fun calculateMoveDistance(board: Board, x: Int, y: Int, direction: Direction): Int {
220221
when(direction) {
221-
LEFT, RIGHT -> return moveDistanceHorizontal(board, x, y)
222-
UP, DOWN -> return moveDistanceVertical(board, x, y)
223-
UP_RIGHT, DOWN_LEFT -> return moveDistanceDiagonalRising(board, x, y)
224-
DOWN_RIGHT, UP_LEFT -> return moveDistanceDiagonalFalling(board, x, y)
222+
Direction.LEFT, Direction.RIGHT -> return moveDistanceHorizontal(board, x, y)
223+
Direction.UP, Direction.DOWN -> return moveDistanceVertical(board, x, y)
224+
Direction.UP_RIGHT, Direction.DOWN_LEFT -> return moveDistanceDiagonalRising(board, x, y)
225+
Direction.DOWN_RIGHT, Direction.UP_LEFT -> return moveDistanceDiagonalFalling(board, x, y)
225226
}
226227
return -1
227228
}
228229

229230
private fun moveDistanceHorizontal(board: Board, ignore: Int, y: Int): Int {
230231
var count = 0
231-
for(i in 0 until BOARD_SIZE) {
232+
for(i in 0 until PiranhaConstants.BOARD_LENGTH) {
232233
if(board.getField(i, y).getPiranha().isPresent()) {
233234
count++
234235
}
@@ -238,7 +239,7 @@ class GameRuleLogic private constructor() {
238239

239240
private fun moveDistanceVertical(board: Board, x: Int, ignore: Int): Int {
240241
var count = 0
241-
for(i in 0 until BOARD_SIZE) {
242+
for(i in 0 until PiranhaConstants.BOARD_LENGTH) {
242243
if(board.getField(x, i).getPiranha().isPresent()) {
243244
count++
244245
}
@@ -262,7 +263,7 @@ class GameRuleLogic private constructor() {
262263
// Move up right
263264
cX = x + 1
264265
cY = y + 1
265-
while(cX < BOARD_SIZE && cY < BOARD_SIZE) {
266+
while(cX < PiranhaConstants.BOARD_LENGTH && cY < PiranhaConstants.BOARD_LENGTH) {
266267
if(board.getField(cX, cY).getPiranha().isPresent()) {
267268
count++
268269
}
@@ -277,7 +278,7 @@ class GameRuleLogic private constructor() {
277278
var cX = x
278279
var cY = y
279280
// Move down left
280-
while(cX < BOARD_SIZE && cY >= 0) {
281+
while(cX < PiranhaConstants.BOARD_LENGTH && cY >= 0) {
281282
if(board.getField(cX, cY).getPiranha().isPresent()) {
282283
count++
283284
}
@@ -288,7 +289,7 @@ class GameRuleLogic private constructor() {
288289
// Move up right
289290
cX = x - 1
290291
cY = y + 1
291-
while(cX >= 0 && cY < BOARD_SIZE) {
292+
while(cX >= 0 && cY < PiranhaConstants.BOARD_LENGTH) {
292293
if(board.getField(cX, cY).getPiranha().isPresent()) {
293294
count++
294295
}

0 commit comments

Comments
 (0)