Modern Apps git

← Modern-Apps.git

logicgate: refresh store listing, screenshots and module docs

Commit
5370f0f015c56a3bfc4fe9973b2b7db04449db74
Author
Vayun Mathur <[email protected]>
When
2026-11-01 18:25 UTC (1 month ago)
Parents
cc1e0ef
Brings the store listing and agent docs in line with the rebuilt game.

- MetadataPreviews renders three listing images from real state: the
  level map with the Basics chapter part-solved, a mid-solve XOR whose
  output is still taken from the OR (the 1 XOR 1 row is probed and the
  output is outlined red, header "first failure: 1 XOR 1 = 0"), and
  the same circuit solved with the completion overlay. Verification
  and wire values come from the simulator, not hand-written numbers.
- metadata_data/games-logicgate.md: new feature bullets (28 levels from
  NAND to a CPU running programs, real simulation, phone-first editor,
  buses, live values and stepping tests, stars against par).
- games/logicgate/AGENTS.md: new package layout (domain/data/platform/
  ui), tick and verification semantics, ISA, par/reference coupling,
  canvas world units, tray pull-out and drag-to-trash, row titles.

Verified with ./gradlew :games:logicgate:metadata (PNGs regenerated
and inspected) and ./gradlew checkMetadata (all listings well formed).

Diff

games/logicgate/AGENTS.md
diff --git a/games/logicgate/AGENTS.md b/games/logicgate/AGENTS.mdindex 679e94a520..9504fdba47 100644--- a/games/logicgate/AGENTS.md+++ b/games/logicgate/AGENTS.md@@ -3,59 +3,50 @@ > Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `games/logicgate/` + allowed shared modules. Do not root-scan.  _Install: ./install games/logicgate (dev by default)._-<!-- last-reviewed: 2026-10-16 -->+<!-- last-reviewed: 2026-11-01 --> - Gradle: :games:logicgate / dir: games/logicgate/-- Package roots present: ui, data, platform+- Package roots present: domain, data, platform, ui - Entry files: MainActivity.kt, Route.kt, Navigation.kt-- Deps: (none declared)+- Deps: :sdk:games - Metadata: metadata_data/games-logicgate.md (present) - Rust: no / screenshotTest: yes  ## Overview-**Purpose:** Logic-gate circuit puzzle — drag-to-connect gates over progressive levels incl. a Turing-gate finale. 100% offline.-**Game shape:** `ui/` circuit canvas (gates/wires/backdrop/transform) + game/progression screens → `platform/LogicViewModel` → `data/` circuit models + chip library + levels.-**Entry points:** `Route` → `MainActivity.kt` → `Navigation.kt` → `ui/GameScreen.kt` → `platform/LogicViewModel.kt` → `data/CircuitModel.kt`.-**Gotchas:** Canvas gesture math (`CanvasTransform`) and eval (`GameEval`) are the bug surface — keep transform/eval pure and unit-tested.+**Purpose:** NAND-to-computer circuit puzzle. 28 levels in 5 chapters (Basics, Routing & buses, Arithmetic, Memory, CPU). Every level is checked by a real cycle-accurate simulator, finishing with a CPU that runs three programs out of RAM. 100% offline.+**Game shape:** `domain/` (pure Kotlin: circuit model, chip catalog, simulator, verifier, levels) → `platform/LogicViewModel` (undo/redo, debounced re-verify on `Dispatchers.Default`) → `ui/` (one-canvas editor, chip tray, test panel, level map). `data/` persists drafts (DataStore key `logicgate2_circuits`) and best costs (`LevelStatsRepository` prefs `logicgate2_stats`).+**Entry points:** `Route` → `MainActivity.kt` → `Navigation.kt` → `ui/GamePage.kt` → `ui/GameScreen.kt` → `platform/LogicViewModel.kt` → `domain/sim/Verifier.kt`.+**Model:**+- Signals are `Int` bit masks on typed 1/4/8-bit pins. SPLIT/JOIN chips convert widths, and wires must match widths.+- Level I/O are real `LevelInput`/`LevelOutput` nodes. Unconnected inputs read 0.+- One tick of an implicit global clock = settle, then latch. Feedback loops iterate Gauss-Seidel (cap 64 passes → oscillation). State-only chips (DFF/REG/PC) break loops.+- Solving a level unlocks its chip as a trusted native behaviour (`domain/model/Chips.kt`). Level pins, tests and par for reward levels derive from that chip (`ChipLevel.kt`), so they cannot drift.+- ISA (`domain/model/Isa.kt`): `op[4]|operand[4]`, LDA STA ADD SUB LDI JMP JZ HLT, one instruction per tick via dual-port RAM16.+**Gotchas:**+- Pars are asserted equal to the reference solution costs in `src/test/.../domain/LevelSolutionsTest.kt`. Change a chip's `nandCost` and its reference together.+- `ui/canvas/` is world-unit geometry (≈dp at 1×). `CameraState.scale` already includes density, so canvas text uses `sizeWorld.toSp()`.+- Nothing edits on finger-down. Chips are created by pulling them up out of the tray (`ChipTray`: an upward drag claims the gesture, a sideways one scrolls) or by tapping them. Gates are deleted by dropping them back on the bottom area (`ui/canvas/TrashZone.kt`) or from the selection bar.+- Test rows carry plain-language titles (`domain/levels/RowTitles.kt`, e.g. `1 OR 1 = 1`), which are shown instead of row numbers.  ## Key files-### Root — entry + navigation-- com/vayunmathur/games/logicgate/MainActivity.kt-- com/vayunmathur/games/logicgate/Navigation.kt-- com/vayunmathur/games/logicgate/Route.kt-### data/ — circuits, chips, levels-- com/vayunmathur/games/logicgate/data/CircuitModel.kt-- com/vayunmathur/games/logicgate/data/ChipLibrary.kt-- com/vayunmathur/games/logicgate/data/Levels.kt-- com/vayunmathur/games/logicgate/data/ProgressRepository.kt-### platform/ — ViewModel + achievements-- com/vayunmathur/games/logicgate/platform/LogicViewModel.kt-- com/vayunmathur/games/logicgate/platform/LogicUiContract.kt-- com/vayunmathur/games/logicgate/platform/Achievements.kt-- com/vayunmathur/games/logicgate/platform/AppBackupAgent.kt-### ui/ — canvas + game + progression-- com/vayunmathur/games/logicgate/ui/GameScreen.kt-- com/vayunmathur/games/logicgate/ui/GamePage.kt-- com/vayunmathur/games/logicgate/ui/CircuitCanvas.kt-- com/vayunmathur/games/logicgate/ui/CircuitGates.kt-- com/vayunmathur/games/logicgate/ui/CircuitWires.kt-- com/vayunmathur/games/logicgate/ui/CircuitBackdrop.kt-- com/vayunmathur/games/logicgate/ui/CanvasTransform.kt-- com/vayunmathur/games/logicgate/ui/GameEval.kt-- com/vayunmathur/games/logicgate/ui/GameInventory.kt-- com/vayunmathur/games/logicgate/ui/GameLabels.kt-- com/vayunmathur/games/logicgate/ui/GameLayout.kt-- com/vayunmathur/games/logicgate/ui/GamePanels.kt-- com/vayunmathur/games/logicgate/ui/MobileTokens.kt-- com/vayunmathur/games/logicgate/ui/ProgressionScreen.kt-- com/vayunmathur/games/logicgate/ui/ProgressionPage.kt-- com/vayunmathur/games/logicgate/ui/TuringGate.kt-- com/vayunmathur/games/logicgate/ui/TuringTerminal.kt-- com/vayunmathur/games/logicgate/ui/Theme.kt-- com/vayunmathur/games/logicgate/ui/components/BitDotsRow.kt+### domain/ — pure, unit-tested+- domain/model/Circuit.kt — nodes, pins, wires, immutable edits, `sanitized`+- domain/model/ChipSpec.kt, domain/model/Chips.kt, domain/model/Isa.kt+- domain/sim/Simulator.kt, domain/sim/Scheduler.kt — tick semantics, SCC ordering+- domain/sim/Verifier.kt, domain/sim/TestSpec.kt, domain/sim/Scoring.kt+- domain/levels/LevelRegistry.kt + {Basics,Routing,Arithmetic,Memory,Cpu}Levels.kt+### data/ + platform/+- data/CircuitStore.kt, data/ProgressStore.kt+- platform/LogicUiContract.kt (state + `LogicActions.Noop`), platform/LogicViewModel.kt+- platform/LogicAchievements.kt (`assets/achievements.json`, ids `lg2_*`), platform/AppBackupAgent.kt+### ui/+- ui/GameScreen.kt, ui/CircuitCanvas.kt, ui/ChipTray.kt, ui/TestPanel.kt, ui/SelectionBar.kt+- ui/BriefSheet.kt, ui/BusValueDialog.kt, ui/LevelCompleteOverlay.kt, ui/ProgressionScreen.kt, ui/StarRating.kt+- ui/canvas/ — Camera, CameraState, GateGeometry (layout), HitTest, CanvasGestures, CanvasController, GatePainter, GateShapes  ## Verify (this module only) ```+./gradlew :games:logicgate:testDevUnitTest ./gradlew :games:logicgate:compileDevKotlin-./gradlew :games:logicgate:lint+./check games/logicgate ./gradlew :games:logicgate:checkMetadata ```
games/logicgate/src/screenshotTest/kotlin/com/vayunmathur/games/logicgate/ui/MetadataPreviews.kt
diff --git a/games/logicgate/src/screenshotTest/kotlin/com/vayunmathur/games/logicgate/ui/MetadataPreviews.kt b/games/logicgate/src/screenshotTest/kotlin/com/vayunmathur/games/logicgate/ui/MetadataPreviews.ktindex 4d4ff94e11..7515e1e9c2 100644--- a/games/logicgate/src/screenshotTest/kotlin/com/vayunmathur/games/logicgate/ui/MetadataPreviews.kt+++ b/games/logicgate/src/screenshotTest/kotlin/com/vayunmathur/games/logicgate/ui/MetadataPreviews.kt@@ -3,98 +3,108 @@ package com.vayunmathur.games.logicgate.ui import androidx.compose.runtime.Composable import androidx.compose.ui.tooling.preview.Preview import com.android.tools.screenshot.PreviewTest-import com.vayunmathur.games.logicgate.data.Circuit-import com.vayunmathur.games.logicgate.data.IoPos-import com.vayunmathur.games.logicgate.data.OutputMapping-import com.vayunmathur.games.logicgate.data.PlacedChip-import com.vayunmathur.games.logicgate.data.Wire-import com.vayunmathur.games.logicgate.data.WireEnd-import com.vayunmathur.games.logicgate.platform.EvalStatus+import com.vayunmathur.games.logicgate.domain.levels.LevelRegistry+import com.vayunmathur.games.logicgate.domain.model.Chips+import com.vayunmathur.games.logicgate.domain.model.Circuit+import com.vayunmathur.games.logicgate.domain.model.LevelInput+import com.vayunmathur.games.logicgate.domain.model.LevelOutput+import com.vayunmathur.games.logicgate.domain.model.NodeId+import com.vayunmathur.games.logicgate.domain.model.PinRef+import com.vayunmathur.games.logicgate.domain.model.PinSide+import com.vayunmathur.games.logicgate.domain.model.Point+import com.vayunmathur.games.logicgate.domain.sim.Scoring+import com.vayunmathur.games.logicgate.domain.sim.Verifier+import com.vayunmathur.games.logicgate.platform.GameUiState+import com.vayunmathur.games.logicgate.platform.LevelCard import com.vayunmathur.games.logicgate.platform.LogicActions-import com.vayunmathur.games.logicgate.platform.UiState-import com.vayunmathur.games.logicgate.ui.GameScreen+import com.vayunmathur.games.logicgate.platform.ProgressionUiState  /** Phone-shaped, roughly 1080x2340 at xxhdpi — comfortably above the F-Droid minimum. */ private const val PHONE = "spec:width=411dp,height=891dp,dpi=420"  /**- * Store listing images for `:games:logicgate`, rendered from Compose previews instead of- * from an instrumented test on a device. See `common-conventions-preview-metadata`.+ * Store listing images for `:games:logicgate`. See `common-conventions-preview-metadata`.  *- * Rendering goes through the app's real [LogicGateTheme] rather than `DynamicTheme` — this- * app ships a fixed palette and never follows the wallpaper, so the theme it uses at- * runtime is the one that belongs in the listing.- *- * Each preview needs @PreviewTest as well as @Preview: @Preview alone renders in Studio but- * is not collected as a screenshot test. Previews must also be class members, not top-level- * functions. Order comes from the function names (Preview1…, Preview2…).+ * Each preview needs @PreviewTest as well as @Preview, and must be a class member. Order comes+ * from the function names. Rendering goes through [LogicGateTheme] because the app ships a fixed+ * palette. The circuits are real: verification and live wire values come from the simulator.  */ class MetadataPreviews { -    /** Through XOR, so the map shows completed nodes, two playable ones and locked ones. */-    private val completed = setOf("NOT", "AND", "OR", "XOR")--    /**-     * A half-built XOR: NAND(a,b) and OR(a,b) both feed an AND, which is the classic-     * `(a|b) & !(a&b)` construction. Terminal positions are pinned so the layout does not-     * depend on the canvas measuring itself first.-     */-    private val gates = listOf(-        PlacedChip("g_nand", "NAND", x = 330f, y = 170f),-        PlacedChip("g_or", "OR", x = 330f, y = 470f),-        PlacedChip("g_and", "AND", x = 620f, y = 320f),-    )--    private val wires = listOf(-        Wire("w_a_nand", WireEnd("__IN_0", 0), WireEnd("g_nand", 0)),-        Wire("w_b_nand", WireEnd("__IN_1", 0), WireEnd("g_nand", 1)),-        Wire("w_a_or", WireEnd("__IN_0", 0), WireEnd("g_or", 0)),-        Wire("w_b_or", WireEnd("__IN_1", 0), WireEnd("g_or", 1)),-        Wire("w_nand_and", WireEnd("g_nand", 0), WireEnd("g_and", 0)),-        Wire("w_or_and", WireEnd("g_or", 0), WireEnd("g_and", 1)),-    )+    private val xor = requireNotNull(LevelRegistry["xor"])+    private val lookup = Chips.lookup(xor.io) -    private val terminals = Circuit(-        inputPositions = mapOf(0 to IoPos(140f, 240f), 1 to IoPos(140f, 560f)),-        outputPositions = mapOf(0 to IoPos(900f, 400f)),-    )--    private fun circuit(outputFrom: String) = terminals.copy(-        gates = gates,-        wires = wires,-        outputMappings = listOf(OutputMapping(0, WireEnd(outputFrom, 0))),-    )+    /** `(a OR b) AND (a NAND b)`, with the board output taken from [outputFrom] (`or` or `and`). */+    private fun xorCircuit(outputFrom: String): Circuit {+        var c = Circuit.forLevel(xor.io)+        val a = c.nodes.first { it is LevelInput && it.index == 0 }.id+        val b = c.nodes.first { it is LevelInput && it.index == 1 }.id+        val o = c.nodes.first { it is LevelOutput }.id+        fun add(chip: String, x: Float, y: Float): NodeId = c.addGate(chip, Point(x, y)).let { (next, id) -> c = next; id }+        fun wire(from: NodeId, to: NodeId, pin: Int) {+            c = requireNotNull(c.connect(PinRef(from, PinSide.OUT, 0), PinRef(to, PinSide.IN, pin), lookup))+        }+        val nand = add(Chips.NAND, 112f, -112f)+        val or = add(Chips.OR, 112f, 56f)+        val and = add(Chips.AND, 266f, -28f)+        wire(a, nand, 0)+        wire(b, nand, 1)+        wire(a, or, 0)+        wire(b, or, 1)+        wire(nand, and, 0)+        wire(or, and, 1)+        wire(if (outputFrom == "and") and else or, o, 0)+        return c+    } -    /** NAND, NOT, AND, OR — everything the XOR level allows, so the palette is full. */-    private val unlocked = setOf("NAND", "NOT", "AND", "OR")+    private fun gameState(circuit: Circuit, probe: Int?, won: Boolean): GameUiState {+        val result = Verifier.verify(xor.io, xor.tests, circuit)+        val cost = Scoring.cost(circuit) { Chips[it]?.nandCost }+        val live = probe?.let { Verifier.probe(xor.io, xor.tests, circuit, it) } ?: Verifier.manual(xor.io, circuit, listOf(1, 0))+        return GameUiState(+            level = xor,+            circuit = circuit,+            chips = LevelRegistry.allowedChips(xor.id).mapNotNull { Chips[it] },+            manualInputs = listOf(1, 0),+            verify = result,+            probeCase = probe,+            live = live,+            canUndo = true,+            won = won,+            stars = Scoring.stars(result.solved, cost, xor.par),+            cost = cost,+            fitToken = 1,+            nextLevelId = LevelRegistry.next(xor.id)?.id,+        )+    }      @PreviewTest     @Preview(name = "1-levels", device = PHONE, group = "phone", showSystemUi = true)     @Composable     fun Preview1Levels() {-        LogicGateTheme {-            ProgressionScreen(completed = completed)+        val best = mapOf("not" to 1, "and" to 2, "or" to 3, "nor" to 5)+        val cards = LevelRegistry.levels.mapIndexed { i, l ->+            LevelCard(+                id = l.id,+                number = i + 1,+                title = l.title,+                chapter = l.chapter,+                unlocked = LevelRegistry.isUnlocked(l.id, best.keys),+                stars = best[l.id]?.let { Scoring.stars(true, it, l.par) } ?: 0,+                bestCost = best[l.id],+                par = l.par,+            )         }+        LogicGateTheme { ProgressionScreen(ProgressionUiState(cards), onOpenLevel = {}, onOpenGameCenter = {}) }     }      @PreviewTest     @Preview(name = "2-circuit", device = PHONE, group = "phone", showSystemUi = true)     @Composable     fun Preview2Circuit() {+        // Output still taken off the OR: the a=1, b=1 row is probed and the output shows the miss.         LogicGateTheme {-            // Output still taken straight off the OR, so three of the four rows pass and-            // the testbench shows the one that does not.-            GameScreen(-                levelId = "XOR",-                state = UiState(-                    currentLevelId = "XOR",-                    circuit = circuit(outputFrom = "g_or"),-                    evalStatus = EvalStatus.Ok(passingRows = 3, totalRows = 4, isFullyCorrect = false, failingRows = listOf(3)),-                    canUndo = true,-                ),-                unlockedChips = unlocked,-                actions = LogicActions.Noop,-            )+            GameScreen(gameState(xorCircuit("or"), probe = 3, won = false), LogicActions.Noop, onBack = {}, onNext = {})         }     } @@ -103,19 +113,7 @@ class MetadataPreviews {     @Composable     fun Preview3Solved() {         LogicGateTheme {-            // Same circuit with the output moved to the AND, which makes it a real XOR.-            GameScreen(-                levelId = "XOR",-                state = UiState(-                    currentLevelId = "XOR",-                    circuit = circuit(outputFrom = "g_and"),-                    evalStatus = EvalStatus.Ok(passingRows = 4, totalRows = 4, isFullyCorrect = true, failingRows = emptyList()),-                    canUndo = true,-                ),-                unlockedChips = unlocked,-                actions = LogicActions.Noop,-                initialShowWinDialog = true,-            )+            GameScreen(gameState(xorCircuit("and"), probe = null, won = true), LogicActions.Noop, onBack = {}, onNext = {})         }     } }
metadata_data/games-logicgate.md
diff --git a/metadata_data/games-logicgate.md b/metadata_data/games-logicgate.mdindex 15548226f9..57ab1bd018 100644--- a/metadata_data/games-logicgate.md+++ b/metadata_data/games-logicgate.md@@ -1,9 +1,13 @@-A logic gate puzzle game - wire up circuits to solve levels+A logic gate puzzle game: start with NAND, end with a working computer  Features:-- Intuitive drag-to-connect gate wiring-- Progressive difficulty with new gate types+- 28 levels across five chapters, from NOT and XOR through adders, an ALU, registers and RAM to a CPU+- Finish by wiring your own CPU to memory and running real programs on it+- Every level is checked by a real cycle-accurate simulator, with no shortcuts+- Phone-first editor: tap a chip to add it, drag from a pin to wire, pinch to zoom, undo and redo+- Multi-bit buses with split and join chips+- Live wire values, and a test table you can step through row by row+- Stars for beating each level's NAND-count par - Achievements, with progress reported to MA GameHub-- Material You design  100% offline
metadata_data/photos/games-logicgate/phone/1.png
diff --git a/metadata_data/photos/games-logicgate/phone/1.png b/metadata_data/photos/games-logicgate/phone/1.pngindex 42de9fe192..c01d447e91 100644Binary files a/metadata_data/photos/games-logicgate/phone/1.png and b/metadata_data/photos/games-logicgate/phone/1.png differ
metadata_data/photos/games-logicgate/phone/2.png
diff --git a/metadata_data/photos/games-logicgate/phone/2.png b/metadata_data/photos/games-logicgate/phone/2.pngindex b5f59250b4..d67a038b65 100644Binary files a/metadata_data/photos/games-logicgate/phone/2.png and b/metadata_data/photos/games-logicgate/phone/2.png differ
metadata_data/photos/games-logicgate/phone/3.png
diff --git a/metadata_data/photos/games-logicgate/phone/3.png b/metadata_data/photos/games-logicgate/phone/3.pngindex fd9e063e01..d13913bd4a 100644Binary files a/metadata_data/photos/games-logicgate/phone/3.png and b/metadata_data/photos/games-logicgate/phone/3.png differ