diff --git a/.dev/scopes.txt b/.dev/scopes.txt index f5b29df43..e090cfd4f 100644 --- a/.dev/scopes.txt +++ b/.dev/scopes.txt @@ -12,6 +12,7 @@ testclient player server +plugin plugin23 plugin24 gamerules diff --git a/plugin/src/main/kotlin/sc/plugin2023/GameState.kt b/plugin/src/main/kotlin/sc/plugin2023/GameState.kt index c28461c6e..d140aa4ca 100644 --- a/plugin/src/main/kotlin/sc/plugin2023/GameState.kt +++ b/plugin/src/main/kotlin/sc/plugin2023/GameState.kt @@ -66,6 +66,9 @@ data class GameState @JvmOverloads constructor( board.filterValues { it.fish == 1 }.map { Move(null, it.key) } } + override fun getAllMoves(): Iterator = + getSensibleMoves().iterator() + fun canPlacePenguin(pos: Coordinates) = !penguinsPlaced && board[pos].fish == 1 fun immovable(team: Team? = null) = diff --git a/plugin/src/main/kotlin/sc/plugin2024/GameState.kt b/plugin/src/main/kotlin/sc/plugin2024/GameState.kt index a0f10141a..f102b214b 100644 --- a/plugin/src/main/kotlin/sc/plugin2024/GameState.kt +++ b/plugin/src/main/kotlin/sc/plugin2024/GameState.kt @@ -132,6 +132,10 @@ data class GameState @JvmOverloads constructor( override fun getSensibleMoves(): List = getPossibleMoves(currentShip.coal.coerceAtMost(1)).ifEmpty { getPossibleMoves() } + /** TODO Incomplete */ + override fun getAllMoves(): Iterator = + getPossibleMoves().iterator() + // TODO this should be a Stream /** Possible simple Moves (accelerate+turn+move) using at most the given coal amount. */ fun getPossibleMoves(maxCoal: Int = currentShip.coal): List = diff --git a/plugin/src/test/kotlin/sc/plugin2024/BoardTest.kt b/plugin/src/test/kotlin/sc/plugin2024/BoardTest.kt index 442337864..6ceb09bc9 100644 --- a/plugin/src/test/kotlin/sc/plugin2024/BoardTest.kt +++ b/plugin/src/test/kotlin/sc/plugin2024/BoardTest.kt @@ -133,12 +133,12 @@ class BoardTest: FunSpec({ } test("return false when rotation mismatch") { - val board = Board(listOf(Segment(CubeDirection.RIGHT, CubeCoordinates.ORIGIN, arrayOf(arrayOf(Field.WATER, Field.WATER, Field.PASSENGER(CubeDirection.LEFT)))))) + val miniBoard = Board(listOf(Segment(CubeDirection.RIGHT, CubeCoordinates.ORIGIN, arrayOf(arrayOf(Field.WATER, Field.WATER, Field.PASSENGER(CubeDirection.LEFT)))))) val ship = Ship(CubeCoordinates.ORIGIN, Team.ONE) - board.pickupPassenger(CubeCoordinates.ORIGIN) shouldBe null - board.pickupPassenger(ship) shouldBe false - board[CubeCoordinates.ORIGIN + CubeDirection.LEFT.vector].shouldBeInstanceOf() - board.pickupPassenger(CubeCoordinates.ORIGIN + CubeDirection.LEFT.vector * 2) shouldBe Field.PASSENGER(CubeDirection.LEFT) + miniBoard.pickupPassenger(CubeCoordinates.ORIGIN) shouldBe null + miniBoard.pickupPassenger(ship) shouldBe false + miniBoard[CubeCoordinates.ORIGIN + CubeDirection.LEFT.vector].shouldBeInstanceOf() + miniBoard.pickupPassenger(CubeCoordinates.ORIGIN + CubeDirection.LEFT.vector * 2) shouldBe Field.PASSENGER(CubeDirection.LEFT) } } diff --git a/sdk/src/main/server-api/sc/api/plugins/IGameState.kt b/sdk/src/main/server-api/sc/api/plugins/IGameState.kt index bd293b969..1d6ec7426 100644 --- a/sdk/src/main/server-api/sc/api/plugins/IGameState.kt +++ b/sdk/src/main/server-api/sc/api/plugins/IGameState.kt @@ -28,10 +28,10 @@ import sc.protocol.room.RoomMessage * Zusaetzlich zu den eigentlichen Informationen koennen bestimmte * Teilinformationen abgefragt werden. */ -interface IGameState : RoomMessage, PublicCloneable { +interface IGameState: RoomMessage, PublicCloneable { /** Aktuelle Zugzahl */ val turn: Int - + /** Aktuelle Rundenzahl */ val round: Int @@ -44,8 +44,18 @@ interface IGameState : RoomMessage, PublicCloneable { /** Gibt Punktzahlen des Teams entsprechend der [ScoreDefinition] zurück. */ fun getPointsForTeam(team: ITeam): IntArray - /** Die möglichen Züge des aktuellen Teams in der aktuellen Situation. + /** Mögliche Züge des aktuellen Teams in der aktuellen Situation. * Bei manchen Spielen wird aufgrund der unüberschaubaren Zahl möglicher Züge * nur ein Ausschnitt zurückgegeben. */ - fun getSensibleMoves(): List + fun getSensibleMoves(): List { + val possibleMoves = getAllMoves() + val someMoves: MutableList = ArrayList() + while(possibleMoves.hasNext() && someMoves.size < 100) + someMoves.add(possibleMoves.next()) + return someMoves + } + + /** Eine Abfolge aller möglichen Züge des aktuellen Teams, + * nur soweit berechnet wie nötig. */ + fun getAllMoves(): Iterator } \ No newline at end of file