Skip to content

Commit 3e1fbbf

Browse files
committed
feat(plugin24): motivate simpleMove to win
1 parent d02e10e commit 3e1fbbf

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ data class GameState @JvmOverloads constructor(
6969
fun calculatePoints(ship: Ship) =
7070
board.segmentIndex(ship.position).let { segmentIndex ->
7171
segmentIndex * POINTS_PER_SEGMENT +
72-
board.segments[segmentIndex].globalToLocal(ship.position).arrayX + 1
73-
// TODO points per passenger
72+
board.segments[segmentIndex].globalToLocal(ship.position).arrayX + 1 +
73+
ship.passengers * PluginConstants.POINTS_PER_PASSENGER
7474
}
7575

7676
/**
@@ -101,9 +101,9 @@ data class GameState @JvmOverloads constructor(
101101
board.pickupPassenger(currentShip)
102102
currentShip.points = calculatePoints(currentShip)
103103
if(move.actions.any { it is Push }) {
104-
otherShip.points = calculatePoints(otherShip)
105104
if(otherShip.speed == 1)
106105
board.pickupPassenger(otherShip)
106+
otherShip.points = calculatePoints(otherShip)
107107
}
108108

109109
lastMove = move
@@ -317,7 +317,7 @@ data class GameState @JvmOverloads constructor(
317317
override val isOver: Boolean
318318
get() = when {
319319
// Bedingung 1: ein Dampfer mit 2 Passagieren erreicht ein Zielfeld mit Geschwindigkeit 1
320-
turn % 2 == 0 && ships.any { it.passengers == 2 && board.effectiveSpeed(it) < 2 && board[it.position] == Field.GOAL } -> true
320+
turn % 2 == 0 && ships.any { isWinner(it) } -> true
321321
// Bedingung 2: ein Spieler macht einen ungültigen Zug.
322322
// Das wird durch eine InvalidMoveException während des Spiels behandelt.
323323
// Bedingung 3: am Ende einer Runde liegt ein Dampfer mehr als 3 Spielsegmente zurück
@@ -328,9 +328,12 @@ data class GameState @JvmOverloads constructor(
328328
else -> false
329329
}
330330

331+
fun isWinner(ship: Ship) =
332+
ship.passengers == 2 && board.effectiveSpeed(ship) < 2 && board[ship.position] == Field.GOAL
333+
331334
override fun getPointsForTeam(team: ITeam): IntArray =
332335
ships[team.index].let { ship ->
333-
intArrayOf(ship.points, ship.coal * 2)
336+
intArrayOf(ship.points, ship.coal * 2, if(isWinner(ship)) 6 else 0)
334337
}
335338

336339
override fun clone(): GameState = copy(board = board.clone(), ships = ships.clone())

0 commit comments

Comments
 (0)