From 9aa8d23e907e7f464008c13c25f160a305351a56 Mon Sep 17 00:00:00 2001 From: Pauljd Date: Mon, 9 Nov 2026 09:40:01 +0000 Subject: [PATCH] Block Drop 40-Line Sprint and Patience Daily Challenge (draw one or three), each with its own High Scores Co-Authored-By: Claude Opus 5.5 --- .../java/tv/orbit/classic/ArcadeBlockDrop.kt | 82 +++++++++++++++---- .../java/tv/orbit/classic/ArcadePatience.kt | 64 ++++++++++++--- .../tv/orbit/classic/arcade/ArcadeStore.kt | 10 +++ .../tv/orbit/classic/PairsPatienceTest.kt | 28 +++++++ .../tv/orbit/classic/arcade/ModeTablesTest.kt | 17 ++++ 5 files changed, 173 insertions(+), 28 deletions(-) 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 19c3ce49..222a73da 100644 --- a/android/app/src/main/java/tv/orbit/classic/ArcadeBlockDrop.kt +++ b/android/app/src/main/java/tv/orbit/classic/ArcadeBlockDrop.kt @@ -17,6 +17,7 @@ import tv.orbit.classic.arcade.classicPace import tv.orbit.classic.arcade.classicPanel import tv.orbit.classic.arcade.gameKeys import tv.orbit.classic.arcade.previousLine +import tv.orbit.classic.arcade.BLOCKS_SPRINT_SCORES import tv.orbit.classic.arcade.ArcadePlay import tv.orbit.classic.arcade.PauseWhenHidden @@ -177,6 +178,12 @@ private fun NextPiece(kind: Int, modifier: Modifier) = Canvas(modifier) { cells.forEach { (x, y) -> cell(x, y, size, origin, BlockColours[kind]) } } +/** Block Drop's Challenge (Phase 2, 9 November 2026): 40 lines as fast as you can, in its own High Scores (fewest centiseconds). */ +internal const val SPRINT_LINES = 40 + +/** A sprint time, as the High Scores and the HUD show it: 1:23.45. */ +internal fun sprintText(centis: Int) = "%d:%02d.%02d".format(centis / 6_000, centis / 100 % 60, centis % 100) + @Composable internal fun BlockDropScreen(play: ArcadePlay) { val gameDef = ArcadeGames.Blocks @@ -186,7 +193,11 @@ internal fun BlockDropScreen(play: ArcadePlay) { var stage by remember { mutableStateOf(ClassicStage.Title) } var paused by remember { mutableStateOf(false) } var howTo by remember { mutableStateOf(false) } - var bestBefore by remember { mutableIntStateOf(play.best) } + // Classic, or the 40-line Sprint: chosen on the title, remembered, each with its own High Scores. + var sprint by remember { mutableStateOf(play.level["mode"] == "Sprint") } + val table = if (sprint) BLOCKS_SPRINT_SCORES else gameDef.id + var bestBefore by remember { mutableIntStateOf(play.bestIn(table)) } + var centis by remember { mutableIntStateOf(0) } val focus = remember { FocusRequester() } val backdrop = ArcadeLook.forGame(gameDef.id) val pace = classicPace(play.difficulty) @@ -198,17 +209,44 @@ internal fun BlockDropScreen(play: ArcadePlay) { LaunchedEffect(stage, paused, game.alive) { while (stage == ClassicStage.Play && !paused && game.alive) { kotlinx.coroutines.delay((game.tickMs / pace).toLong()); game = game.fall(random = random) } } - val run = rememberRun(play.onRunEnd) { RunEnd(game.score, finished = false, detail = "Level ${game.level}") } - fun startRun() { bestBefore = latestPlay.best; game = BlockGame.start(random); guard.reset(); run.begin(); paused = false; stage = ClassicStage.Play } - fun leave() { run.end(RunEnd(game.score, finished = !game.alive, detail = "Level ${game.level}")); latestPlay.onLeave() } - LaunchedEffect(game.alive) { if (!game.alive && stage == ClassicStage.Play) { run.end(RunEnd(game.score, finished = true, detail = "Level ${game.level}")); stage = ClassicStage.Result } } + // Classic saves its points; a Sprint saves its time, only when all 40 lines are cleared. + val run = rememberRun({ end -> if (sprint) latestPlay.onRunEndIn(BLOCKS_SPRINT_SCORES, end) else latestPlay.onRunEnd(end) }) { + if (sprint) RunEnd(centis, finished = false, detail = "${game.lines} lines") else RunEnd(game.score, finished = false, detail = "Level ${game.level}") + } + fun startRun() { bestBefore = latestPlay.bestIn(table); game = BlockGame.start(random); centis = 0; guard.reset(); run.begin(); paused = false; stage = ClassicStage.Play } + fun leave() { + run.end(if (sprint) RunEnd(centis, finished = false, detail = "${game.lines} lines") else RunEnd(game.score, finished = !game.alive, detail = "Level ${game.level}")) + latestPlay.onLeave() + } + LaunchedEffect(game.alive) { + if (!game.alive && stage == ClassicStage.Play) { + run.end(if (sprint) RunEnd(centis, finished = false, detail = "${game.lines} lines") else RunEnd(game.score, finished = true, detail = "Level ${game.level}")) + stage = ClassicStage.Result + } + } + // The Sprint's clock (frame time, so it's true to the hundredth) and its finish line. + LaunchedEffect(stage, paused, sprint) { + if (!sprint) return@LaunchedEffect + var last = -1L; var carry = 0L + while (stage == ClassicStage.Play && !paused && game.alive) { + val now = withFrameNanos { it } + if (last >= 0) { carry += now - last; val whole = carry / 10_000_000L; if (whole > 0) { centis += whole.toInt(); carry -= whole * 10_000_000L } } + last = now + } + } + LaunchedEffect(game.lines) { + if (sprint && stage == ClassicStage.Play && game.lines >= SPRINT_LINES) { run.end(RunEnd(centis, finished = true, detail = "$SPRINT_LINES lines")); stage = ClassicStage.Result } + } LaunchedEffect(stage, paused) { if (stage == ClassicStage.Play && !paused) runCatching { focus.requestFocus() } } BackHandler(stage == ClassicStage.Play && !paused) { pause() } if (stage == ClassicStage.Title) { - ClassicTitle(gameDef, backdrop, OrbCharacter.Drift.colour, "Stack them neatly… zzz", listOf("Your best" to if (play.best > 0) "%,d".format(play.best) else "Not played yet"), + val best = play.bestIn(table) + ClassicTitle(gameDef, backdrop, OrbCharacter.Drift.colour, if (sprint) "Forty rows? I'm awake!" else "Stack them neatly… zzz", + listOf("Your best" to if (best <= 0) "Not played yet" else if (sprint) sprintText(best) else "%,d".format(best)), timed = true, difficulty = play.difficulty, refocus = !howTo, onPlay = ::startRun, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() }, - note = "Clear several rows at once for more; every ten rows the blocks fall faster.") + mode = if (sprint) "40-Line Sprint" else "Classic", modes = 2, onMode = { sprint = !sprint; latestPlay.setLevel("mode", if (sprint) "Sprint" else "Classic") }, + note = if (sprint) "Clear 40 rows as fast as you can. The clock stops when you pause." else "Clear several rows at once for more; every ten rows the blocks fall faster.") if (howTo) HowToPlayCard(gameDef, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false }) return } @@ -230,11 +268,18 @@ internal fun BlockDropScreen(play: ArcadePlay) { Box(Modifier.fillMaxSize()) { ClassicPlayFrame(backdrop, keys, footer = listOf(Control("◀▶", "Move"), Control("▲", "Turn"), Control("▼", "Down"), Control("OK", "Drop"), Control("Back", "Pause")), hud = { - HudLabel("SCORE"); HudValue("%,d".format(game.score)) - HudLabel("BEST"); HudValue("%,d".format(maxOf(bestBefore, game.score))) - Spacer(Modifier.height(6.dp)) - HudLabel("LEVEL"); HudValue("${game.level}") - HudLabel("ROWS ${game.lines}") + if (sprint) { + HudLabel("TIME"); HudValue(sprintText(centis)) + HudLabel("BEST"); HudValue(if (bestBefore > 0) sprintText(bestBefore) else "—") + Spacer(Modifier.height(6.dp)) + HudLabel("ROWS TO GO"); HudValue("${(SPRINT_LINES - game.lines).coerceAtLeast(0)}") + } else { + HudLabel("SCORE"); HudValue("%,d".format(game.score)) + HudLabel("BEST"); HudValue("%,d".format(maxOf(bestBefore, game.score))) + Spacer(Modifier.height(6.dp)) + HudLabel("LEVEL"); HudValue("${game.level}") + HudLabel("ROWS ${game.lines}") + } Spacer(Modifier.weight(1f)) // Drift hosts (Paul, 6 November 2026), dozing beside the board. Canvas(Modifier.size(56.dp)) { drawOrbChaser(center, size.minDimension * .36f, OrbCharacter.Drift, OrbDir.Down, scared = false, returning = false, blink = false, wobble = 0f, eyesShut = true) } @@ -245,10 +290,17 @@ internal fun BlockDropScreen(play: ArcadePlay) { }) { BlockField(game, Modifier.fillMaxHeight().aspectRatio(BLOCK_COLUMNS / BLOCK_ROWS.toFloat()).classicPanel().padding(6.dp)) } - if (stage == ClassicStage.Result) ClassicResult(gameDef, "BLOCK DROP · LEVEL ${game.level} REACHED", "SCORE", "%,d".format(game.score), + if (stage == ClassicStage.Result && sprint) { + val done = game.lines >= SPRINT_LINES + 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) + } 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) - if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, "Block Drop · Level ${game.level} · ${"%,d".format(game.score)}", - onResume = { guard.reset(); paused = false }, onRestart = { run.end(RunEnd(game.score, finished = false, detail = "Level ${game.level}")); startRun() }, onExit = ::leave) + if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, if (sprint) "Sprint · ${game.lines} of $SPRINT_LINES · ${sprintText(centis)}" else "Block Drop · Level ${game.level} · ${"%,d".format(game.score)}", + onResume = { guard.reset(); paused = false }, + onRestart = { run.end(if (sprint) RunEnd(centis, finished = false) else RunEnd(game.score, finished = false, detail = "Level ${game.level}")); startRun() }, onExit = ::leave) } } diff --git a/android/app/src/main/java/tv/orbit/classic/ArcadePatience.kt b/android/app/src/main/java/tv/orbit/classic/ArcadePatience.kt index 81fcdd69..b7ce71b1 100644 --- a/android/app/src/main/java/tv/orbit/classic/ArcadePatience.kt +++ b/android/app/src/main/java/tv/orbit/classic/ArcadePatience.kt @@ -60,7 +60,9 @@ internal val HOMES = 2..5 internal val COLUMNS = 6..12 /** Where the pointer is, what's held ([held]: the pile and how many cards), the moves made, and moves refused (for the "can't go there"). */ -internal data class PatienceGame(val piles: List>, val pile: Int = 6, val held: Pair? = null, val moves: Int = 0, val refusals: Int = 0) { +internal data class PatienceGame(val piles: List>, val pile: Int = 6, val held: Pair? = null, val moves: Int = 0, val refusals: Int = 0, + /** Cards turned from the stock at a time: 1 (Classic), or 3 (the Daily Challenge's Draw Three). */ + val draw: Int = 1) { val won get() = HOMES.all { piles[it].size == 13 } fun faceUp(i: Int) = piles[i].takeLastWhile { it.up }.size @@ -112,7 +114,7 @@ internal data class PatienceGame(val piles: List>, val pile: I STOCK -> { val next = piles.toMutableList() if (piles[STOCK].isEmpty()) { next[STOCK] = piles[WASTE].reversed().map { it.copy(up = false) }; next[WASTE] = emptyList() } - else { next[WASTE] = piles[WASTE] + piles[STOCK].last().copy(up = true); next[STOCK] = piles[STOCK].dropLast(1) } + else { val n = minOf(draw, piles[STOCK].size); next[WASTE] = piles[WASTE] + piles[STOCK].takeLast(n).reversed().map { it.copy(up = true) }; next[STOCK] = piles[STOCK].dropLast(n) } copy(piles = next) } WASTE, in HOMES -> if (piles[pile].isEmpty()) this else copy(held = pile to 1) @@ -130,6 +132,9 @@ internal data class PatienceGame(val piles: List>, val pile: I fun drop() = copy(held = null) companion object { + /** The Daily Challenge's deal: the same for everyone on any Orbit all day. */ + fun daily(day: java.time.LocalDate, draw: Int = 1) = deal(java.util.Random(day.toEpochDay() * 104_729 + 7)).copy(draw = draw) + fun deal(random: java.util.Random): PatienceGame { val deck = (0 until 4).flatMap { s -> (1..13).map { r -> PlayingCard(r, s, false) } }.toMutableList().also { java.util.Collections.shuffle(it, random) } val piles = MutableList(13) { emptyList() } @@ -141,6 +146,15 @@ internal data class PatienceGame(val piles: List>, val pile: I } } +/** The Daily Challenge's score: fewest moves, then quickest, in one number (lower is better). */ +internal fun dailyScore(moves: Int, seconds: Int) = moves * 10_000 + seconds.coerceIn(0, 9_999) +internal fun dailyLine(score: Int) = "${score / 10_000} moves · %d:%02d".format(score % 10_000 / 60, score % 10_000 % 60) + +/** The three ways to play: Classic, and the Daily Challenge drawing one or three. */ +internal enum class PatienceMode(val title: String, val table: String?, val draw: Int) { + Classic("Classic", null, 1), Daily("Daily Challenge", tv.orbit.classic.arcade.PATIENCE_DAILY_SCORES, 1), DailyThree("Daily · Draw Three", tv.orbit.classic.arcade.PATIENCE_DAILY3_SCORES, 3) +} + private val CardW = 76.dp private val CardH = 104.dp /** Held cards: lifted and ringed in cyan. The pointer: the yellow ring, as everywhere in the Arcade. Never the same. */ @@ -185,13 +199,26 @@ internal fun PatienceScreen(play: ArcadePlay) { var paused by remember { mutableStateOf(false) } var howTo by remember { mutableStateOf(false) } var winsBefore by remember { mutableIntStateOf(play.best) } + // Classic, or the Daily Challenge (one or three at a time): chosen on the title and remembered. + var mode by remember { mutableStateOf(PatienceMode.entries.firstOrNull { it.name == play.level["mode"] } ?: PatienceMode.Classic) } + val today = remember { java.time.LocalDate.now() } + var seconds by remember { mutableIntStateOf(0) } + var dailyBefore by remember { mutableIntStateOf(0) } val focus = remember { FocusRequester() } val backdrop = ArcadeLook.forGame(gameDef.id) - // A won game counts for this profile; leaving part-way counts nothing. - val run = rememberRun(play.onRunEnd) { RunEnd(game.moves, finished = game.won) } - fun deal() { winsBefore = latestPlay.best; game = PatienceGame.deal(random); run.begin(); paused = false; stage = ClassicStage.Play } - fun leave() { run.end(RunEnd(game.moves, finished = game.won)); latestPlay.onLeave() } - LaunchedEffect(game.won) { if (game.won && stage == ClassicStage.Play) { run.end(RunEnd(game.moves, finished = true)); stage = ClassicStage.Result } } + // A won game counts for this profile; leaving part-way counts nothing. A daily win goes in its own table, moves then time. + val run = rememberRun({ end -> mode.table?.let { latestPlay.onRunEndIn(it, end) } ?: latestPlay.onRunEnd(end) }) { + if (mode.table != null) RunEnd(dailyScore(game.moves, seconds), finished = game.won) else RunEnd(game.moves, finished = game.won) + } + fun finishRun(won: Boolean) = run.end(if (mode.table != null) RunEnd(dailyScore(game.moves, seconds), finished = won, detail = today.toString()) else RunEnd(game.moves, finished = won)) + fun deal() { + winsBefore = latestPlay.best; dailyBefore = mode.table?.let { latestPlay.bestIn(it) } ?: 0; seconds = 0 + game = if (mode.table != null) PatienceGame.daily(today, mode.draw) else PatienceGame.deal(random) + run.begin(); paused = false; stage = ClassicStage.Play + } + fun leave() { finishRun(game.won); latestPlay.onLeave() } + LaunchedEffect(game.won) { if (game.won && stage == ClassicStage.Play) { finishRun(true); stage = ClassicStage.Result } } + LaunchedEffect(stage, paused, mode) { while (mode.table != null && stage == ClassicStage.Play && !paused && !game.won) { kotlinx.coroutines.delay(1_000); seconds++ } } LaunchedEffect(stage, paused) { if (stage == ClassicStage.Play && !paused) runCatching { focus.requestFocus() } } // "That can't go there", for a moment after a refused move. var refusedShown by remember { mutableStateOf(false) } @@ -199,9 +226,14 @@ internal fun PatienceScreen(play: ArcadePlay) { BackHandler(stage == ClassicStage.Play && !paused) { if (game.held != null) game = game.drop() else paused = true } if (stage == ClassicStage.Title) { - ClassicTitle(gameDef, backdrop, ArcadeColours.Green, "Deal you in?", listOf("Games won" to "${play.best}"), timed = false, difficulty = play.difficulty, - refocus = !howTo, onPlay = ::deal, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() }, playLabel = "Deal", - note = "Pick a card up and OK where it goes: as many as fit there move together. OK twice sends a card home.") + val dailyBest = mode.table?.let { play.bestIn(it) } ?: 0 + ClassicTitle(gameDef, backdrop, ArcadeColours.Green, if (mode.table != null) "Today's deal is the same for everyone!" else "Deal you in?", + if (mode.table != null) listOf("Your best" to if (dailyBest > 0) dailyLine(dailyBest) else "Not won yet") else listOf("Games won" to "${play.best}"), + timed = false, difficulty = play.difficulty, refocus = !howTo, onPlay = ::deal, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() }, + playLabel = if (mode.table != null) "Today's deal" else "Deal", mode = mode.title, modes = PatienceMode.entries.size, + onMode = { mode = PatienceMode.entries[(mode.ordinal + 1) % PatienceMode.entries.size]; latestPlay.setLevel("mode", mode.name) }, + note = if (mode.table != null) "One deal a day, the same on every Orbit, so the family can compare. Win it in the fewest moves, then the quickest." + (if (mode.draw == 3) " Three cards turn at a time." else "") + else "Pick a card up and OK where it goes: as many as fit there move together. OK twice sends a card home.") if (howTo) HowToPlayCard(gameDef, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false }) return } @@ -228,7 +260,8 @@ internal fun PatienceScreen(play: ArcadePlay) { hud = { HudLabel("MOVES"); HudValue("${game.moves}") Spacer(Modifier.height(8.dp)) - HudLabel("GAMES WON"); HudValue("${maxOf(play.best, winsBefore)}") + if (mode.table != null) { HudLabel(if (mode.draw == 3) "DAILY · DRAW 3" else "DAILY DEAL"); HudValue("%d:%02d".format(seconds / 60, seconds % 60)) } + else { HudLabel("GAMES WON"); HudValue("${maxOf(play.best, winsBefore)}") } Spacer(Modifier.height(8.dp)) HudLabel("IN HAND") Text(game.held?.let { (from, n) -> game.piles[from].takeLast(n).first().label + if (n > 1) " and ${n - 1} more" else "" } ?: "Nothing", @@ -266,9 +299,14 @@ internal fun PatienceScreen(play: ArcadePlay) { } } } - if (stage == ClassicStage.Result) ClassicResult(gameDef, "PATIENCE · WON IN ${game.moves} MOVES", "GAMES WON", "${winsBefore + 1}", newBest = false, + if (stage == ClassicStage.Result && mode.table != null) { + val score = dailyScore(game.moves, seconds) + ClassicResult(gameDef, "PATIENCE · ${mode.title.uppercase()} · ${today}", "TODAY'S DEAL", dailyLine(score), newBest = dailyBefore == 0 || score < dailyBefore, + previous = if (dailyBefore > 0) "Best ${dailyLine(dailyBefore)}" else "Your first Daily Challenge win", detail = "Same deal all day: can anyone beat it?", heading = "WON!", + againLabel = "Try it again", cheer = Mascot.Luna, onAgain = ::deal, onBack = ::leave) + } else if (stage == ClassicStage.Result) ClassicResult(gameDef, "PATIENCE · WON IN ${game.moves} MOVES", "GAMES WON", "${winsBefore + 1}", newBest = false, previous = "Every suit home, ace to king", detail = null, heading = "WON!", againLabel = "Deal again", cheer = Mascot.Luna, onAgain = ::deal, onBack = ::leave) if (paused && stage == ClassicStage.Play) ArcadePauseMenu(gameDef, "Patience · ${game.moves} moves", - onResume = { paused = false }, onRestart = { run.end(RunEnd(game.moves, finished = false)); deal() }, onExit = ::leave) + onResume = { paused = false }, onRestart = { finishRun(false); deal() }, onExit = ::leave) } } 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 8d069286..cee2fec2 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 @@ -99,6 +99,13 @@ internal const val ORBMAN_SIGNAL_SCORES = "OrbManSignal" /** Skydoku's Challenge ladder: puzzles solved, then time, in one number ([tv.orbit.classic.challengeScore]). */ internal const val SKY_CHALLENGE_SCORES = "SkyChallenge" +/** Block Drop's 40-line Sprint: the time in hundredths, fewest first. */ +internal const val BLOCKS_SPRINT_SCORES = "BlocksSprint" + +/** Patience's Daily Challenge, drawing one and drawing three: fewest moves then time, in one number ([tv.orbit.classic.dailyScore]). */ +internal const val PATIENCE_DAILY_SCORES = "PatienceDaily" +internal const val PATIENCE_DAILY3_SCORES = "PatienceDaily3" + /** * 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. @@ -109,6 +116,9 @@ internal class ScoreTable(val id: String, val name: String, val kind: ScoreKind, internal val modeTables: Map> = mapOf( "Hive" to listOf(ScoreTable(HIVE_HARD_SCORES, "Hard", ScoreKind.Points)), "OrbMan" to listOf(ScoreTable(ORBMAN_SIGNAL_SCORES, "Signal Run", ScoreKind.Points)), + "Blocks" to listOf(ScoreTable(BLOCKS_SPRINT_SCORES, "40-Line Sprint", ScoreKind.FewestMoves) { tv.orbit.classic.sprintText(it) }), + "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) }), "Sky" to listOf(ScoreTable(SKY_CHALLENGE_SCORES, "Challenge", ScoreKind.Points) { tv.orbit.classic.challengeLine(it) }), ) diff --git a/android/app/src/test/java/tv/orbit/classic/PairsPatienceTest.kt b/android/app/src/test/java/tv/orbit/classic/PairsPatienceTest.kt index 987b2937..623f8c83 100644 --- a/android/app/src/test/java/tv/orbit/classic/PairsPatienceTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/PairsPatienceTest.kt @@ -84,4 +84,32 @@ class PairsPatienceTest { assertTrue(104f + 6 * 8f + 12 * step <= 340f + .01f || step == 12f) assertEquals(26f, patienceSteps(0, 3, 400f, 104f), .01f) } + + // ---------- the Daily Challenge (Phase 2) ---------- + + @Test fun theDailyDealIsTheSameAllDayAndChangesTomorrow() { + val day = java.time.LocalDate.of(2026, 11, 9) + assertEquals(PatienceGame.daily(day).piles, PatienceGame.daily(day).piles) + assertNotEquals(PatienceGame.daily(day).piles, PatienceGame.daily(day.plusDays(1)).piles) + assertEquals(1, PatienceGame.daily(day).draw); assertEquals(3, PatienceGame.daily(day, 3).draw) + // Classic still turns one card at a time. + assertEquals(1, PatienceGame.deal(java.util.Random(1)).draw) + } + + @Test fun drawThreeTurnsThreeWithTheThirdOnTop() { + val stock = listOf(PlayingCard(2, 0, false), PlayingCard(3, 0, false), PlayingCard(4, 0, false), PlayingCard(5, 0, false)) + val g = PatienceGame(List(13) { i -> if (i == STOCK) stock else emptyList() }, draw = 3).point(STOCK).press() + assertEquals(1, g.piles[STOCK].size); assertEquals(3, g.piles[WASTE].size) + // The top three of the stock were 3, 4 and 5 (5 on top); turned over, 3 is the one showing. + assertEquals(3, g.piles[WASTE].last().rank); assertTrue(g.piles[WASTE].all { it.up }) + // The last card goes on its own, then the turned cards go back. + val g2 = g.press(); assertEquals(0, g2.piles[STOCK].size); assertEquals(4, g2.piles[WASTE].size) + assertEquals(4, g2.press().piles[STOCK].size) + } + + @Test fun dailyScoresFewestMovesFirstThenTime() { + assertTrue(dailyScore(90, 900) < dailyScore(91, 10)) + assertTrue(dailyScore(90, 100) < dailyScore(90, 200)) + assertEquals("90 moves · 5:21", dailyLine(dailyScore(90, 321))) + } } 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 9d68c92e..d5ea8565 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 @@ -30,4 +30,21 @@ class ModeTablesTest { assertEquals(tv.orbit.classic.challengeScore(3, 400), bestOf(d.game(SKY_CHALLENGE_SCORES), ScoreKind.Points)) assertEquals("3 of 10 · 6:40", scoreTableDefs("Sky", ScoreKind.Solved)[1].format(bestOf(d.game(SKY_CHALLENGE_SCORES), ScoreKind.Points))) } + + @Test fun blockDropsSprintAndPatiencesDailiesKeepTheirOwnTables() { + assertEquals(listOf("Blocks", BLOCKS_SPRINT_SCORES), scoreTables("Blocks")) + assertEquals(listOf("Patience", PATIENCE_DAILY_SCORES, PATIENCE_DAILY3_SCORES), scoreTables("Patience")) + var d = ArcadeProfileData(profileId = "p1") + // A Sprint counts only when finished, fastest first. + d = recordRun(d, BLOCKS_SPRINT_SCORES, tableKind("Blocks", BLOCKS_SPRINT_SCORES, ScoreKind.Points), RunEnd(9_000, false), 1) + assertTrue(d.game(BLOCKS_SPRINT_SCORES).runs.isEmpty()) + d = recordRun(d, BLOCKS_SPRINT_SCORES, ScoreKind.FewestMoves, RunEnd(9_000, true), 2) + d = recordRun(d, BLOCKS_SPRINT_SCORES, ScoreKind.FewestMoves, RunEnd(8_123, true), 3) + assertEquals("1:21.23", scoreTableDefs("Blocks", ScoreKind.Points)[1].format(bestOf(d.game(BLOCKS_SPRINT_SCORES), ScoreKind.FewestMoves))) + assertTrue(d.game("Blocks").runs.isEmpty()) + // Patience's wins count is untouched by daily wins. + d = recordRun(d, PATIENCE_DAILY_SCORES, tableKind("Patience", PATIENCE_DAILY_SCORES, ScoreKind.Wins), RunEnd(tv.orbit.classic.dailyScore(95, 300), true), 4) + assertEquals(0, d.game("Patience").count) + assertEquals("◀ DAILY DRAW 3 ▶", scoreTableLabel(ArcadeGames.Patience, 2)) + } }