Skip to content

Commit d02e10e

Browse files
committed
fix(plugin24): do not offer impossible push moves
1 parent 128a760 commit d02e10e

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ data class GameState @JvmOverloads constructor(
143143
if(minDistance < 1)
144144
return@flatMap emptyList()
145145
(minDistance..info.distance)
146-
.map { dist ->
146+
.mapNotNull { dist ->
147147
Move(listOfNotNull(Accelerate(info.costUntil(dist) + (if(dist == info.distance && info.problem == AdvanceProblem.SHIP_ALREADY_IN_TARGET) 1 else 0) - currentShip.movement).takeUnless { it.acc == 0 || dist < 1 },
148148
turn, Advance(dist),
149149
if(currentShip.position + (direction.vector * dist) == otherShip.position) {
150150
val currentRotation = board.findSegment(otherShip.position)?.direction
151151
getPossiblePushs(otherShip.position, direction).maxByOrNull {
152152
currentRotation?.turnCountTo(it.direction)?.absoluteValue ?: 2
153-
}
153+
} ?: return@mapNotNull null
154154
} else null
155155
))
156156
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ data class Ship(
6060
): PublicCloneable<Ship> {
6161
override fun clone(): Ship =
6262
this.copy()
63+
64+
fun accelerateBy(diff: Int) {
65+
speed += diff
66+
movement += diff
67+
}
68+
6369
fun readResolve(): Ship {
6470
freeAcc = 1
6571
movement = speed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,27 @@ class GameStateTest: FunSpec({
188188
moves shouldHaveSize 3
189189
}
190190
test("costly move") {
191+
ship.accelerateBy(1)
191192
ship.coal = 0
192-
ship.speed = 2
193-
ship.movement = 2
194193
ship.freeAcc = 0
195194
ship.freeTurns = 0
196195
ship.direction = CubeDirection.DOWN_RIGHT
197196
gameState.getSensibleMoves() shouldHaveSingleElement Move(Advance(1))
198197
ship.movement = 3
199198
gameState.getSensibleMoves() shouldHaveSingleElement Move(Advance(2))
200199
}
200+
test("unpushable opponent") {
201+
val state = GameState(
202+
Board(listOf(Segment (CubeDirection.RIGHT, CubeCoordinates.ORIGIN, arrayOf(arrayOf(Field.WATER, Field.WATER, Field.WATER))))),
203+
ships = listOf(
204+
Ship(CubeCoordinates(-1, -2), Team.ONE),
205+
Ship(CubeCoordinates(-1, 0), Team.TWO),
206+
)
207+
)
208+
state.getSensibleMoves() shouldBe listOf(Move(Turn(CubeDirection.DOWN_RIGHT), Advance(1)))
209+
state.currentShip.accelerateBy(2)
210+
state.getSensibleMoves() shouldBe listOf(Move(Accelerate(-2), Turn(CubeDirection.DOWN_RIGHT), Advance(1)))
211+
}
201212
}
202213

203214
context("current works when board is truncated") {

sdk/src/main/server-api/sc/api/plugins/CubeCoordinates.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ enum class CubeDirection(val vector: CubeCoordinates) {
9595
UP_LEFT(CubeCoordinates(0, -1)),
9696
UP_RIGHT(CubeCoordinates(+1, -1));
9797

98+
val angle
99+
get() = ordinal * 60
100+
98101
/** @return an array of this and the two neighboring directions. */
99102
fun withNeighbors() = arrayOf(rotatedBy(-1), this, rotatedBy(1))
100103

0 commit comments

Comments
 (0)