From 9cd43b1e40f1e459287e40007a705858c6dd3ddf Mon Sep 17 00:00:00 2001 From: Pauljd Date: Mon, 9 Nov 2026 09:50:02 +0000 Subject: [PATCH] Classic Challenges (0.113.0, versionCode 303): Blast Off's twenty hand-made challenges; Skydoku, Block Drop, Patience and Pairs modes complete - Blast Off: twenty numbered boards with line targets and shape limits, same shapes each try, all beaten by a test bot - Mode button shows the whole mode name; title buttons 230 dp, Play Again 180 dp - Every mode its own High Scores table; Classic tables, kinds and Household keys unchanged Co-Authored-By: Claude Opus 5.5 --- android/app/build.gradle.kts | 4 +- .../java/tv/orbit/classic/ArcadeBlastOff.kt | 76 ++++++++++++++++--- .../java/tv/orbit/classic/ArcadeBlockDrop.kt | 2 +- .../java/tv/orbit/classic/BlastChallenges.kt | 66 ++++++++++++++++ .../tv/orbit/classic/arcade/ArcadeStore.kt | 4 + .../tv/orbit/classic/arcade/ClassicKit.kt | 7 +- .../tv/orbit/classic/BlastChallengesTest.kt | 64 ++++++++++++++++ .../tv/orbit/classic/arcade/ModeTablesTest.kt | 12 +++ .../orbit/classic/arcade/TitleTextFitsTest.kt | 24 ++++-- docs/classics-modes.md | 22 ++++++ 10 files changed, 256 insertions(+), 25 deletions(-) create mode 100644 android/app/src/main/java/tv/orbit/classic/BlastChallenges.kt create mode 100644 android/app/src/test/java/tv/orbit/classic/BlastChallengesTest.kt diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 160f9176..7493b598 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -9,8 +9,8 @@ android { applicationId = "tv.orbit.classic" minSdk = 26 targetSdk = 36 - versionCode = 302 - versionName = "0.112.0-signal-run" + versionCode = 303 + versionName = "0.113.0-classic-challenges" } buildFeatures { compose = true } // The finished build for the TVs (Paul, 6 November 2026: the test build stuttered on the box). Not debuggable, so diff --git a/android/app/src/main/java/tv/orbit/classic/ArcadeBlastOff.kt b/android/app/src/main/java/tv/orbit/classic/ArcadeBlastOff.kt index eb57ee99..c34ed584 100644 --- a/android/app/src/main/java/tv/orbit/classic/ArcadeBlastOff.kt +++ b/android/app/src/main/java/tv/orbit/classic/ArcadeBlastOff.kt @@ -15,6 +15,7 @@ import tv.orbit.classic.arcade.HudValue import tv.orbit.classic.arcade.Mascot import tv.orbit.classic.arcade.gameKeys import tv.orbit.classic.arcade.previousLine +import tv.orbit.classic.arcade.BLAST_CHALLENGE_SCORES import tv.orbit.classic.arcade.ArcadePlay import tv.orbit.classic.arcade.PauseWhenHidden @@ -199,6 +200,12 @@ internal fun BlastOffScreen(play: ArcadePlay) { var paused by remember { mutableStateOf(false) } var howTo by remember { mutableStateOf(false) } var bestBefore by remember { mutableIntStateOf(play.best) } + // Classic, or the twenty numbered Challenges (Phase 2): chosen on the title and remembered. + var challenge by remember { mutableStateOf(play.level["mode"] == "Challenge") } + var cleared by remember { mutableIntStateOf(play.level["challenge.cleared"]?.toIntOrNull() ?: 0) } + var crun by remember { mutableStateOf(null) } + var crandom by remember { mutableStateOf(java.util.Random(1)) } + var picked by remember { mutableIntStateOf(1) } val focus = remember { FocusRequester() } val backdrop = ArcadeLook.forGame(gameDef.id) // Holding OK places one shape, not one after another (audit finding 8). @@ -206,9 +213,25 @@ internal fun BlastOffScreen(play: ArcadePlay) { fun pause() { paused = true; guard.reset() } PauseWhenHidden(stage == ClassicStage.Play && !paused) { pause() } val run = rememberRun(play.onRunEnd) { RunEnd(game.score, finished = false) } - fun startRun() { bestBefore = latestPlay.best; game = BlastGame.start(random); guard.reset(); run.begin(); paused = false; stage = ClassicStage.Play } - fun leave() { run.end(RunEnd(game.score, finished = !game.alive)); latestPlay.onLeave() } - LaunchedEffect(game.alive) { if (!game.alive && stage == ClassicStage.Play) { run.end(RunEnd(game.score, finished = true)); stage = ClassicStage.Result } } + fun startRun() { crun = null; bestBefore = latestPlay.best; game = BlastGame.start(random); guard.reset(); run.begin(); paused = false; stage = ClassicStage.Play } + fun startChallenge(n: Int) { + val c = BlastChallenges[(n - 1).coerceIn(0, BlastChallenges.size - 1)] + val (r, rnd) = BlastRun.start(c) + picked = c.number; crun = r; crandom = rnd; game = r.game; guard.reset(); paused = false; stage = ClassicStage.Play + } + fun leave() { if (crun == null) run.end(RunEnd(game.score, finished = !game.alive)); latestPlay.onLeave() } + LaunchedEffect(game.alive) { if (crun == null && !game.alive && stage == ClassicStage.Play) { run.end(RunEnd(game.score, finished = true)); stage = ClassicStage.Result } } + // A challenge is over when its target is reached, or there are no shapes or no room left. Clearing one saves how far you've got. + LaunchedEffect(crun?.over) { + val r = crun ?: return@LaunchedEffect + if (!r.over || stage != ClassicStage.Play) return@LaunchedEffect + if (r.won && r.challenge.number > cleared) { + cleared = r.challenge.number + latestPlay.setLevel("challenge.cleared", cleared.toString()) + latestPlay.onRunEndIn(BLAST_CHALLENGE_SCORES, RunEnd(cleared, finished = true, detail = r.challenge.name)) + } + stage = ClassicStage.Result + } LaunchedEffect(stage, paused) { if (stage == ClassicStage.Play && !paused) runCatching { focus.requestFocus() } } // Zip zooms past on a combo; the flight stops while paused (it used to run on behind the pause menu). var zipAt by remember { mutableLongStateOf(-1L) } @@ -218,18 +241,26 @@ internal fun BlastOffScreen(play: ArcadePlay) { val start = withFrameMillis { it } - now while (true) { val t = withFrameMillis { it } - start; now = t; if (t > 1_200) { zipAt = -1; now = 0; break } } } - BackHandler(stage == ClassicStage.Play && !paused) { if (game.inTray) game = game.move(0, -1) else pause() } + fun setGame(next: BlastGame) { game = next; crun = crun?.moved(next) } + BackHandler(stage == ClassicStage.Play && !paused) { if (game.inTray) setGame(game.move(0, -1)) else pause() } if (stage == ClassicStage.Title) { - ClassicTitle(gameDef, backdrop, ArcadeColours.Pink, "Fit them in, light them up!", listOf("Your best" to if (play.best > 0) "%,d".format(play.best) else "Not played yet"), + val nextUp = minOf(cleared + 1, BlastChallenges.size) + if (challenge) ClassicTitle(gameDef, backdrop, ArcadeColours.Pink, "Twenty boards. Can you clear them all?", + listOf("Cleared" to "$cleared of ${BlastChallenges.size}"), timed = false, difficulty = play.difficulty, refocus = !howTo, + playLabel = "Challenge $nextUp", onPlay = { startChallenge(nextUp) }, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() }, + mode = "Challenges", modes = 2, onMode = { challenge = false; latestPlay.setLevel("mode", "Classic") }, + note = "Each board is made by hand, with a target: clear so many lines with so many shapes. The shapes come in the same order every try, so you can learn it. Next: ${BlastChallenges[nextUp - 1].name}, ${BlastChallenges[nextUp - 1].lines} lines in ${BlastChallenges[nextUp - 1].pieces} shapes.") + else ClassicTitle(gameDef, backdrop, ArcadeColours.Pink, "Fit them in, light them up!", listOf("Your best" to if (play.best > 0) "%,d".format(play.best) else "Not played yet"), timed = false, difficulty = play.difficulty, refocus = !howTo, onPlay = ::startRun, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() }, + mode = "Classic", modes = 2, onMode = { challenge = true; latestPlay.setLevel("mode", "Challenge") }, note = "Clear lines on placings in a row for a combo: it multiplies every clear.") if (howTo) HowToPlayCard(gameDef, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false }) return } val keys = Modifier.focusRequester(focus).focusable().gameKeys(enabled = stage == ClassicStage.Play && !paused, // Back by context: choosing in the tray, Back goes back to the board with the shape you had; on the board it pauses. - active = { game.inTray }, cancel = { game = game.move(0, -1) }, pause = ::pause) { key, native -> + active = { game.inTray }, cancel = { setGame(game.move(0, -1)) }, pause = ::pause) { key, native -> // Releases are always noted, so the guard knows OK was let go even if the game paused meanwhile. if (native.action == KeyEvent.ACTION_UP) { guard.accept(native); return@gameKeys false } if (native.action != KeyEvent.ACTION_DOWN || !game.alive) return@gameKeys false @@ -238,10 +269,14 @@ internal fun BlastOffScreen(play: ArcadePlay) { ArcadeKey.Right -> game.move(1, 0) ArcadeKey.Up -> game.move(0, -1) ArcadeKey.Down -> game.move(0, 1) - ArcadeKey.Ok -> if (!guard.accept(native)) game else game.press(random).also { if (it.lastCleared >= 2 || it.streak >= 2) { now = 0; zipAt = System.currentTimeMillis() } } + ArcadeKey.Ok -> if (!guard.accept(native)) game else { + // A challenge counts its shapes and lines as they're placed; Classic plays on as before. + val r = crun + if (r != null) { val after = r.press(crandom); crun = after; after.game } else game.press(random) + }.also { if (it.lastCleared >= 2 || it.streak >= 2) { now = 0; zipAt = System.currentTimeMillis() } } else -> null } - if (next != null) game = next + if (next != null) { if (key == ArcadeKey.Ok) game = next else setGame(next) } next != null } Box(Modifier.fillMaxSize()) { @@ -249,6 +284,15 @@ internal fun BlastOffScreen(play: ArcadePlay) { footer = if (game.inTray) listOf(Control("◀▶", "Choose a shape"), Control("OK", "Take it"), Control("▲", "Back to the board"), Control("Back", "Back to the board")) else listOf(Control("◀▶▲▼", "Move the shape"), Control("OK", "Place it"), Control("▼", "Off the board: the tray"), Control("Back", "Pause")), hud = { + val r = crun + if (r != null) { + HudLabel("CHALLENGE ${r.challenge.number}") + Text(r.challenge.name, color = ArcadeColours.Ink, fontSize = 16.sp, fontWeight = FontWeight.SemiBold) + Spacer(Modifier.height(6.dp)) + HudLabel("LINES"); HudValue("${r.lines} of ${r.challenge.lines}", if (r.won) ArcadeColours.Green else ArcadeColours.Ink) + HudLabel("SHAPES LEFT"); HudValue("${r.shapesLeft}", if (r.shapesLeft <= 3) ArcadeColours.Red else ArcadeColours.Ink) + return@ClassicPlayFrame + } HudLabel("SCORE"); HudValue("%,d".format(game.score)) HudLabel("BEST"); HudValue("%,d".format(maxOf(bestBefore, game.score))) Spacer(Modifier.height(6.dp)) @@ -278,10 +322,20 @@ internal fun BlastOffScreen(play: ArcadePlay) { drawOrbChaser(at, r, OrbCharacter.Zip, OrbDir.Left, false, false, false, 0f) } } - if (stage == ClassicStage.Result) ClassicResult(gameDef, "BLAST OFF · NO ROOM LEFT", "SCORE", "%,d".format(game.score), + val cr = crun + if (stage == ClassicStage.Result && cr != null) { + val last = cr.challenge.number == BlastChallenges.size + if (cr.won) ClassicResult(gameDef, "BLAST OFF · CHALLENGE ${cr.challenge.number} · ${cr.challenge.name.uppercase()}", "LINES", "${cr.lines} of ${cr.challenge.lines}", newBest = false, + previous = "With ${cr.shapesLeft} shapes to spare", detail = if (last) "All ${BlastChallenges.size} cleared!" else "Next: ${BlastChallenges[cr.challenge.number].name}", + heading = "CLEARED!", againLabel = if (last) "Play it again" else "Next board", cheer = Mascot.Zip, + onAgain = { startChallenge(if (last) cr.challenge.number else cr.challenge.number + 1) }, extra = if (last) null else "Try again" to { startChallenge(cr.challenge.number) }, onBack = ::leave) + else ClassicResult(gameDef, "BLAST OFF · CHALLENGE ${cr.challenge.number} · ${cr.challenge.name.uppercase()}", "LINES", "${cr.lines} of ${cr.challenge.lines}", newBest = false, + previous = if (cr.game.alive) "Out of shapes" else "No room left", detail = "The shapes come in the same order: try another way.", heading = "NOT QUITE", + againLabel = "Try again", cheer = Mascot.Drift, onAgain = { startChallenge(cr.challenge.number) }, onBack = ::leave) + } else if (stage == ClassicStage.Result) ClassicResult(gameDef, "BLAST OFF · NO ROOM LEFT", "SCORE", "%,d".format(game.score), newBest = game.score > bestBefore && game.score > 0, previous = previousLine(gameDef.scoreKind, bestBefore, gameDef.title), detail = null, cheer = Mascot.Zip, onAgain = ::startRun, onBack = ::leave) - if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, "Blast Off · ${"%,d".format(game.score)}", - onResume = { guard.reset(); paused = false }, onRestart = { run.end(RunEnd(game.score, finished = false)); startRun() }, onExit = ::leave) + if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, crun?.let { "Challenge ${it.challenge.number} · ${it.lines} of ${it.challenge.lines} lines" } ?: "Blast Off · ${"%,d".format(game.score)}", + onResume = { guard.reset(); paused = false }, onRestart = { val r = crun; if (r != null) startChallenge(r.challenge.number) else { run.end(RunEnd(game.score, finished = false)); startRun() } }, onExit = ::leave) } } diff --git a/android/app/src/main/java/tv/orbit/classic/ArcadeBlockDrop.kt b/android/app/src/main/java/tv/orbit/classic/ArcadeBlockDrop.kt index 222a73da..5e1c57b2 100644 --- a/android/app/src/main/java/tv/orbit/classic/ArcadeBlockDrop.kt +++ b/android/app/src/main/java/tv/orbit/classic/ArcadeBlockDrop.kt @@ -295,7 +295,7 @@ internal fun BlockDropScreen(play: ArcadePlay) { ClassicResult(gameDef, "BLOCK DROP · 40-LINE SPRINT", if (done) "TIME" else "ROWS", if (done) sprintText(centis) else "${game.lines} of $SPRINT_LINES", newBest = done && (bestBefore == 0 || centis < bestBefore), heading = if (done) "FORTY!" else "TOPPED OUT", previous = if (bestBefore > 0) "Best ${sprintText(bestBefore)}" else "Your first Sprint", detail = if (done) null else "Only a finished Sprint goes in the High Scores", - againLabel = "Sprint again", cheer = Mascot.Luna, onAgain = ::startRun, onBack = ::leave) + againLabel = "Go again", cheer = Mascot.Luna, onAgain = ::startRun, onBack = ::leave) } else if (stage == ClassicStage.Result) ClassicResult(gameDef, "BLOCK DROP · LEVEL ${game.level} REACHED", "SCORE", "%,d".format(game.score), newBest = game.score > bestBefore && game.score > 0, previous = previousLine(gameDef.scoreKind, bestBefore, gameDef.title), detail = "${game.lines} rows cleared", cheer = Mascot.Luna, onAgain = ::startRun, onBack = ::leave) diff --git a/android/app/src/main/java/tv/orbit/classic/BlastChallenges.kt b/android/app/src/main/java/tv/orbit/classic/BlastChallenges.kt new file mode 100644 index 00000000..4169f6fa --- /dev/null +++ b/android/app/src/main/java/tv/orbit/classic/BlastChallenges.kt @@ -0,0 +1,66 @@ +package tv.orbit.classic + +/** + * Blast Off's Challenge (Phase 2, 9 November 2026): twenty numbered boards, made by hand, each with a target: clear so many + * lines with so many shapes. The shapes come in the same order every try (each challenge has its own seed), so a challenge + * is a puzzle you can learn, not luck. Free and optional, no streaks; the High Scores keep the furthest challenge cleared. + */ +internal class BlastChallenge(val number: Int, val name: String, val rows: List, val lines: Int, val pieces: Int) { + val seed get() = 7_700L + number * 131L + + /** The starting board: # is a block already there, in the cast's colours by where it sits. */ + fun board(): List> = rows.mapIndexed { y, row -> row.mapIndexed { x, c -> if (c == '#') (x + 2 * y) % BlastColours.size + 1 else 0 } } + + fun start(random: java.util.Random) = BlastGame(board(), BlastGame.deal(random), 0, 3, 3) +} + +/** A challenge being played: the board, shapes used, lines cleared. Won on reaching the target; lost when out of shapes or room. */ +internal class BlastRun(val challenge: BlastChallenge, val game: BlastGame, val placed: Int = 0, val lines: Int = 0) { + val won get() = lines >= challenge.lines + val lost get() = !won && (placed >= challenge.pieces || !game.alive) + val over get() = won || lost + val shapesLeft get() = (challenge.pieces - placed).coerceAtLeast(0) + + /** The game moved (steering, the tray): nothing counted. */ + fun moved(next: BlastGame) = BlastRun(challenge, next, placed, lines) + + /** OK: a shape placed counts one, and the lines it clears count towards the target. */ + fun press(random: java.util.Random): BlastRun { + if (over) return this + val next = game.press(random) + return if (next.score > game.score) BlastRun(challenge, next, placed + 1, lines + next.lastCleared) else BlastRun(challenge, next, placed, lines) + } + + companion object { + fun start(c: BlastChallenge) = java.util.Random(c.seed).let { r -> BlastRun(c, c.start(r)) to r } + } +} + +private fun b(vararg rows: String) = rows.toList() + +/** The twenty, easiest first. */ +internal val BlastChallenges: List = listOf( + BlastChallenge(1, "Warm-up", b("........", "........", "........", "........", "........", "........", "###..###", "###..###"), 2, 8), + BlastChallenge(2, "Side door", b("........", "........", "........", "........", "##......", "##......", "##......", "##......"), 2, 10), + BlastChallenge(3, "Two gaps", b("........", "........", "........", "........", "........", "##.#####", "#####.##", "##.#####"), 3, 10), + BlastChallenge(4, "Pillars", b("........", "#......#", "#......#", "#......#", "#......#", "#......#", "#......#", "#......#"), 3, 12), + BlastChallenge(5, "Steps", b("........", "........", "........", "........", "#.......", "##......", "###.....", "####...."), 3, 12), + BlastChallenge(6, "The frame", b(".######.", "#......#", "#......#", "#......#", "#......#", "#......#", "#......#", ".######."), 3, 12), + BlastChallenge(7, "Chequers", b("........", "........", "........", "........", "#.#.#.#.", ".#.#.#.#", "#.#.#.#.", ".#.#.#.#"), 3, 14), + BlastChallenge(8, "Ollie's ring", b("........", "........", "..####..", ".##..##.", ".##..##.", "..####..", "........", "........"), 4, 14), + BlastChallenge(9, "Comb", b("#.#.#.#.", "#.#.#.#.", "#.#.#.#.", "........", "........", "........", "........", "........"), 4, 14), + BlastChallenge(10, "Half way", b("........", "........", "........", "........", "####....", "####....", "####....", "####...."), 4, 14), + BlastChallenge(11, "Corners", b("##....##", "##....##", "........", "........", "........", "........", "##....##", "##....##"), 4, 16), + BlastChallenge(12, "Cross", b("...#....", "...#....", "...#....", "###.####", "...#....", "...#....", "...#....", "...#...."), 4, 16), + BlastChallenge(13, "Staircase", b("#.......", "##......", "###.....", "####....", "#####...", "######..", "#######.", "........"), 5, 16), + BlastChallenge(14, "Gappy", b("###.####", "####.###", "#.######", "######.#", "........", "........", "........", "........"), 6, 16), + BlastChallenge(15, "Window", b("..####..", "##....##", "##....##", "##....##", "##....##", "##....##", "##....##", "..####.."), 6, 16), + BlastChallenge(16, "Zig-zag", b("##......", ".##.....", "..##....", "...##...", "....##..", ".....##.", "......##", "........"), 6, 18), + BlastChallenge(17, "Shelves", b("........", "######..", "........", "..######", "........", "######..", "........", "..######"), 7, 18), + BlastChallenge(18, "Sky high", b("##.##.##", "........", "##.##.##", "........", "........", "........", "........", "........"), 7, 20), + BlastChallenge(19, "Tight squeeze", b("###..###", "###..###", "###..###", "........", "........", "###..###", "###..###", "###..###"), 8, 20), + BlastChallenge(20, "Blast off!", b("........", "........", "........", "........", "#.######", "###.####", "#####.##", "#######."), 8, 20), +) + +/** The furthest challenge cleared, as the High Scores write it. */ +internal fun blastChallengeLine(score: Int) = if (score >= BlastChallenges.size) "All ${BlastChallenges.size} cleared" else "Challenge $score" diff --git a/android/app/src/main/java/tv/orbit/classic/arcade/ArcadeStore.kt b/android/app/src/main/java/tv/orbit/classic/arcade/ArcadeStore.kt index a841f3b8..7320feda 100644 --- a/android/app/src/main/java/tv/orbit/classic/arcade/ArcadeStore.kt +++ b/android/app/src/main/java/tv/orbit/classic/arcade/ArcadeStore.kt @@ -109,6 +109,9 @@ internal const val PATIENCE_DAILY3_SCORES = "PatienceDaily3" /** Pairs' Challenge: boards cleared then pairs matched, in one number ([tv.orbit.classic.pairsScore]). */ internal const val PAIRS_CHALLENGE_SCORES = "PairsChallenge" +/** Blast Off's Challenges: the furthest of the twenty cleared. */ +internal const val BLAST_CHALLENGE_SCORES = "BlastChallenge" + /** * One of a game's High Scores tables: the game's own (its id, its score kind), or a mode's, kept under its own record id so * the two never mix (Paul: "preserve existing scores and make new modes separate"). [format] writes a score for the page. @@ -123,6 +126,7 @@ internal val modeTables: Map> = mapOf( "Patience" to listOf(ScoreTable(PATIENCE_DAILY_SCORES, "Daily", ScoreKind.FewestMoves) { tv.orbit.classic.dailyLine(it) }, ScoreTable(PATIENCE_DAILY3_SCORES, "Daily Draw 3", ScoreKind.FewestMoves) { tv.orbit.classic.dailyLine(it) }), "Pairs" to listOf(ScoreTable(PAIRS_CHALLENGE_SCORES, "Challenge", ScoreKind.Points) { tv.orbit.classic.pairsLine(it) }), + "Blast" to listOf(ScoreTable(BLAST_CHALLENGE_SCORES, "Challenges", ScoreKind.Points) { tv.orbit.classic.blastChallengeLine(it) }), "Sky" to listOf(ScoreTable(SKY_CHALLENGE_SCORES, "Challenge", ScoreKind.Points) { tv.orbit.classic.challengeLine(it) }), ) diff --git a/android/app/src/main/java/tv/orbit/classic/arcade/ClassicKit.kt b/android/app/src/main/java/tv/orbit/classic/arcade/ClassicKit.kt index 72946963..85a01180 100644 --- a/android/app/src/main/java/tv/orbit/classic/arcade/ClassicKit.kt +++ b/android/app/src/main/java/tv/orbit/classic/arcade/ClassicKit.kt @@ -89,9 +89,10 @@ internal fun ClassicTitle(game: ArcadeGame, backdrop: ArcadeBackdrop, accent: Co Canvas(Modifier.size(80.dp)) { drawMascot(game.mascot, center, size.minDimension * .36f) } } Spacer(Modifier.height(16.dp)) - Column(Modifier.width(210.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) { + Column(Modifier.width(230.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) { ArcadeButton(playLabel, Modifier.fillMaxWidth().focusRequester(play), icon = "▶", primary = true, height = 34.dp, onClick = onPlay) - if (modes > 1) ArcadeButton("Mode", Modifier.fillMaxWidth(), icon = "◆", detail = mode, height = 34.dp, onClick = onMode) + // The mode spelled out in full on the button itself (OK steps to the next); the chip below says it too. + if (modes > 1) ArcadeButton(mode, Modifier.fillMaxWidth(), icon = "◆", height = 34.dp, onClick = onMode) ArcadeButton("How to Play", Modifier.fillMaxWidth(), icon = "?", height = 34.dp, onClick = onHowTo) ArcadeButton("Back to Arcade", Modifier.fillMaxWidth(), icon = "←", height = 34.dp, onClick = onBack) } @@ -171,7 +172,7 @@ internal fun ClassicResult(game: ArcadeGame, kicker: String, label: String, valu if (detail != null) Text(detail, color = ArcadeColours.Muted, fontSize = 13.sp, textAlign = TextAlign.Center) Spacer(Modifier.height(6.dp)) Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) { - ArcadeButton(againLabel, Modifier.width(160.dp).focusRequester(first), icon = "▶", primary = true, height = 34.dp, onClick = onAgain) + ArcadeButton(againLabel, Modifier.width(180.dp).focusRequester(first), icon = "▶", primary = true, height = 34.dp, onClick = onAgain) if (extra != null) ArcadeButton(extra.first, Modifier.width(160.dp), icon = "✦", height = 34.dp, onClick = extra.second) ArcadeButton("Back to Arcade", Modifier.width(200.dp), icon = "←", height = 34.dp, onClick = onBack) } diff --git a/android/app/src/test/java/tv/orbit/classic/BlastChallengesTest.kt b/android/app/src/test/java/tv/orbit/classic/BlastChallengesTest.kt new file mode 100644 index 00000000..6d3c5fa3 --- /dev/null +++ b/android/app/src/test/java/tv/orbit/classic/BlastChallengesTest.kt @@ -0,0 +1,64 @@ +package tv.orbit.classic + +import org.junit.Assert.* +import org.junit.Test + +/** Blast Off's twenty challenges (Phase 2): well formed, fair, and each one beatable. */ +class BlastChallengesTest { + /** A plain bot: each shape where it clears the most lines, then where it touches the most blocks; tries every shape in the tray. */ + private fun bot(c: BlastChallenge): BlastRun { + var (run, random) = BlastRun.start(c) + while (!run.over) { + val g = run.game + var best: Triple? = null; var bestValue = Int.MIN_VALUE + for ((slot, p) in g.tray.withIndex()) { + if (p == null) continue + for (y in 0..BLAST_SIZE - p.shape.height) for (x in 0..BLAST_SIZE - p.shape.width) { + if (!g.fits(p, x, y)) continue + val board = g.board.map { it.toMutableList() } + p.shape.cells.forEach { (cx, cy) -> board[y + cy][x + cx] = 1 } + val lines = (0 until BLAST_SIZE).count { r -> board[r].all { it != 0 } } + (0 until BLAST_SIZE).count { col -> board.all { it[col] != 0 } } + val touch = p.shape.cells.sumOf { (cx, cy) -> listOf(-1 to 0, 1 to 0, 0 to -1, 0 to 1).count { (dx, dy) -> + val bx = x + cx + dx; val by = y + cy + dy; bx !in 0 until BLAST_SIZE || by !in 0 until BLAST_SIZE || g.board[by][bx] != 0 } } + val value = lines * 1_000 + touch * 10 + p.shape.cells.size + if (value > bestValue) { bestValue = value; best = Triple(slot, x, y) } + } + } + val (slot, x, y) = best ?: break + run = run.moved(BlastGame(g.board, g.tray, slot, x, y, false, g.score, g.alive, g.lastCleared, g.streak)).press(random) + } + return run + } + + @Test fun twentyBoardsNumberedInOrderEachEightByEightWithNothingAlreadyFull() { + assertEquals((1..20).toList(), BlastChallenges.map { it.number }) + for (c in BlastChallenges) { + assertEquals(8, c.rows.size); assertTrue(c.rows.all { it.length == 8 }) + val b = c.board() + assertTrue("${c.name} starts with a full row", b.none { r -> r.all { it != 0 } }) + assertTrue("${c.name} starts with a full column", (0 until 8).none { col -> b.all { it[col] != 0 } }) + assertTrue(c.lines in 1..c.pieces) + } + // Targets never get easier as the numbers go up. + assertEquals(BlastChallenges.map { it.lines }.sorted(), BlastChallenges.map { it.lines }) + } + + @Test fun theSameShapesComeInTheSameOrderEveryTry() { + val c = BlastChallenges[4] + val a = BlastRun.start(c).first.game.tray; val b = BlastRun.start(c).first.game.tray + assertEquals(a.map { it?.shape?.cells }, b.map { it?.shape?.cells }) + } + + @Test fun everyChallengeCanBeBeatenByAPlainBot() { + val failed = BlastChallenges.mapNotNull { c -> bot(c).let { r -> if (r.won) null else "${c.number} ${c.name}: ${r.lines} of ${c.lines} lines, ${r.placed} of ${c.pieces} shapes" } } + assertTrue("not beaten: $failed", failed.isEmpty()) + } + + @Test fun aShapePlacedCountsAndSteeringDoesNot() { + val (run, random) = BlastRun.start(BlastChallenges[0]) + assertEquals(0, run.moved(run.game.move(1, 0)).placed) + val placed = run.press(random) + assertEquals(1, placed.placed); assertEquals(BlastChallenges[0].pieces - 1, placed.shapesLeft) + assertEquals("Challenge 7", blastChallengeLine(7)); assertEquals("All 20 cleared", blastChallengeLine(20)) + } +} diff --git a/android/app/src/test/java/tv/orbit/classic/arcade/ModeTablesTest.kt b/android/app/src/test/java/tv/orbit/classic/arcade/ModeTablesTest.kt index d5ea8565..21ced822 100644 --- a/android/app/src/test/java/tv/orbit/classic/arcade/ModeTablesTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/arcade/ModeTablesTest.kt @@ -47,4 +47,16 @@ class ModeTablesTest { assertEquals(0, d.game("Patience").count) assertEquals("◀ DAILY DRAW 3 ▶", scoreTableLabel(ArcadeGames.Patience, 2)) } + + @Test fun everyModeTableIsItsOwnAndNoneIsAGame() { + val ids = modeTables.values.flatten().map { it.id } + assertEquals(ids.size, ids.toSet().size) + assertTrue(ids.none { ArcadeGames.byId(it) != null }) + // The Classics' own tables, kinds and Household keys are as they were. + val classic = mapOf("OrbMan" to ScoreKind.Points, "Blast" to ScoreKind.Points, "Sky" to ScoreKind.Solved, "Snake" to ScoreKind.Points, + "Blocks" to ScoreKind.Points, "Bricks" to ScoreKind.Points, "Pairs" to ScoreKind.FewestMoves, "Patience" to ScoreKind.Wins) + for ((id, kind) in classic) { assertEquals(kind, ArcadeGames.byId(id)!!.scoreKind); assertEquals(id, scoreTables(id).first()) } + assertEquals(listOf("orb_man_best", "blast_best", "skydoku_solved", "snake_best", "block_drop_best", "brick_break_best", "pairs_best", "patience_wins"), + ArcadeGames.classics.map { it.legacyRecordKey }) + } } diff --git a/android/app/src/test/java/tv/orbit/classic/arcade/TitleTextFitsTest.kt b/android/app/src/test/java/tv/orbit/classic/arcade/TitleTextFitsTest.kt index 2e07a3b5..005d4ebf 100644 --- a/android/app/src/test/java/tv/orbit/classic/arcade/TitleTextFitsTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/arcade/TitleTextFitsTest.kt @@ -72,28 +72,36 @@ class TitleTextFitsTest { val anton = Font.createFont(Font.TRUETYPE_FONT, File("src/main/res/font/anton_regular.ttf")).deriveFont(76f) for (g in ArcadeGames.classics) { val w = width(anton, g.title.uppercase()) - assertTrue("${g.title} is ${"%.0f".format(w)} dp", w <= 960.0 - 96 - 210 - 16) + assertTrue("${g.title} is ${"%.0f".format(w)} dp", w <= 960.0 - 96 - 230 - 16) } val font = Font(Font.SANS_SERIF, Font.BOLD, 1).deriveFont(14f * 1.3f) val labels = listOf("▶ Play" to 210, "▶ Deal" to 210, "▶ Today's puzzle" to 210, "▶ New puzzle" to 210, "? How to Play" to 210, "← Back to Arcade" to 210, - "▶ Play Again" to 160, "▶ Deal again" to 160, "▶ Try it again" to 160, "▶ New puzzle" to 160, "✦ New puzzle" to 160, "← Back to Arcade" to 200) + "▶ Play Again" to 180, "▶ Deal again" to 180, "▶ Try it again" to 180, "▶ New puzzle" to 180, "✦ New puzzle" to 160, "← Back to Arcade" to 200) for ((label, column) in labels) { val w = width(font, label) assertTrue("$label is ${"%.0f".format(w)} dp in $column", w <= column - 2 * 12 - 4) } // The result's three buttons (Skydoku out of hearts) fit its wider card: 600 dp less 2 × 20 padding. - assertTrue(160 + 160 + 200 + 2 * 10 <= 600 - 40) + assertTrue(180 + 160 + 200 + 2 * 10 <= 600 - 40) // And the whole result row fits the screen: the cast either side. assertTrue(100 + 16 + 600 + 16 + 100 <= 960) } @Test fun theModeButtonSpellsEachModeOutInFull() { - // "◆ Mode" on the left, the mode's whole name on the right (12 sp detail), in the title's 210 dp column. + // The mode's whole name on the button, after its ◆, in the title's 210 dp column. val label = Font(Font.SANS_SERIF, Font.BOLD, 1).deriveFont(14f * 1.3f) - val detail = Font(Font.SANS_SERIF, Font.PLAIN, 1).deriveFont(12f * 1.3f) - for (mode in listOf("Classic", "Signal Run")) { - val w = width(label, "◆ Mode") + 8 + width(detail, mode) - assertTrue("Mode · $mode is ${"%.0f".format(w)} dp", w <= 210 - 2 * 12 - 4) + for (mode in listOf("Classic", "Signal Run", "Challenge", "Challenges", "40-Line Sprint", "Daily Challenge", "Daily · Draw Three")) { + val w = width(label, "◆ $mode") + assertTrue("Mode · $mode is ${"%.0f".format(w)} dp", w <= 230 - 2 * 12 - 4) + } + } + + @Test fun theModesPlayAndResultButtonsFit() { + val font = Font(Font.SANS_SERIF, Font.BOLD, 1).deriveFont(14f * 1.3f) + for ((label, column) in listOf("▶ Start the climb" to 210, "▶ Today's deal" to 210, "▶ Challenge 20" to 210, "▶ Climb again" to 180, + "▶ Next board" to 180, "▶ Go again" to 180, "▶ Try it again" to 180, "▶ Play it again" to 180, "✦ Try again" to 160)) { + val w = width(font, label) + assertTrue("$label is ${"%.0f".format(w)} dp in $column", w <= column - 2 * 12 - 4) } } } diff --git a/docs/classics-modes.md b/docs/classics-modes.md index 138281ce..0d0db159 100644 --- a/docs/classics-modes.md +++ b/docs/classics-modes.md @@ -33,3 +33,25 @@ shows the table chosen, and Clear high scores clears all of a game's tables. Gam Checks: 1,003 unit tests run, 24 skipped, 0 failed; lint 0 errors, 87 warnings (none new); release APK 48,006,747 bytes (+16,372 on 0.111.0); the Mode button's words fit at the largest font scale. Not installed; nothing seen running. + +## The Challenges (0.113.0, versionCode 303) + +Free and optional, no streaks, each in its own High Scores table. Classic's tables, score kinds and Household keys are +unchanged (`ModeTablesTest`). + +| Game | Mode | What it is | Table, ranked by | +|---|---|---|---| +| Skydoku | **Challenge** | A ladder of ten puzzles, 6×6 ×3, 7×7 ×4, 8×8 ×3, against the clock. Three hearts for the whole climb; every third puzzle solved wins one back (up to three). The next puzzle is made in the background while you solve this one. | `SkyChallenge`: puzzles solved, then time ("7 of 10 · 5:21") | +| Block Drop | **40-Line Sprint** | Clear 40 rows as fast as you can; Classic's rules, the clock stops on pause. Only a finished Sprint is saved. | `BlocksSprint`: fewest hundredths ("1:21.23") | +| Patience | **Daily Challenge** and **Daily · Draw Three** | One deal a day, the same on every Orbit, so the family can compare; win it in the fewest moves, then quickest. Draw Three turns three at a time. | `PatienceDaily`, `PatienceDaily3`: moves, then time | +| Pairs | **Challenge** | Boards in a row against one clock, growing 4×3, 4×4, 5×4, 6×4, 6×5 (then 6×5 again). 90 seconds to start, +2 a match, +30 a board. More of Orbit's family channels and Drift join the cards for the bigger boards. | `PairsChallenge`: boards, then pairs | +| Blast Off | **Challenges** | Twenty numbered boards made by hand (Warm-up … Blast off!), each "clear so many lines with so many shapes". The shapes come in the same order every try, so each is a puzzle to learn. The next uncleared one is offered; the furthest cleared is saved. | `BlastChallenge`: furthest cleared | + +- Skydoku's puzzle maker now takes a size; 6×6 runs exactly as before, so the daily puzzle is unchanged. The 7×7 brings in + Nite Owl; the 8×8's eighth is a gold star for now (Paul to pick who). +- Every Blast Off challenge is beaten by a plain test bot within its shapes (`BlastChallengesTest`); none starts with a full + line. +- The Mode button carries the mode's whole name (the title's buttons widened to 230 dp, Play Again to 180 dp to fit). + +Checks: 1,022 unit tests run, 24 skipped, 0 failed; lint 0 errors, 87 warnings (none new); release APK 48,039,519 bytes +(+32,772 on 0.112.0); every mode name and new button fits at the largest font scale. Not installed; nothing seen running.