Orbit Rush prototype (0.119.0, versionCode 310): three lanes, Asteroid Alley, three hazards, one power-up, lane warnings, bot-checked dodgeable, zero allocation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,7 +16,7 @@ class KidsArcadeTest {
|
||||
|
||||
@Test fun grownUpsSeeEveryGame() {
|
||||
assertEquals(ArcadeGames.all.map { it.id }, ids(grown))
|
||||
assertEquals(17, ids(grown).size)
|
||||
assertEquals(18, ids(grown).size)
|
||||
// A grown-up's Arcade for Kids setting means nothing.
|
||||
assertEquals(ArcadeGames.all.map { it.id }, ids(grown.withKidsArcade(KidsArcade.Off)))
|
||||
assertEquals(ArcadeGames.all.map { it.id }, ids(null))
|
||||
@@ -70,16 +70,16 @@ class KidsArcadeTest {
|
||||
@Test fun theFamilyLineSaysWhatKidsReallySee() {
|
||||
// The audit: "On: the games chosen for Kids" promised a choice that didn't exist.
|
||||
assertEquals("Off: no Arcade for Kids", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.Off)))
|
||||
assertEquals("Kids-suitable games: 15 to play", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.KidsSuitable)))
|
||||
assertEquals("Kids-suitable games: 16 to play", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.KidsSuitable)))
|
||||
assertEquals("Chosen games: 2 to play", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.Chosen, setOf("Pairs", "Sky", "Retired"))))
|
||||
assertEquals("Chosen games: none chosen yet, so no Arcade", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.Chosen, emptySet())))
|
||||
}
|
||||
|
||||
@Test fun everyGameIsDescribed() {
|
||||
assertEquals(ArcadeGames.all.size, ArcadeGames.all.map { it.id }.toSet().size)
|
||||
assertEquals(9, ArcadeGames.originals.size); assertEquals(8, ArcadeGames.classics.size)
|
||||
assertEquals(10, ArcadeGames.originals.size); assertEquals(8, ArcadeGames.classics.size)
|
||||
// All five Originals play now (Orbiteroids, the last, 9 November 2026); every Classic does.
|
||||
assertEquals(listOf("OrbiRaiders", "ChannelChaos", "Hive", "NightShift", "Orbiteroids", "QuizNight", "TestCardTangle", "Codebreaker", "ArcadeDaily"), ArcadeGames.originals.filter { it.launchable }.map { it.id })
|
||||
assertEquals(listOf("OrbiRaiders", "ChannelChaos", "Hive", "NightShift", "Orbiteroids", "QuizNight", "TestCardTangle", "Codebreaker", "ArcadeDaily", "OrbitRush"), ArcadeGames.originals.filter { it.launchable }.map { it.id })
|
||||
assertTrue(ArcadeGames.classics.all { it.launchable })
|
||||
ArcadeGames.all.forEach { g ->
|
||||
assertTrue(g.id, g.controls.isNotEmpty()); assertTrue(g.id, g.title.isNotBlank()); assertTrue(g.id, g.goal.isNotBlank())
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package tv.orbit.classic.arcade.rush
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import tv.orbit.classic.arcade.Difficulty
|
||||
|
||||
class RushSimTest {
|
||||
private fun fresh(d: Difficulty, seed: Long = 1) = RushSim(d).also { it.newRun(d, seed) }
|
||||
|
||||
/**
|
||||
* A careful player with a reaction time: acts only once a hazard's lane warning is showing and [reaction] seconds have
|
||||
* passed since it first could have; rocks get a lane change to a lane clear of the next thing coming, low things a
|
||||
* rise, tall ones a dive, timed for the moment they arrive.
|
||||
*/
|
||||
private fun bot(s: RushSim, reaction: Float) {
|
||||
var nearest = -1
|
||||
for (i in 0 until RushSim.MAX) if (s.on[i] && s.laneOf[i] == s.lane && s.kind[i] <= RKind.TALL && (nearest < 0 || s.z[i] < s.z[nearest])) nearest = i
|
||||
if (nearest < 0) return
|
||||
val seen = (WARN - s.z[nearest]) / s.speed // seconds since its warning came on
|
||||
if (seen < reaction) return
|
||||
val t = s.z[nearest] / s.speed // seconds until it arrives
|
||||
when (s.kind[nearest]) {
|
||||
RKind.ROCK -> {
|
||||
// The lane whose next hazard is furthest off.
|
||||
var best = s.lane; var room = -1f
|
||||
for (l in 0 until LANES) if (kotlin.math.abs(l - s.lane) == 1 || l == s.lane) {
|
||||
var near = Float.MAX_VALUE
|
||||
for (i in 0 until RushSim.MAX) if (s.on[i] && s.laneOf[i] == l && s.kind[i] <= RKind.TALL) near = minOf(near, s.z[i])
|
||||
if (l != s.lane && near > room) { room = near; best = l }
|
||||
}
|
||||
if (best < s.lane) s.left() else if (best > s.lane) s.right()
|
||||
}
|
||||
RKind.LOW -> if (t < .45f && s.height != RHeight.RISE) s.rise()
|
||||
RKind.TALL -> if (t < .45f && s.height != RHeight.DIVE) s.dive()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun everyHazardCanBeDodgedInTimeOnEveryDifficulty() {
|
||||
// Three minutes each, at the fastest the run gets: a player reacting within a quarter of a second takes no hits.
|
||||
for (d in Difficulty.entries) for (seed in 1L..6L) {
|
||||
val s = fresh(d, seed); var hits = 0
|
||||
repeat(180 * 60) { bot(s, .25f); s.step(); if (s.events and REvents.HIT != 0) hits++ }
|
||||
assertEquals("$d seed $seed: hits", 0, hits); assertFalse(s.over)
|
||||
assertTrue(s.dodged > 50)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun theWarningComesSoonEnoughEvenAtFullSpeed() {
|
||||
// From the warning to arrival is at least half a second at the top speed on Tricky: time to see and press.
|
||||
val top = RushSim.MAX_SPEED * 1.18f
|
||||
assertTrue(WARN / top >= .45f)
|
||||
// And rows never come so close that a lane change and a rise can't both be done between them.
|
||||
assertTrue(.6f >= RushSim.MOVE_TIME * .8f)
|
||||
}
|
||||
|
||||
@Test fun eachHazardWantsItsOwnMove() {
|
||||
fun meet(kind: Int, act: (RushSim) -> Unit): Int {
|
||||
val s = fresh(Difficulty.Normal); for (i in 0 until RushSim.MAX) s.on[i] = false
|
||||
s.on[0] = true; s.kind[0] = kind; s.laneOf[0] = 1; s.z[0] = .1f
|
||||
act(s); s.step(); return s.hull
|
||||
}
|
||||
assertEquals(RushSim.HULL - 1, meet(RKind.ROCK) { it.rise() }) // a rock: rising doesn't help
|
||||
assertEquals(RushSim.HULL, meet(RKind.ROCK) { it.left() })
|
||||
assertEquals(RushSim.HULL, meet(RKind.LOW) { it.rise() }); assertEquals(RushSim.HULL - 1, meet(RKind.LOW) { it.dive() })
|
||||
assertEquals(RushSim.HULL, meet(RKind.TALL) { it.dive() }); assertEquals(RushSim.HULL - 1, meet(RKind.TALL) { it.rise() })
|
||||
}
|
||||
|
||||
@Test fun theShieldIsHeldUntilOkAndThenTakesHits() {
|
||||
val s = fresh(Difficulty.Normal); for (i in 0 until RushSim.MAX) s.on[i] = false
|
||||
s.on[0] = true; s.kind[0] = RKind.SHIELD; s.laneOf[0] = 1; s.z[0] = .1f; s.step()
|
||||
assertTrue(s.shieldHeld); assertTrue(s.usePower()); assertFalse(s.usePower())
|
||||
s.on[1] = true; s.kind[1] = RKind.ROCK; s.laneOf[1] = 1; s.z[1] = .1f; s.step()
|
||||
assertEquals(RushSim.HULL, s.hull)
|
||||
}
|
||||
|
||||
@Test fun threeHitsEndTheRunAndTheStormClosesIn() {
|
||||
val s = fresh(Difficulty.Normal); var t = 0
|
||||
while (!s.over && t < 60 * 120) { s.step(); t++ } // nobody steering
|
||||
assertTrue(s.over); assertEquals(0, s.hull); assertTrue(s.storm < 1f)
|
||||
}
|
||||
|
||||
@Test fun nothingIsAllocatedWhileItRuns() {
|
||||
val s = fresh(Difficulty.Normal, 3)
|
||||
repeat(2_000) { bot(s, .25f); s.step() }
|
||||
val mx = java.lang.management.ManagementFactory.getThreadMXBean() as com.sun.management.ThreadMXBean
|
||||
val before = mx.getThreadAllocatedBytes(Thread.currentThread().id)
|
||||
repeat(10_000) { bot(s, .25f); s.step(); if (s.over) s.newRun(Difficulty.Normal, 4) }
|
||||
val bytes = mx.getThreadAllocatedBytes(Thread.currentThread().id) - before
|
||||
println("Orbit Rush: 10,000 ticks allocated $bytes bytes")
|
||||
assertTrue("allocated $bytes", bytes < 8 * 1024)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user