Skip to content

Commit

Permalink
fix(plugin24): bounds in edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
xeruf committed Sep 11, 2023
1 parent ffd86e8 commit 7b56e5a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ The version should always be in sync with the [GUI](https://github.com/software-
A `y` version of 0 marks the beta of the current year
and likely contains breaking changes between patches.

### 24.1.1
- Fix segment boundaries in special cases
- Crash oversped ships
- Allow other player to move on when one is disqualified

### 24.1.0 New Helpers - 2023-09-11
- Add a few helpers

Expand Down
8 changes: 6 additions & 2 deletions plugin/src/main/kotlin/sc/plugin2024/Field.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import sc.api.plugins.IField
sealed class Field: IField<Field> {
override val isEmpty
get() = true

override fun clone() = this

override fun toString() = javaClass.simpleName
override fun toString(): String = javaClass.simpleName

val letter: Char
get() = javaClass.simpleName.first()
Expand All @@ -32,7 +33,10 @@ sealed class Field: IField<Field> {

/** Passagierfeld mit Anleger */
@XStreamAlias("passenger")
data class PASSENGER(@XStreamAsAttribute val direction: CubeDirection = CubeDirection.values().random(), @XStreamAsAttribute var passenger: Int = 1): Field() {
data class PASSENGER(
@XStreamAsAttribute val direction: CubeDirection = CubeDirection.values().random(),
@XStreamAsAttribute var passenger: Int = 1,
): Field() {
override val isEmpty
get() = false
override fun clone() = PASSENGER(direction, passenger)
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/kotlin/sc/plugin2024/GameState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ data class GameState @JvmOverloads constructor(
fun advanceTurn() {
currentShip.freeAcc = 1
currentShip.freeTurns = 1
currentShip.movement = if(board[currentShip.position] == Field.SANDBANK) 1 else currentShip.speed
currentShip.movement = currentShip.speed
turn++
currentTeam = if(turn % 2 == 0) determineAheadTeam() else currentTeam.opponent()
if(!canMove() && !isOver) {
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/kotlin/sc/plugin2024/Segment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ typealias SegmentFields = Array<Array<Field>>
typealias Segments = List<Segment>

val Segments.bounds
get() = fold(Pair(0 to 0, 0 to 0)) { acc, segment ->
get() = fold(Pair(99 to -99, 99 to -99)) { acc, segment ->
val center = segment.center
val x = center.x / 2
Pair(acc.first.first.coerceAtMost(x - 2) to acc.first.second.coerceAtLeast(x + 2),
Expand Down
5 changes: 5 additions & 0 deletions plugin/src/main/kotlin/sc/plugin2024/Ship.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ data class Ship(

fun canTurn() = freeTurns > 0 || coal > 0


/** The maximum count of points this speed is able and allowed to accelerate by. */
val maxAcc: Int
get() = (coal + freeAcc).coerceAtMost(PluginConstants.MAX_SPEED - speed)

/** Adjust speed and movement simultaneously. */
fun accelerateBy(diff: Int) {
speed += diff
Expand Down

0 comments on commit 7b56e5a

Please sign in to comment.