Test Card Tangle: thirty calm cable puzzles over Orbit's own test card, bot-checked within par
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -104,6 +104,12 @@ internal object ArcadeGames {
|
||||
tv.orbit.classic.arcade.quiz.QuizNightScreen(it)
|
||||
}
|
||||
|
||||
val TestCardTangle: ArcadeGame = GameDef("TestCardTangle", "Test Card Tangle", "Turn the cables, bring the picture back", "Join every cable up to the signal and Orbit's test card comes back.", Mascot.Drift,
|
||||
kidsSuitable = true, original = true, launchable = true, ScoreKind.Points, keepsLevels = true, legacyRecordKey = null,
|
||||
listOf(Control("◀▶▲▼", "Move"), Control("OK", "Turn the piece"), BackPause), "Every piece joined to the signal, no loose ends. No timer.") {
|
||||
tv.orbit.classic.arcade.tangle.TestCardTangleScreen(it)
|
||||
}
|
||||
|
||||
// Classics: the eight Kotlin games, unchanged, each in a thin wrapper.
|
||||
val OrbMan: ArcadeGame = GameDef("OrbMan", "Star Chase", "Maze chase starring Ollie", "Help Ollie clear the stars, and dodge Blaze, Zip, Drift and Luna.", Mascot.Ollie,
|
||||
kidsSuitable = true, original = false, launchable = true, ScoreKind.Points, keepsLevels = false, legacyRecordKey = "orb_man_best",
|
||||
@@ -134,7 +140,7 @@ internal object ArcadeGames {
|
||||
listOf(Control("◀▶▲▼", "Point"), Control("OK", "Pick up / put down"), Control("OK twice", "Send a card home"), Control("Back", "Put back, or pause")),
|
||||
"Klondike, one card at a time: build each suit home, ace to king.") { PatienceScreen(it) }
|
||||
|
||||
val originals = listOf(OrbiRaiders, ChannelChaos, Hive, NightShift, Orbiteroids, QuizNight)
|
||||
val originals = listOf(OrbiRaiders, ChannelChaos, Hive, NightShift, Orbiteroids, QuizNight, TestCardTangle)
|
||||
val classics = listOf(OrbMan, Blast, Sky, Snake, Blocks, Bricks, Pairs, Patience)
|
||||
val all = originals + classics
|
||||
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
package tv.orbit.classic.arcade.tangle
|
||||
|
||||
/**
|
||||
* Test Card Tangle (9 November 2026): a calm puzzle. A grid of cable pieces has been knocked about; turn them (OK, a
|
||||
* quarter turn) until every piece joins up to the signal in the middle, with no loose ends, and Orbit's test card lights
|
||||
* up behind them. No timer, no fail: moves against a par. Suits Kids and Wind Down.
|
||||
*
|
||||
* Each level is a tangle with one answer pattern: a tree over every square from the signal (so it can always be solved),
|
||||
* its pieces then turned at random. The levels are fixed (each has its own seed), easiest first.
|
||||
*/
|
||||
internal const val T_N = 1; internal const val T_E = 2; internal const val T_S = 4; internal const val T_W = 8
|
||||
private val TDx = intArrayOf(0, 1, 0, -1); private val TDy = intArrayOf(-1, 0, 1, 0)
|
||||
private val TSide = intArrayOf(T_N, T_E, T_S, T_W)
|
||||
private fun opposite(s: Int) = when (s) { T_N -> T_S; T_S -> T_N; T_E -> T_W; else -> T_E }
|
||||
internal fun turnSides(m: Int, quarters: Int): Int { var x = m; repeat(((quarters % 4) + 4) % 4) { x = ((x shl 1) or (x shr 3)) and 15 }; return x }
|
||||
|
||||
internal class TangleLevel(val number: Int, val w: Int, val h: Int, val seed: Long) {
|
||||
/** The answer: each square's sides. */
|
||||
val solution: IntArray
|
||||
/** Where the pieces start: each square's sides, turned out of place. */
|
||||
val start: IntArray
|
||||
/** The fewest quarter turns to put every piece right (a straight is right either way round). */
|
||||
val minTurns: Int
|
||||
val source get() = (h / 2) * w + w / 2
|
||||
|
||||
init {
|
||||
val r = java.util.Random(seed)
|
||||
val n = w * h
|
||||
val sides = IntArray(n)
|
||||
// A random spanning tree from the signal: grow it a step at a time from any square already in it.
|
||||
val inTree = BooleanArray(n); inTree[source] = true
|
||||
val frontier = ArrayList<Int>(); frontier += source
|
||||
var placed = 1
|
||||
while (placed < n) {
|
||||
val from = frontier[r.nextInt(frontier.size)]
|
||||
val x = from % w; val y = from / w
|
||||
val open = (0..3).filter { k -> val nx = x + TDx[k]; val ny = y + TDy[k]; nx in 0 until w && ny in 0 until h && !inTree[ny * w + nx] }
|
||||
if (open.isEmpty()) { frontier.remove(from); continue }
|
||||
val k = open[r.nextInt(open.size)]
|
||||
val to = (y + TDy[k]) * w + x + TDx[k]
|
||||
sides[from] = sides[from] or TSide[k]; sides[to] = sides[to] or opposite(TSide[k])
|
||||
inTree[to] = true; frontier += to; placed++
|
||||
}
|
||||
solution = sides
|
||||
// Turn every piece out of place (a cross can't be, and a straight only by a quarter).
|
||||
val st = IntArray(n); var turns = 0
|
||||
for (i in 0 until n) {
|
||||
val q = 1 + r.nextInt(3)
|
||||
st[i] = turnSides(sides[i], q)
|
||||
// Turns back to right: the fewest quarter turns from where it starts to any way round that matches.
|
||||
turns += (0..3).first { turnSides(st[i], it) == sides[i] }
|
||||
}
|
||||
start = st; minTurns = turns
|
||||
}
|
||||
}
|
||||
|
||||
/** Owl's par equivalent: Drift's par, the fewest turns and a little room. */
|
||||
internal fun tanglePar(level: TangleLevel) = level.minTurns + 2 + level.w * level.h / 12
|
||||
|
||||
/** Stars: three on par or under, two a little over, one however long. */
|
||||
internal fun tangleStars(moves: Int, par: Int) = when { moves <= par -> 3; moves <= par + maxOf(3, par / 3) -> 2; else -> 1 }
|
||||
|
||||
/** The thirty levels: 4 by 3 up to 8 by 6, in three packs of ten. */
|
||||
internal val TangleLevels: List<TangleLevel> = run {
|
||||
val sizes = listOf(4 to 3, 4 to 3, 5 to 3, 5 to 4, 5 to 4, 6 to 4, 6 to 4, 6 to 4, 6 to 5, 6 to 5,
|
||||
6 to 5, 7 to 5, 7 to 5, 7 to 5, 7 to 5, 7 to 5, 8 to 5, 8 to 5, 8 to 5, 8 to 5,
|
||||
8 to 5, 8 to 6, 8 to 6, 8 to 6, 8 to 6, 8 to 6, 8 to 6, 8 to 6, 8 to 6, 8 to 6)
|
||||
sizes.mapIndexed { i, (w, h) -> TangleLevel(i + 1, w, h, 51_000L + i * 97L) }
|
||||
}
|
||||
internal val TanglePacks = listOf("Warming Up", "Tangled Up", "Picture Perfect")
|
||||
|
||||
/** One level being played: a cursor and the pieces' sides. Turns are moves; moving the cursor isn't. */
|
||||
internal class TangleGame(val level: TangleLevel, val sides: IntArray = level.start.copyOf(), val cursor: Int = level.source, val moves: Int = 0) {
|
||||
fun move(dx: Int, dy: Int): TangleGame {
|
||||
val x = (cursor % level.w + dx).coerceIn(0, level.w - 1); val y = (cursor / level.w + dy).coerceIn(0, level.h - 1)
|
||||
return TangleGame(level, sides, y * level.w + x, moves)
|
||||
}
|
||||
|
||||
/** OK: the piece under the cursor turns a quarter, clockwise. */
|
||||
fun turn(): TangleGame { val s = sides.copyOf(); s[cursor] = turnSides(s[cursor], 1); return TangleGame(level, s, cursor, moves + 1) }
|
||||
|
||||
/** The squares joined up to the signal, through sides that meet. */
|
||||
fun lit(): BooleanArray {
|
||||
val w = level.w; val n = w * level.h
|
||||
val on = BooleanArray(n); on[level.source] = true
|
||||
val todo = IntArray(n); var k = 0; todo[k++] = level.source
|
||||
while (k > 0) {
|
||||
val i = todo[--k]
|
||||
for (d in 0..3) {
|
||||
if (sides[i] and TSide[d] == 0) continue
|
||||
val x = i % w + TDx[d]; val y = i / w + TDy[d]
|
||||
if (x !in 0 until w || y !in 0 until level.h) continue
|
||||
val j = y * w + x
|
||||
if (on[j] || sides[j] and opposite(TSide[d]) == 0) continue
|
||||
on[j] = true; todo[k++] = j
|
||||
}
|
||||
}
|
||||
return on
|
||||
}
|
||||
|
||||
/** Done: every square joined to the signal and no cable pointing at nothing (an edge, or a side that doesn't meet). */
|
||||
val solved: Boolean get() {
|
||||
if (!lit().all { it }) return false
|
||||
val w = level.w
|
||||
for (i in sides.indices) for (d in 0..3) {
|
||||
if (sides[i] and TSide[d] == 0) continue
|
||||
val x = i % w + TDx[d]; val y = i / w + TDy[d]
|
||||
if (x !in 0 until w || y !in 0 until level.h) return false
|
||||
if (sides[y * w + x] and opposite(TSide[d]) == 0) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
/** A profile's progress: each level's best (stars and moves), in the game's level progress. */
|
||||
internal object TangleProgress {
|
||||
fun key(n: Int) = "tangle.$n"
|
||||
fun best(saved: Map<String, String>, n: Int): Pair<Int, Int>? = saved[key(n)]?.split(',')?.let { p -> p.getOrNull(0)?.toIntOrNull()?.let { it to (p.getOrNull(1)?.toIntOrNull() ?: 0) } }
|
||||
fun cleared(saved: Map<String, String>) = TangleLevels.count { best(saved, it.number) != null }
|
||||
fun stars(saved: Map<String, String>) = TangleLevels.sumOf { best(saved, it.number)?.first ?: 0 }
|
||||
/** The first level not yet done (or the last). */
|
||||
fun next(saved: Map<String, String>) = TangleLevels.firstOrNull { best(saved, it.number) == null }?.number ?: TangleLevels.size
|
||||
fun better(old: Pair<Int, Int>?, stars: Int, moves: Int) = old == null || stars > old.first || (stars == old.first && moves < old.second)
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
package tv.orbit.classic.arcade.tangle
|
||||
|
||||
import android.view.KeyEvent
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.focusable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.geometry.CornerRadius
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.StrokeCap
|
||||
import androidx.compose.ui.graphics.drawscope.DrawScope
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.tv.material3.Text
|
||||
import tv.orbit.classic.Anton
|
||||
import tv.orbit.classic.ArcadeBackdrop
|
||||
import tv.orbit.classic.ArcadeBackdropLayer
|
||||
import tv.orbit.classic.OrbCharacter
|
||||
import tv.orbit.classic.OrbDir
|
||||
import tv.orbit.classic.arcade.ArcadeButton
|
||||
import tv.orbit.classic.arcade.ArcadeColours
|
||||
import tv.orbit.classic.arcade.ArcadeGames
|
||||
import tv.orbit.classic.arcade.ArcadeKey
|
||||
import tv.orbit.classic.arcade.ArcadePauseMenu
|
||||
import tv.orbit.classic.arcade.ArcadePlay
|
||||
import tv.orbit.classic.arcade.ClassicTitle
|
||||
import tv.orbit.classic.arcade.Control
|
||||
import tv.orbit.classic.arcade.HowToPlayCard
|
||||
import tv.orbit.classic.arcade.HudLabel
|
||||
import tv.orbit.classic.arcade.HudValue
|
||||
import tv.orbit.classic.arcade.KeyFooter
|
||||
import tv.orbit.classic.arcade.RunEnd
|
||||
import tv.orbit.classic.arcade.SpeechBubble
|
||||
import tv.orbit.classic.arcade.classicPanel
|
||||
import tv.orbit.classic.arcade.gameKeys
|
||||
import tv.orbit.classic.arcade.onBackKey
|
||||
import tv.orbit.classic.drawOrbChaser
|
||||
import tv.orbit.classic.drawOrbMascot
|
||||
import tv.orbit.classic.starPath
|
||||
|
||||
/** Orbit's own test card's bars (not anyone else's card): the cast's colours across, as the tangle lights up. */
|
||||
internal val TestCardBars = listOf(Color(0xFFF4F6FB), Color(0xFFFFDE59), Color(0xFF35D6F2), Color(0xFF6EDCAA), Color(0xFFFF4FA3), Color(0xFFFF6B6B), Color(0xFFA77BFF), Color(0xFF3D63B8))
|
||||
|
||||
private enum class TStage { Title, Play, Done }
|
||||
|
||||
@Composable
|
||||
internal fun TestCardTangleScreen(play: ArcadePlay) {
|
||||
val gameDef = ArcadeGames.TestCardTangle
|
||||
val latestPlay by rememberUpdatedState(play)
|
||||
var saved by remember { mutableStateOf(play.level) }
|
||||
var stage by remember { mutableStateOf(TStage.Title) }
|
||||
var howTo by remember { mutableStateOf(false) }
|
||||
var paused by remember { mutableStateOf(false) }
|
||||
var game by remember { mutableStateOf(TangleGame(TangleLevels[TangleProgress.next(play.level) - 1])) }
|
||||
var finished by remember { mutableStateOf<Pair<Int, Int>?>(null) } // stars, moves
|
||||
val focus = remember { FocusRequester() }
|
||||
val backdrop = ArcadeBackdrop.TestCardDusk
|
||||
val par = tanglePar(game.level)
|
||||
|
||||
fun startLevel(n: Int) { game = TangleGame(TangleLevels[(n - 1).coerceIn(0, TangleLevels.lastIndex)]); paused = false; finished = null; stage = TStage.Play }
|
||||
LaunchedEffect(game) {
|
||||
if (stage != TStage.Play || !game.solved) return@LaunchedEffect
|
||||
val stars = tangleStars(game.moves, par)
|
||||
val old = TangleProgress.best(saved, game.level.number)
|
||||
if (TangleProgress.better(old, stars, game.moves)) {
|
||||
val v = "${maxOf(stars, old?.first ?: 0)},${if (old != null && old.first > stars) old.second else game.moves}"
|
||||
saved = saved + (TangleProgress.key(game.level.number) to v); latestPlay.setLevel(TangleProgress.key(game.level.number), v)
|
||||
}
|
||||
// The High Scores keep how many pictures are back on.
|
||||
latestPlay.onRunEnd(RunEnd(TangleProgress.cleared(saved), finished = true, detail = "Level ${game.level.number}"))
|
||||
finished = stars to game.moves
|
||||
stage = TStage.Done
|
||||
}
|
||||
LaunchedEffect(stage, paused) { if (stage == TStage.Play && !paused) runCatching { focus.requestFocus() } }
|
||||
BackHandler(stage == TStage.Play && !paused) { paused = true }
|
||||
|
||||
if (stage == TStage.Title) {
|
||||
val next = TangleProgress.next(saved)
|
||||
ClassicTitle(gameDef, backdrop, ArcadeColours.Cyan, "Help me get the picture back!",
|
||||
listOf("Pictures back on" to "${TangleProgress.cleared(saved)} of ${TangleLevels.size}", "Stars" to "${TangleProgress.stars(saved)}"),
|
||||
timed = false, difficulty = play.difficulty, refocus = !howTo, onPlay = { startLevel(next) }, onHowTo = { howTo = true }, onBack = { latestPlay.onLeave() },
|
||||
playLabel = "Level $next", kicker = "AN ORBIT ARCADE ORIGINAL", mode = TanglePacks[(next - 1) / 10],
|
||||
note = "Turn the cable pieces until every one joins up to the signal in the middle, with no loose ends, and the test card comes back. No timer, no rush.")
|
||||
if (howTo) HowToPlayCard(gameDef, firstRun = false, everyTime = null, onEveryTime = {}, onPlay = { howTo = false }, onBack = { howTo = false })
|
||||
return
|
||||
}
|
||||
val lit = remember(game) { game.lit() }
|
||||
val keys = Modifier.focusRequester(focus).focusable().gameKeys(enabled = stage == TStage.Play && !paused, pause = { paused = true }) { key, native ->
|
||||
if (native.action != KeyEvent.ACTION_DOWN) return@gameKeys key != ArcadeKey.Other
|
||||
val next = when (key) {
|
||||
ArcadeKey.Left -> game.move(-1, 0); ArcadeKey.Right -> game.move(1, 0)
|
||||
ArcadeKey.Up -> game.move(0, -1); ArcadeKey.Down -> game.move(0, 1)
|
||||
ArcadeKey.Ok -> if (native.repeatCount > 0) game else game.turn()
|
||||
else -> null
|
||||
}
|
||||
if (next != null) game = next
|
||||
next != null
|
||||
}
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
ArcadeBackdropLayer(backdrop)
|
||||
Column(Modifier.fillMaxSize().then(keys).padding(start = 32.dp, end = 32.dp, top = 20.dp, bottom = 10.dp)) {
|
||||
Row(Modifier.fillMaxWidth().weight(1f), horizontalArrangement = Arrangement.spacedBy(18.dp)) {
|
||||
Column(Modifier.width(176.dp).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(2.dp)) {
|
||||
HudLabel("LEVEL ${game.level.number} OF ${TangleLevels.size}")
|
||||
Text(TanglePacks[(game.level.number - 1) / 10].uppercase(), color = ArcadeColours.Ink, fontFamily = Anton, fontSize = 20.sp)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
HudLabel("MOVES"); HudValue("${game.moves}")
|
||||
HudLabel("DRIFT'S PAR"); HudValue("$par", ArcadeColours.Cyan)
|
||||
Spacer(Modifier.height(6.dp))
|
||||
val joined = lit.count { it }
|
||||
HudLabel("JOINED UP"); Text("$joined of ${lit.size}", color = ArcadeColours.Ink, fontSize = 16.sp, fontWeight = FontWeight.SemiBold)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Text("No timer. Take your time.", color = ArcadeColours.Muted, fontSize = 14.sp)
|
||||
Canvas(Modifier.size(56.dp)) { drawOrbChaser(center, size.minDimension * .38f, OrbCharacter.Drift, OrbDir.Down, false, false, false, 0f, eyesShut = false) }
|
||||
}
|
||||
Box(Modifier.weight(1f).fillMaxHeight(), contentAlignment = Alignment.Center) {
|
||||
Canvas(Modifier.fillMaxHeight().aspectRatio(game.level.w / game.level.h.toFloat()).classicPanel().padding(8.dp)) { drawTangle(game, lit, stage == TStage.Done) }
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.height(6.dp))
|
||||
KeyFooter(listOf(Control("◀▶▲▼", "Move"), Control("OK", "Turn the piece"), Control("Back", "Pause")))
|
||||
}
|
||||
if (stage == TStage.Done) finished?.let { (stars, moves) ->
|
||||
TangleDone(game.level.number, stars, moves, par, last = game.level.number == TangleLevels.size,
|
||||
onNext = { startLevel(game.level.number + 1) }, onReplay = { startLevel(game.level.number) }, onBack = { latestPlay.onLeave() })
|
||||
}
|
||||
if (paused && stage == TStage.Play) ArcadePauseMenu(gameDef, "Test Card Tangle · Level ${game.level.number} · ${game.moves} moves",
|
||||
onResume = { paused = false }, onRestart = { startLevel(game.level.number) }, onExit = { latestPlay.onLeave() })
|
||||
}
|
||||
}
|
||||
|
||||
/** The tangle over Orbit's test card: each square shows its bar of the card faintly, brightly once it's joined up. */
|
||||
private fun DrawScope.drawTangle(g: TangleGame, lit: BooleanArray, done: Boolean) {
|
||||
val w = g.level.w; val h = g.level.h
|
||||
val cell = minOf(size.width / w, size.height / h)
|
||||
val ox = (size.width - cell * w) / 2; val oy = (size.height - cell * h) / 2
|
||||
for (i in 0 until w * h) {
|
||||
val x = ox + i % w * cell; val y = oy + i / w * cell
|
||||
val bar = TestCardBars[(i % w) * TestCardBars.size / w]
|
||||
drawRect(bar.copy(alpha = if (done) 1f else if (lit[i]) .7f else .14f), Offset(x, y), Size(cell + .5f, cell + .5f))
|
||||
}
|
||||
if (done) {
|
||||
// The picture's back: Orbit's ring and Ollie in the middle of the card.
|
||||
val c = Offset(ox + cell * w / 2, oy + cell * h / 2); val r = minOf(cell * w, cell * h) * .3f
|
||||
drawCircle(Color(0xFF14213D), r, c); drawCircle(Color.White, r, c, style = Stroke(r * .08f))
|
||||
drawOrbMascot(c, r * .55f)
|
||||
return
|
||||
}
|
||||
for (i in 0 until w * h) {
|
||||
val c = Offset(ox + i % w * cell + cell / 2, oy + i / w * cell + cell / 2)
|
||||
val ends = arrayOf(Offset(0f, -cell / 2), Offset(cell / 2, 0f), Offset(0f, cell / 2), Offset(-cell / 2, 0f))
|
||||
val colour = if (lit[i]) Color(0xFF14213D) else Color(0xFFB4C0DA)
|
||||
for (k in 0..3) if (g.sides[i] and (1 shl k) != 0) drawLine(colour, c, c + ends[k], cell * .14f, StrokeCap.Round)
|
||||
if (i == g.level.source) { drawCircle(Color(0xFF14213D), cell * .22f, c); drawPath(starPath(c, cell * .16f, cell * .07f, 0f), ArcadeColours.Yellow) }
|
||||
else drawCircle(colour, cell * .09f, c)
|
||||
}
|
||||
val cur = g.cursor
|
||||
drawRoundRect(ArcadeColours.Yellow, Offset(ox + cur % w * cell + 3f, oy + cur / w * cell + 3f), Size(cell - 6f, cell - 6f), CornerRadius(cell * .12f), style = Stroke(4f))
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TangleDone(level: Int, stars: Int, moves: Int, par: Int, last: Boolean, onNext: () -> Unit, onReplay: () -> Unit, onBack: () -> Unit) {
|
||||
val first = remember { FocusRequester() }
|
||||
LaunchedEffect(Unit) { runCatching { first.requestFocus() } }
|
||||
BackHandler(onBack = onBack)
|
||||
Box(Modifier.fillMaxSize().onBackKey(action = onBack).background(ArcadeColours.Night.copy(alpha = .55f)), contentAlignment = Alignment.Center) {
|
||||
Column(Modifier.width(460.dp).background(ArcadeColours.PanelDeep, RoundedCornerShape(14.dp)).border(1.dp, ArcadeColours.Line, RoundedCornerShape(14.dp)).padding(20.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text("TEST CARD TANGLE · LEVEL $level", color = ArcadeColours.Muted, fontSize = 13.sp, letterSpacing = 3.sp)
|
||||
Text("PICTURE'S BACK ON!", color = ArcadeColours.Ink, fontFamily = Anton, fontSize = 32.sp)
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
Canvas(Modifier.size(96.dp, 30.dp)) { for (k in 0 until 3) { val c = Offset(15.dp.toPx() + k * 32.dp.toPx(), size.height / 2); drawPath(starPath(c, 13.dp.toPx(), 5.dp.toPx(), 0f), if (k < stars) ArcadeColours.Yellow else ArcadeColours.Line) } }
|
||||
Text("$moves moves · par $par", color = ArcadeColours.Ink, fontSize = 15.sp, fontWeight = FontWeight.SemiBold)
|
||||
}
|
||||
SpeechBubble(if (stars == 3) "Lovely and tidy." else "There we are. No rush.")
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
ArcadeButton(if (last) "Back to Arcade" else "Next level", Modifier.width(180.dp).focusRequester(first), icon = "▶", primary = true, height = 34.dp, onClick = if (last) onBack else onNext)
|
||||
ArcadeButton("Replay", Modifier.width(130.dp), icon = "↻", height = 34.dp, onClick = onReplay)
|
||||
}
|
||||
}
|
||||
KeyFooter(listOf(Control("◀▶", "Choose"), Control("OK", "Select"), Control("Back", "Arcade home")), Modifier.align(Alignment.BottomStart).padding(start = 24.dp, end = 24.dp, bottom = 10.dp))
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ class KidsArcadeTest {
|
||||
|
||||
@Test fun grownUpsSeeEveryGame() {
|
||||
assertEquals(ArcadeGames.all.map { it.id }, ids(grown))
|
||||
assertEquals(14, ids(grown).size)
|
||||
assertEquals(15, 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: 12 to play", arcadeForKidsLine(kids.withKidsArcade(KidsArcade.KidsSuitable)))
|
||||
assertEquals("Kids-suitable games: 13 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(6, ArcadeGames.originals.size); assertEquals(8, ArcadeGames.classics.size)
|
||||
assertEquals(7, 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"), ArcadeGames.originals.filter { it.launchable }.map { it.id })
|
||||
assertEquals(listOf("OrbiRaiders", "ChannelChaos", "Hive", "NightShift", "Orbiteroids", "QuizNight", "TestCardTangle"), 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,55 @@
|
||||
package tv.orbit.classic.arcade.tangle
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class TangleTest {
|
||||
/** The bot: walks to each piece and turns it until it matches the answer, counting turns as moves. */
|
||||
private fun bot(level: TangleLevel): TangleGame {
|
||||
var g = TangleGame(level)
|
||||
for (i in 0 until level.w * level.h) {
|
||||
while (g.cursor % level.w != i % level.w) g = g.move(Integer.signum(i % level.w - g.cursor % level.w), 0)
|
||||
while (g.cursor / level.w != i / level.w) g = g.move(0, Integer.signum(i / level.w - g.cursor / level.w))
|
||||
while (g.sides[i] != level.solution[i]) g = g.turn()
|
||||
}
|
||||
return g
|
||||
}
|
||||
|
||||
@Test fun thirtyLevelsGrowingAndNoneStartsSolved() {
|
||||
assertEquals(30, TangleLevels.size); assertEquals(3, TanglePacks.size)
|
||||
assertEquals(TangleLevels.map { it.w * it.h }.sorted(), TangleLevels.map { it.w * it.h })
|
||||
for (l in TangleLevels) {
|
||||
assertFalse("level ${l.number} starts solved", TangleGame(l).solved)
|
||||
// The answer is a proper tangle: every square joined, no loose end.
|
||||
assertTrue("level ${l.number}'s answer", TangleGame(l, l.solution.copyOf()).solved)
|
||||
assertTrue(l.solution.all { it != 0 })
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun aBotSolvesEveryLevelWithinDriftsPar() {
|
||||
for (l in TangleLevels) {
|
||||
val g = bot(l)
|
||||
assertTrue("level ${l.number}", g.solved)
|
||||
assertEquals("level ${l.number}", l.minTurns, g.moves)
|
||||
assertTrue(g.moves <= tanglePar(l))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun turningAndJoiningUp() {
|
||||
val l = TangleLevels[0]
|
||||
var g = TangleGame(l)
|
||||
assertTrue(g.lit()[l.source])
|
||||
val before = g.sides[g.cursor]; g = g.turn()
|
||||
assertEquals(turnSides(before, 1), g.sides[g.cursor]); assertEquals(1, g.moves)
|
||||
assertEquals(g.cursor, g.move(0, 0).cursor)
|
||||
assertEquals(0, g.move(-9, -9).cursor)
|
||||
}
|
||||
|
||||
@Test fun starsAndProgress() {
|
||||
assertEquals(3, tangleStars(10, 10)); assertEquals(2, tangleStars(13, 10)); assertEquals(1, tangleStars(30, 10))
|
||||
var saved = emptyMap<String, String>()
|
||||
assertEquals(1, TangleProgress.next(saved))
|
||||
saved = saved + (TangleProgress.key(1) to "3,8")
|
||||
assertEquals(2, TangleProgress.next(saved)); assertEquals(1, TangleProgress.cleared(saved)); assertEquals(3, TangleProgress.stars(saved))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user