Skip to content

Commit ea50632

Browse files
committed
feat(plugin24): allow omitting movement checks
1 parent a556b1b commit ea50632

File tree

12 files changed

+24
-21
lines changed

12 files changed

+24
-21
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ import sc.shared.IMoveMistake
55

66
@XStreamAlias(value = "action")
77
interface Action {
8-
fun perform(state: GameState): IMoveMistake?
8+
fun perform(state: GameState, movementCheck: Boolean = true): IMoveMistake?
99
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ data class GameState @JvmOverloads constructor(
302302

303303
result.add(totalCost)
304304
}
305-
return result(AdvanceProblem.NO_MOVEMENT_POINTS)
305+
return result(AdvanceProblem.MOVEMENT_POINTS_MISSING)
306306
}
307307

308308
/**

plugin/src/main/kotlin/sc/plugin2024/actions/Accelerate.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ data class Accelerate(
3838
* @param state [GameState], auf dem die Beschleunigung ausgeführt wird
3939
* @param ship [Ship], für welches die Beschleunigung ausgeführt wird
4040
*/
41-
override fun perform(state: GameState): AccelerationProblem? {
41+
override fun perform(state: GameState, movementCheck: Boolean): AccelerationProblem? {
4242
var speed: Int = state.currentShip.speed
4343
speed += acc
4444
when {

plugin/src/main/kotlin/sc/plugin2024/actions/Advance.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ data class Advance(
3131
@XStreamAsAttribute val distance: Int,
3232
): Action {
3333

34-
override fun perform(state: GameState): AdvanceProblem? {
34+
override fun perform(state: GameState, movementCheck: Boolean): AdvanceProblem? {
3535
if(distance < 1 && state.board[state.currentShip.position] != Field.SANDBANK || distance > 6)
3636
return AdvanceProblem.INVALID_DISTANCE
3737

3838
val result = state.checkAdvanceLimit(state.currentShip.position, if(distance > 0) state.currentShip.direction else state.currentShip.direction.opposite(), state.currentShip.movement)
39-
if(result.distance < distance.absoluteValue)
39+
if(result.distance < distance.absoluteValue && movementCheck)
4040
return result.problem
4141

4242
state.currentShip.position += state.currentShip.direction.vector * distance

plugin/src/main/kotlin/sc/plugin2024/actions/Push.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ data class Push(
3333
@XStreamAsAttribute val direction: CubeDirection,
3434
): Action {
3535

36-
override fun perform(state: GameState): PushProblem? {
36+
override fun perform(state: GameState, movementCheck: Boolean): PushProblem? {
3737
val nudgedShip = state.otherShip
3838

39-
if(state.currentShip.movement == 0)
40-
return PushProblem.MOVEMENT_POINTS_EXCEEDED
39+
if(state.currentShip.movement == 0 && movementCheck)
40+
return PushProblem.MOVEMENT_POINTS_MISSING
4141
state.currentShip.movement--
4242

4343
val pushFrom: CubeCoordinates = state.currentShip.position

plugin/src/main/kotlin/sc/plugin2024/actions/Turn.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ data class Turn(
2727
@XStreamAsAttribute val direction: CubeDirection,
2828
): Action {
2929

30-
override fun perform(state: GameState): TurnProblem? {
30+
override fun perform(state: GameState, movementCheck: Boolean): TurnProblem? {
3131
val turnCount = state.currentShip.direction.turnCountTo(direction)
3232

3333
val absTurnCount = turnCount.absoluteValue

plugin/src/main/kotlin/sc/plugin2024/mistake/AdvanceProblem.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package sc.plugin2024.mistake
33
import sc.shared.IMoveMistake
44

55
enum class AdvanceProblem(override val message: String) : IMoveMistake {
6-
NO_MOVEMENT_POINTS("Keine Bewegungspunkte mehr vorhanden"),
6+
MOVEMENT_POINTS_MISSING("Nicht genug Bewegungspunkte."),
77
INSUFFICIENT_PUSH("Nicht genug Bewegungspunkte für notwendige nachfolgende Abdrängaktion."),
88
INVALID_DISTANCE("Zurückzulegende Distanz ist ungültig."),
99
SHIP_ALREADY_IN_TARGET("Kann nicht durch einen Gegner ziehen."),

plugin/src/main/kotlin/sc/plugin2024/mistake/PushProblem.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package sc.plugin2024.mistake
33
import sc.shared.IMoveMistake
44

55
enum class PushProblem(override val message: String): IMoveMistake {
6-
MOVEMENT_POINTS_EXCEEDED("Keine Bewegungspunkte mehr vorhanden"),
6+
MOVEMENT_POINTS_MISSING("Nicht genug Bewegungspunkte."),
77
SAME_FIELD_PUSH("Um einen Spieler abzudrängen muss man sich auf demselben Feld wie der Spieler befinden."),
88
INVALID_FIELD_PUSH("Ein Spieler darf nicht auf ein nicht vorhandenes (oder nicht sichtbares) Feld abgedrängt werden."),
99
BLOCKED_FIELD_PUSH("Ein Spieler darf nicht auf ein blockiertes Feld abgedrängt werden."),

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AdvanceTest: FunSpec({
3737
test("across current") {
3838
shouldThrow<InvalidMoveException> {
3939
gameState.performMoveDirectly(Move(Turn(CubeDirection.DOWN_RIGHT), Advance(1)))
40-
}.mistake shouldBe AdvanceProblem.NO_MOVEMENT_POINTS
40+
}.mistake shouldBe AdvanceProblem.MOVEMENT_POINTS_MISSING
4141
listOf(1, 2, 3).forAll {
4242
val state = gameState.performMove(Move(Accelerate(it), Advance(it)))
4343
(state as GameState).otherShip.position shouldBe CubeCoordinates(-1, it - 1)
@@ -50,7 +50,7 @@ class AdvanceTest: FunSpec({
5050
shipONE.position = CubeCoordinates.ORIGIN
5151
shouldThrow<InvalidMoveException> {
5252
gameState.performMoveDirectly(Move(Advance(1)))
53-
}.mistake shouldBe AdvanceProblem.NO_MOVEMENT_POINTS
53+
}.mistake shouldBe AdvanceProblem.MOVEMENT_POINTS_MISSING
5454
listOf(1, 2).forAll {
5555
val state = gameState.performMove(Move(Accelerate(it), Advance(it)))
5656
(state as GameState).otherShip.position shouldBe CubeCoordinates(it, 0)
@@ -59,14 +59,14 @@ class AdvanceTest: FunSpec({
5959
test("double crossing") {
6060
shouldThrow<InvalidMoveException> {
6161
gameState.performMove(Move(Accelerate(4), Turn(CubeDirection.DOWN_RIGHT), Advance(2), Turn(CubeDirection.UP_RIGHT), Advance(2)))
62-
}.mistake shouldBe AdvanceProblem.NO_MOVEMENT_POINTS
62+
}.mistake shouldBe AdvanceProblem.MOVEMENT_POINTS_MISSING
6363
gameState.performMoveDirectly(Move(Accelerate(5), Turn(CubeDirection.DOWN_RIGHT), Advance(2), Turn(CubeDirection.UP_RIGHT), Advance(2)))
6464
shipONE.position shouldBe CubeCoordinates(1, -1)
6565
}
6666
}
6767

6868
test("no movement points") {
69-
Advance(3).perform(gameState) shouldBe AdvanceProblem.NO_MOVEMENT_POINTS
69+
Advance(3).perform(gameState) shouldBe AdvanceProblem.MOVEMENT_POINTS_MISSING
7070
}
7171

7272
context("invalid distance") {
@@ -118,7 +118,7 @@ class AdvanceTest: FunSpec({
118118
dest != null && dest.isEmpty
119119
} ?: throw IllegalStateException("No valid direction found.")
120120

121-
Advance(2).perform(gameState) shouldBe AdvanceProblem.NO_MOVEMENT_POINTS
121+
Advance(2).perform(gameState) shouldBe AdvanceProblem.MOVEMENT_POINTS_MISSING
122122
}
123123

124124
context("on opponent") {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class GameStateTest: FunSpec({
8686

8787
gameState.checkAdvanceLimit(ship).run {
8888
distance shouldBe 0
89-
problem shouldBe AdvanceProblem.NO_MOVEMENT_POINTS
89+
problem shouldBe AdvanceProblem.MOVEMENT_POINTS_MISSING
9090
}
9191

9292
ship.speed = 3
@@ -213,9 +213,9 @@ class GameStateTest: FunSpec({
213213
test("merges duplicate advances") {
214214
straightState.currentShip.position = CubeCoordinates.ORIGIN
215215
val actions = arrayOf(Turn(CubeDirection.RIGHT), Turn(CubeDirection.UP_RIGHT), Turn(CubeDirection.RIGHT), Advance(1))
216-
shouldThrow<InvalidMoveException> { straightState.performMove(Move(*actions)) }.mistake shouldBe AdvanceProblem.NO_MOVEMENT_POINTS
216+
shouldThrow<InvalidMoveException> { straightState.performMove(Move(*actions)) }.mistake shouldBe AdvanceProblem.MOVEMENT_POINTS_MISSING
217217
straightState.performMove(Move(Accelerate(1), *actions))
218-
shouldThrow<InvalidMoveException> { straightState.performMove(Move(*actions)) }.mistake shouldBe AdvanceProblem.NO_MOVEMENT_POINTS
218+
shouldThrow<InvalidMoveException> { straightState.performMove(Move(*actions)) }.mistake shouldBe AdvanceProblem.MOVEMENT_POINTS_MISSING
219219
straightState.performMove(Move(Accelerate(2), *actions, Advance(1)))
220220
straightState.performMoveDirectly(Move(Accelerate(2), *actions, Advance(1), Turn(CubeDirection.DOWN_RIGHT)))
221221
straightState.otherShip.run {
@@ -246,7 +246,7 @@ class GameStateTest: FunSpec({
246246
state.performMove(Move(Accelerate(3), Advance(4)))
247247
state.performMove(Move(Accelerate(4), Advance(5)))
248248
shouldThrow<InvalidMoveException> { state.performMove(Move(Accelerate(2), Advance(3))) }.mistake shouldBe MoveMistake.MOVEMENT_POINTS_LEFT
249-
shouldThrow<InvalidMoveException> { state.performMove(Move(Accelerate(2), Advance(4))) }.mistake shouldBe AdvanceProblem.NO_MOVEMENT_POINTS
249+
shouldThrow<InvalidMoveException> { state.performMove(Move(Accelerate(2), Advance(4))) }.mistake shouldBe AdvanceProblem.MOVEMENT_POINTS_MISSING
250250
}
251251
}
252252
}

0 commit comments

Comments
 (0)