The arcade redesigned, and Orb-Man (from 0.108.24)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class OrbManTest {
|
||||
private val maze = OrbMaze()
|
||||
private val random = java.util.Random(5)
|
||||
private fun play(g: OrbGame, ticks: Int): OrbGame { var x = g; repeat(ticks) { x = x.step(random) }; return x }
|
||||
|
||||
@Test fun theMazeIsWholeAndEveryStarCanBeReached() {
|
||||
assertTrue(maze.rows.all { it.length == maze.width })
|
||||
val open = { p: OrbPos -> !maze.wall(p) && !maze.door(p) && !maze.den(p) }
|
||||
val seen = mutableSetOf(maze.start); val queue = ArrayDeque(listOf(maze.start))
|
||||
while (queue.isNotEmpty()) { val p = queue.removeFirst(); for (d in OrbDir.entries) { val n = maze.step(p, d); if (n.y in 0 until maze.height && open(n) && seen.add(n)) queue += n } }
|
||||
assertTrue((maze.cells('.') + maze.cells('o')).all { it in seen })
|
||||
assertEquals(4, maze.cells('o').size)
|
||||
// The rocks' way out of the den leads into the maze.
|
||||
assertTrue(maze.outside in seen)
|
||||
// A tunnel through the side.
|
||||
assertEquals(OrbPos(maze.width - 1, 6), maze.step(OrbPos(0, 6), OrbDir.Left))
|
||||
}
|
||||
|
||||
@Test fun orbManEatsStarsAndTurnsWhenThereIsRoom() {
|
||||
var g = OrbGame.start(maze)
|
||||
g = play(g, OrbGame.READY_TICKS + g.playerEvery)
|
||||
assertEquals(OrbPos(maze.start.x - 1, maze.start.y), g.player.pos)
|
||||
assertEquals(10, g.score); assertTrue(OrbEvent.Star in g.events || g.score == 10)
|
||||
// Up is a wall at (8, 11): he carries on left, and goes up as soon as there's room, at (7, 11).
|
||||
val at = OrbPos(8, 11)
|
||||
g = g.copy(player = OrbMover(at, at, OrbDir.Left, g.tick), wanted = OrbDir.Up)
|
||||
g = play(g, g.playerEvery)
|
||||
assertEquals(OrbPos(7, 11), g.player.pos); assertEquals(OrbDir.Left, g.player.dir)
|
||||
g = play(g, g.playerEvery)
|
||||
assertEquals(OrbPos(7, 10), g.player.pos); assertEquals(OrbDir.Up, g.player.dir)
|
||||
}
|
||||
|
||||
@Test fun aPowerHexagonFrightensTheRocksAndCatchingOneScores() {
|
||||
val g0 = OrbGame.start(maze).copy(readyLeft = 0)
|
||||
val power = maze.cells('o').first { it.y == maze.start.y }
|
||||
// Stand next to a power hexagon, facing it.
|
||||
val beside = OrbPos(power.x + 1, power.y)
|
||||
var g = g0.copy(player = OrbMover(beside, beside, OrbDir.Left, 0), wanted = OrbDir.Left)
|
||||
g = play(g, g.playerEvery)
|
||||
assertEquals(power, g.player.pos)
|
||||
assertTrue(g.powered); assertTrue(OrbEvent.Power in g.events)
|
||||
assertTrue(g.chasers.filter { it.out }.all { it.scared })
|
||||
// A frightened rock on his square is caught, worth 200, then 400.
|
||||
val rock = g.chasers[0].copy(mover = OrbMover(g.player.pos, g.player.pos, OrbDir.Right, g.tick), scared = true, out = true)
|
||||
val next = g.copy(chasers = listOf(rock) + g.chasers.drop(1)).step(random)
|
||||
assertTrue(next.chasers[0].returning); assertEquals(1, next.chain)
|
||||
assertTrue(next.score >= g.score + 200)
|
||||
}
|
||||
|
||||
@Test fun beingCaughtCostsALifeAndTheLastOneEndsIt() {
|
||||
val g = OrbGame.start(maze).copy(readyLeft = 0)
|
||||
val rock = g.chasers[0].copy(mover = OrbMover(g.player.pos, g.player.pos, OrbDir.Left, 0))
|
||||
val after = g.copy(chasers = listOf(rock) + g.chasers.drop(1)).step(random)
|
||||
assertEquals(2, after.lives); assertEquals(maze.start, after.player.pos); assertTrue(after.readyLeft > 0)
|
||||
val last = g.copy(lives = 1, chasers = listOf(rock) + g.chasers.drop(1)).step(random)
|
||||
assertFalse(last.alive)
|
||||
}
|
||||
|
||||
@Test fun clearingTheMazeIsTheNextLevelAndQuicker() {
|
||||
val g = OrbGame.start(maze).copy(readyLeft = 0)
|
||||
val star = OrbPos(maze.start.x - 1, maze.start.y)
|
||||
val next = play(g.copy(stars = setOf(star), powers = emptySet()), g.playerEvery)
|
||||
assertEquals(2, next.level); assertTrue(OrbEvent.Cleared in next.events)
|
||||
assertEquals(maze.cells('.').size, next.stars.size)
|
||||
assertTrue(OrbGame.start(maze, level = 6).chaserEvery < g.chaserEvery)
|
||||
assertTrue(OrbGame.start(maze, level = 6).powerTicks < g.powerTicks)
|
||||
}
|
||||
|
||||
@Test fun theRocksLeaveTheDenAndHuntWithoutGettingStuck() {
|
||||
// A long game with Orb-Man somewhere they can't reach him: every rock gets out and keeps moving.
|
||||
var g = OrbGame.start(maze)
|
||||
g = g.copy(player = OrbMover(OrbPos(0, 0), OrbPos(0, 0), OrbDir.Left))
|
||||
var most = 0
|
||||
repeat(3_000) {
|
||||
g = g.step(random)
|
||||
assertTrue(g.chasers.all { !maze.wall(it.mover.pos) })
|
||||
most = maxOf(most, g.chasers.count { it.out })
|
||||
}
|
||||
assertTrue(g.alive); assertEquals(4, most)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user