Modern Apps git

← Modern-Apps.git

Logic Gate: remove optimality entirely

Commit
dd89094ab31550f10847285db5ac4e1de069a5b1
Author
Vayun Mathur <[email protected]>
When
2026-07-22 21:01 UTC (4 months ago)
Parents
d0ac71c
- Delete optimalNands from LevelDef, Levels.all (no optimal targets)
- Remove bestNands/bestScore tracking from ViewModel and ProgressRepository (now simple completed set)
- ProgressionScreen: nodes show DONE/PLAY/LOCK only, no stars, no N counter
- GameScreen status: ✓ CORRECT only, no gate N vs optimal, badge shows gate count not NAND cost
- Inventory: shows IO width only, not NAND cost
- Achievements: removed optimal_5, only completion-based chapters + first_gate + all_levels
- Strings: removed optimal/your_gates/nand_count leftover
- DAG still max 2 open validated

Diff

games/logicgate/src/main/assets/achievements.json
diff --git a/games/logicgate/src/main/assets/achievements.json b/games/logicgate/src/main/assets/achievements.jsonindex f1c00cdb06..d5b3ccc027 100644--- a/games/logicgate/src/main/assets/achievements.json+++ b/games/logicgate/src/main/assets/achievements.json@@ -5,6 +5,5 @@   {"id": "arith_complete", "name": "Arithmetician", "description": "Complete Arithmetic chapter (4 levels)", "targetProgress": 4},   {"id": "memory_complete", "name": "Mnemosyne", "description": "Complete Memory chapter (3 levels)", "targetProgress": 3},   {"id": "cpu_complete", "name": "CPU Architect", "description": "Complete CPU chapter (2 levels)", "targetProgress": 2},-  {"id": "optimal_5", "name": "Perfectionist", "description": "Build 5 levels with optimal NAND count", "targetProgress": 5},   {"id": "all_levels", "name": "NAND to CPU", "description": "Complete all 18 levels and build the 8-bit CPU", "targetProgress": 18} ]
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/MainActivity.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/MainActivity.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/MainActivity.ktindex 20c8a1e224..7c48d03a54 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/MainActivity.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/MainActivity.kt@@ -158,7 +158,7 @@ fun GameScreen(backStack: NavBackStack<Route>, viewModel: LogicViewModel, levelI         ) {             val status = uiState.evalStatus             val statusText = when (status) {-                is EvalStatus.Ok -> if (status.isFullyCorrect) "✓ CORRECT — ${uiState.circuit.gates.sumOf { com.vayunmathur.games.logicgate.data.ChipLibrary.get(it.chipId).nandCost }}N / ${level.optimalNands}N optimal"+                is EvalStatus.Ok -> if (status.isFullyCorrect) "✓ CORRECT"                 else "${status.passingRows}/${status.totalRows} passing — ${status.failingRows.size} failing"                  is EvalStatus.Error -> "Error: ${status.msg}"@@ -188,9 +188,9 @@ fun GameScreen(backStack: NavBackStack<Route>, viewModel: LogicViewModel, levelI                         if (uiState.wiringFrom != null) {                             Button(onClick = { viewModel.cancelWiring() }) { Text("Cancel Wire", fontSize = 10.sp) }                         }-                        val nandCost = uiState.circuit.gates.sumOf { com.vayunmathur.games.logicgate.data.ChipLibrary.get(it.chipId).nandCost }+                        val gateCount = uiState.circuit.gates.size                         Card(modifier = Modifier.padding(start = 4.dp)) {-                            Text(" ${nandCost}N ", fontSize = 11.sp, modifier = Modifier.padding(horizontal = 6.dp, vertical = 2.dp))+                            Text(" $gateCount gates ", fontSize = 11.sp, modifier = Modifier.padding(horizontal = 6.dp, vertical = 2.dp))                         }                     }                 }
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/data/Levels.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/data/Levels.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/data/Levels.ktindex 3ee5e88a1b..d01a5424fd 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/data/Levels.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/data/Levels.kt@@ -2,7 +2,7 @@ package com.vayunmathur.games.logicgate.data  /**  * Level progression DAG: max 2 open at any time, chapters separated.- * Prereqs define unlock. Visual layout rows defined below for timeline.+ * Prereqs define unlock. Optimality removed - pure completion gated.  */  enum class ChapterId { FOUNDATION, ROUTING, ARITH, MEMORY, CPU }@@ -24,7 +24,6 @@ data class LevelDef(     val outputs: List<String>,     val targetChipId: String,     val allowedChipIds: List<String>,-    val optimalNands: Int,     val flavor: String = "",     val unlocksChipId: String? = null,     val prereqs: List<String> = emptyList()@@ -42,7 +41,6 @@ object Levels {             outputs = listOf("out"),             targetChipId = "NOT",             allowedChipIds = listOf("NAND"),-            optimalNands = 1,             flavor = "Everything starts with NAND.",             unlocksChipId = "NOT",             prereqs = emptyList()@@ -57,7 +55,6 @@ object Levels {             outputs = listOf("out"),             targetChipId = "AND",             allowedChipIds = listOf("NAND", "NOT"),-            optimalNands = 2,             flavor = "NOT unlocked! Now combine.",             unlocksChipId = "AND",             prereqs = listOf("NOT")@@ -72,7 +69,6 @@ object Levels {             outputs = listOf("out"),             targetChipId = "OR",             allowedChipIds = listOf("NAND", "NOT", "AND"),-            optimalNands = 3,             flavor = "De Morgan is your friend.",             unlocksChipId = "OR",             prereqs = listOf("AND")@@ -87,7 +83,6 @@ object Levels {             outputs = listOf("out"),             targetChipId = "XOR",             allowedChipIds = listOf("NAND", "NOT", "AND", "OR"),-            optimalNands = 4,             flavor = "The key to addition.",             unlocksChipId = "XOR",             prereqs = listOf("OR")@@ -102,7 +97,6 @@ object Levels {             outputs = listOf("out"),             targetChipId = "NOR",             allowedChipIds = listOf("NAND", "NOT", "AND", "OR", "XOR"),-            optimalNands = 4,             unlocksChipId = "NOR",             prereqs = listOf("XOR")         ),@@ -116,7 +110,6 @@ object Levels {             outputs = listOf("out"),             targetChipId = "XNOR",             allowedChipIds = listOf("NAND", "NOT", "AND", "OR", "XOR", "NOR"),-            optimalNands = 5,             unlocksChipId = "XNOR",             prereqs = listOf("XOR")         ),@@ -131,7 +124,6 @@ object Levels {             outputs = listOf("out"),             targetChipId = "MUX",             allowedChipIds = listOf("NAND", "NOT", "AND", "OR", "XOR"),-            optimalNands = 4,             flavor = "Choose between signals.",             unlocksChipId = "MUX",             prereqs = listOf("NOR", "XNOR")@@ -146,7 +138,6 @@ object Levels {             outputs = listOf("a", "b"),             targetChipId = "DMUX",             allowedChipIds = listOf("NAND", "NOT", "AND", "OR", "XOR", "MUX"),-            optimalNands = 3,             unlocksChipId = "DMUX",             prereqs = listOf("MUX")         ),@@ -160,7 +151,6 @@ object Levels {             outputs = listOf("out"),             targetChipId = "MUX4",             allowedChipIds = listOf("NAND", "NOT", "AND", "OR", "XOR", "MUX", "DMUX"),-            optimalNands = 12,             unlocksChipId = "MUX4",             prereqs = listOf("MUX")         ),@@ -175,7 +165,6 @@ object Levels {             outputs = listOf("sum", "carry"),             targetChipId = "HALF_ADDER",             allowedChipIds = listOf("NAND", "NOT", "AND", "OR", "XOR", "MUX"),-            optimalNands = 6,             flavor = "1-bit addition.",             unlocksChipId = "HALF_ADDER",             prereqs = listOf("DMUX", "MUX4")@@ -190,7 +179,6 @@ object Levels {             outputs = listOf("sum", "cout"),             targetChipId = "FULL_ADDER",             allowedChipIds = listOf("NAND", "NOT", "AND", "OR", "XOR", "MUX", "HALF_ADDER"),-            optimalNands = 14,             flavor = "Brick of binary addition.",             unlocksChipId = "FULL_ADDER",             prereqs = listOf("HALF_ADDER")@@ -205,7 +193,6 @@ object Levels {             outputs = listOf("s0","s1","s2","s3","cout"),             targetChipId = "ADDER_4",             allowedChipIds = listOf("NAND", "NOT", "AND", "OR", "XOR", "HALF_ADDER", "FULL_ADDER"),-            optimalNands = 56,             unlocksChipId = "ADDER_4",             prereqs = listOf("HALF_ADDER")         ),@@ -219,7 +206,6 @@ object Levels {             outputs = (0..7).map { "s$it" } + listOf("cout"),             targetChipId = "ADDER_8",             allowedChipIds = listOf("NAND", "NOT", "AND", "OR", "XOR", "HALF_ADDER", "FULL_ADDER", "ADDER_4"),-            optimalNands = 112,             flavor = "Heart of CPU.",             unlocksChipId = "ADDER_8",             prereqs = listOf("FULL_ADDER", "ADDER_4")@@ -235,7 +221,6 @@ object Levels {             outputs = listOf("q"),             targetChipId = "DFF",             allowedChipIds = listOf("NAND", "NOT", "AND", "OR", "XOR", "MUX"),-            optimalNands = 6,             flavor = "Time enters.",             unlocksChipId = "DFF",             prereqs = listOf("ADDER_8")@@ -250,7 +235,6 @@ object Levels {             outputs = listOf("out"),             targetChipId = "BIT",             allowedChipIds = ChipLibrary.all.keys.filter { it != "CPU_8" && it != "REG_8" && it != "ALU_8" }.toList(),-            optimalNands = 12,             unlocksChipId = "BIT",             prereqs = listOf("DFF")         ),@@ -264,7 +248,6 @@ object Levels {             outputs = (0..7).map { "out$it" },             targetChipId = "REG_8",             allowedChipIds = ChipLibrary.all.keys.filter { it != "CPU_8" && it != "ALU_8" }.toList(),-            optimalNands = 96,             unlocksChipId = "REG_8",             prereqs = listOf("BIT")         ),@@ -279,7 +262,6 @@ object Levels {             outputs = (0..7).map { "out$it" } + listOf("zero","carry"),             targetChipId = "ALU_8",             allowedChipIds = ChipLibrary.all.keys.filter { it != "CPU_8" }.toList(),-            optimalNands = 200,             flavor = "Calculator of CPU.",             unlocksChipId = "ALU_8",             prereqs = listOf("REG_8")@@ -294,7 +276,6 @@ object Levels {             outputs = (0..7).map { "out$it" } + (0..7).map { "addr$it" } + listOf("write"),             targetChipId = "CPU_8",             allowedChipIds = ChipLibrary.all.keys.toList(),-            optimalNands = 2000,             flavor = "NAND to computer. Done.",             unlocksChipId = "CPU_8",             prereqs = listOf("ALU_8")@@ -312,7 +293,6 @@ object Levels {     val byId: Map<String, LevelDef> = all.associateBy { it.id }     fun get(id: String): LevelDef = byId[id] ?: error("Unknown level $id") -    // Timeline rows for progression UI (1 or 2 nodes per row, max 2 open)     val timelineRows: List<List<String>> = listOf(         listOf("NOT"),         listOf("AND"),
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/data/ProgressRepository.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/data/ProgressRepository.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/data/ProgressRepository.ktindex fe1bd4e5ae..b59179dc41 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/data/ProgressRepository.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/data/ProgressRepository.kt@@ -1,32 +1,45 @@ package com.vayunmathur.games.logicgate.data  import android.content.Context-import com.vayunmathur.library.util.LevelStatsRepository+import android.content.SharedPreferences+import androidx.core.content.edit -class LogicProgressRepository(context: Context) : LevelStatsRepository(context, "logicgate_stats") {-    fun getCompletedLevelIds(): Set<String> = getLevelStats().keys+class LogicProgressRepository(context: Context) {+    private val prefs: SharedPreferences = context.getSharedPreferences("logicgate_stats", Context.MODE_PRIVATE) -    fun isLevelComplete(id: String): Boolean = getLevelStats().containsKey(id)+    fun getCompletedLevelIds(): Set<String> {+        return prefs.getStringSet(KEY_COMPLETED, emptySet())?.toSet() ?: emptySet()+    } -    fun bestNandCount(levelId: String): Int? = getLevelStats()[levelId]?.bestScore+    fun isLevelComplete(id: String): Boolean = id in getCompletedLevelIds() -    // we reuse bestScore as nand count (lower is better, but LevelStatsRepository keeps min)-    // so storing nand count directly works+    fun markCompleted(id: String) {+        val current = getCompletedLevelIds()+        if (id !in current) {+            prefs.edit { putStringSet(KEY_COMPLETED, (current + id).toMutableSet()) }+        }+    }      fun unlockedChipIds(): Set<String> {         val completed = getCompletedLevelIds()         val chips = mutableSetOf("NAND")         for (lvlId in completed) {-            val lvl = Levels.byId[lvlId] ?: continue-            lvl.unlocksChipId?.let { chips.add(it) }+            Levels.byId[lvlId]?.unlocksChipId?.let { chips.add(it) }         }         return chips     } -    fun totalCompleted(): Int = getLevelStats().size+    fun totalCompleted(): Int = getCompletedLevelIds().size -    fun incCircuitsChecked() = incrementCounter("circuits_checked")-    fun getCircuitsChecked(): Int = getCounter("circuits_checked")+    fun incCircuitsChecked() { prefs.edit { putInt("circuits_checked", prefs.getInt("circuits_checked", 0) + 1) } }+    fun getCircuitsChecked(): Int = prefs.getInt("circuits_checked", 0) -    fun setChipHintUsed(chipId: String) = incrementCounter("hint_$chipId")+    // For achievements compatibility+    fun getLevelStats(): Map<String, DummyStat> = getCompletedLevelIds().associateWith { DummyStat() }++    data class DummyStat(val bestScore: Int = 0)++    companion object {+        private const val KEY_COMPLETED = "completed_levels"+    } }
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/Screens.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/Screens.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/Screens.ktindex 5a3df6e68f..d8000d0020 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/Screens.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/Screens.kt@@ -19,12 +19,11 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Color-import androidx.compose.ui.text.font.FontStyle-import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.compose.ui.res.painterResource+import androidx.compose.ui.text.font.FontWeight import com.vayunmathur.games.logicgate.data.ChapterId import com.vayunmathur.games.logicgate.data.ChipCategory import com.vayunmathur.games.logicgate.data.ChipLibrary@@ -32,7 +31,6 @@ import com.vayunmathur.games.logicgate.data.CircuitEvaluator import com.vayunmathur.games.logicgate.data.LevelDef import com.vayunmathur.games.logicgate.data.Levels import com.vayunmathur.games.logicgate.util.LogicViewModel-import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.Icon@@ -72,7 +70,6 @@ fun ProgressionScreen(     viewModel: LogicViewModel ) {     val completed by viewModel.completedIds.collectAsState()-    val bestNands by viewModel.bestNands.collectAsState()     val available = Levels.availableLevels(completed)     val timelineItems = buildTimelineItems() @@ -129,11 +126,9 @@ fun ProgressionScreen(                     val item = timelineItems[idx]                     when (item) {                         is TimelineItem.ChapterHeader -> {-                            // Connector from previous row into this chapter bar (merge)                             if (idx > 0) {                                 val prev = timelineItems[idx - 1]                                 if (prev is TimelineItem.LevelRow) {-                                    // Determine if any next level depends on prev – always draw merge visually                                     MergeIntoChapterConnector(                                         fromRow = prev,                                         sideOffset = sideOffset,@@ -153,7 +148,6 @@ fun ProgressionScreen(                                     .padding(horizontal = 12.dp)                             ) -                            // Connector out of chapter into next row                             if (idx + 1 < timelineItems.size) {                                 val next = timelineItems[idx + 1]                                 if (next is TimelineItem.LevelRow) {@@ -172,9 +166,7 @@ fun ProgressionScreen(                                 row = item,                                 completed = completed,                                 available = available,-                                bestNands = bestNands,                                 nodeSize = nodeSize,-                                sideOffset = sideOffset,                                 onClickLevel = { lvlId ->                                     if (lvlId in completed || lvlId in available) {                                         backStack.add(com.vayunmathur.games.logicgate.Route.Game(lvlId))@@ -182,7 +174,6 @@ fun ProgressionScreen(                                 }                             ) -                            // Connector to next level row (skip if next is header)                             if (idx + 1 < timelineItems.size) {                                 val next = timelineItems[idx + 1]                                 if (next is TimelineItem.LevelRow) {@@ -214,7 +205,7 @@ fun ProgressionScreen(                         )                         Spacer(Modifier.height(8.dp))                         Text(-                            "Progress is gated: you must finish prerequisites to unlock next. At most 2 paths run in parallel (NOR/XNOR, DMUX/MUX4, FULL_ADDER/ADDER_4). Each chapter starts with a thick bar.",+                            "Progress is gated by prerequisites. At most 2 paths are open at once (NOR/XNOR, DMUX/MUX4, FULL_ADDER/ADDER_4). Each chapter starts with a thick bar.",                             style = MaterialTheme.typography.bodySmall,                             color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)                         )@@ -266,15 +257,13 @@ private fun LevelRowContent(     row: TimelineItem.LevelRow,     completed: Set<String>,     available: Set<String>,-    bestNands: Map<String, Int>,     nodeSize: Dp,-    sideOffset: Dp,     onClickLevel: (String) -> Unit ) {     Row(         modifier = Modifier             .fillMaxWidth()-            .height(120.dp),+            .height(110.dp),         horizontalArrangement = Arrangement.Center,         verticalAlignment = Alignment.CenterVertically     ) {@@ -283,7 +272,6 @@ private fun LevelRowContent(                 levelId = row.levelIds[0],                 isCompleted = row.levelIds[0] in completed,                 isAvailable = row.levelIds[0] in available,-                bestNand = bestNands[row.levelIds[0]],                 size = nodeSize,                 onClick = onClickLevel             )@@ -293,7 +281,6 @@ private fun LevelRowContent(                     levelId = lvlId,                     isCompleted = lvlId in completed,                     isAvailable = lvlId in available,-                    bestNand = bestNands[lvlId],                     size = nodeSize,                     onClick = onClickLevel                 )@@ -308,7 +295,6 @@ private fun LevelNode(     levelId: String,     isCompleted: Boolean,     isAvailable: Boolean,-    bestNand: Int?,     size: Dp,     onClick: (String) -> Unit ) {@@ -316,7 +302,6 @@ private fun LevelNode(     val isLocked = !isCompleted && !isAvailable      val bg = when {-        isCompleted && (bestNand ?: 999) <= def.optimalNands -> Color(0xFF0F3D2E)         isCompleted -> Color(0xFF1E3A2F)         isAvailable -> Color(0xFF1B2E41)         else -> Color(0xFF242A33)@@ -350,13 +335,10 @@ private fun LevelNode(                     }                 )                 Spacer(Modifier.height(2.dp))-                if (isLocked) {-                    Text("LOCK", fontSize = 9.sp, fontWeight = FontWeight.Bold, color = Color(0xFF6B7280))-                } else if (isCompleted) {-                    val star = if ((bestNand ?: 999) <= def.optimalNands) "★★★" else if ((bestNand ?: 999) <= (def.optimalNands * 1.5).toInt()) "★★" else "★"-                    Text(star, fontSize = 10.sp, color = Color(0xFFFDE68A))-                } else {-                    Text("PLAY", fontSize = 9.sp, fontWeight = FontWeight.Bold, color = Color(0xFF7FD8BE))+                when {+                    isLocked -> Text("LOCK", fontSize = 9.sp, fontWeight = FontWeight.Bold, color = Color(0xFF6B7280))+                    isCompleted -> Text("DONE", fontSize = 9.sp, fontWeight = FontWeight.Bold, color = Color(0xFF22C55E))+                    else -> Text("PLAY", fontSize = 9.sp, fontWeight = FontWeight.Bold, color = Color(0xFF7FD8BE))                 }             }         }@@ -367,30 +349,14 @@ private fun LevelNode(             fontWeight = FontWeight.SemiBold,             color = if (isLocked) Color(0xFF6B7280) else MaterialTheme.colorScheme.onBackground         )-        when {-            isCompleted && bestNand != null -> {-                Text(-                    "${bestNand}N / ${def.optimalNands}N",-                    fontSize = 10.sp,-                    color = if (bestNand <= def.optimalNands) Color(0xFF22C55E) else Color(0xFF94A3B8)-                )-            }-            isLocked -> {-                val need = def.prereqs.joinToString(", ") { Levels.byId[it]?.displayName ?: it }-                Text(-                    "needs $need",-                    fontSize = 9.sp,-                    color = Color(0xFF6B7280),-                    modifier = Modifier.padding(horizontal = 4.dp)-                )-            }-            isAvailable -> {-                Text(-                    "${def.optimalNands}N optimal",-                    fontSize = 10.sp,-                    color = Color(0xFF7FD8BE).copy(alpha = 0.8f)-                )-            }+        if (isLocked) {+            val need = def.prereqs.joinToString(", ") { Levels.byId[it]?.displayName ?: it }+            Text(+                "needs $need",+                fontSize = 9.sp,+                color = Color(0xFF6B7280),+                modifier = Modifier.padding(horizontal = 4.dp)+            )         }     } }@@ -417,37 +383,20 @@ private fun RowToRowConnector(             else if (row.levelIds[0] == id) leftX else rightX         } -        // Draw each dependency edge fromRow -> toRow         for (toId in toRow.levelIds) {             val def = Levels.byId[toId] ?: continue             val toX = xFor(toId, toRow)-            var hasEdge = false             for (pr in def.prereqs) {                 if (pr in fromRow.levelIds) {-                    hasEdge = true                     val fromX = xFor(pr, fromRow)-                    val bothDone = pr in completed && (toId in completed || pr in completed)                     drawLine(-                        color = if (bothDone) Color(0xFF7FD8BE) else Color(0xFF374151),+                        color = if (pr in completed) Color(0xFF7FD8BE) else Color(0xFF374151),                         start = Offset(fromX, 0f),                         end = Offset(toX, size.height),                         strokeWidth = 6f                     )                 }             }-            // If this row's only prereq is in fromRow but we already handled, nothing extra-            if (!hasEdge && fromRow.levelIds.size == 1 && toRow.levelIds.size == 1) {-                // fallback for linear chain where prereq is immediate predecessor-                val fromId = fromRow.levelIds[0]-                if (def.prereqs.contains(fromId)) {-                    drawLine(-                        color = if (fromId in completed) Color(0xFF7FD8BE) else Color(0xFF374151),-                        start = Offset(cx, 0f),-                        end = Offset(cx, size.height),-                        strokeWidth = 6f-                    )-                }-            }         }     } }@@ -510,7 +459,7 @@ private fun BranchOutOfChapterConnector(     } } -// --- TruthTable + Inventory (kept minimal, game screen) ---+// --- TruthTable + Inventory ---  @Composable fun TruthTableView(@@ -569,8 +518,10 @@ fun TruthTableView(                 }             }         }-        if (failingRows.isNotEmpty()) Spacer(Modifier.height(6.dp))-        if (failingRows.isNotEmpty()) Text("${failingRows.size} failing", fontSize = 10.sp, color = Color(0xFFFF8A80))+        if (failingRows.isNotEmpty()) {+            Spacer(Modifier.height(6.dp))+            Text("${failingRows.size} failing", fontSize = 10.sp, color = Color(0xFFFF8A80))+        }     } } @@ -600,7 +551,7 @@ fun InventoryBar(                 ) {                     Column(horizontalAlignment = Alignment.CenterHorizontally) {                         Text(def.displayName, fontSize = 11.sp, fontWeight = FontWeight.Bold, color = Color.White)-                        Text("${def.nandCost}N ${def.inputs.size}→${def.outputs.size}", fontSize = 9.sp, color = Color.White.copy(alpha = 0.6f))+                        Text("${def.inputs.size}→${def.outputs.size}", fontSize = 9.sp, color = Color.White.copy(alpha = 0.6f))                     }                 }             }
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/util/Achievements.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/util/Achievements.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/util/Achievements.ktindex f41a304b34..e00ce85a43 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/util/Achievements.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/util/Achievements.kt@@ -8,19 +8,9 @@ import com.vayunmathur.library.util.AchievementsManager  class LogicAchievementsManager(context: Context, json: String, private val repo: LogicProgressRepository) : AchievementsManager(context, json) {     override fun checkExistingAchievements() {-        val stats = repo.getLevelStats()-        val completedIds = stats.keys+        val completedIds = repo.getLevelStats().keys         if (completedIds.isNotEmpty()) onAchievementUnlocked("first_gate")--        val optimalCount = completedIds.count { id ->-            val best = stats[id]?.bestScore ?: 9999-            val optimal = Levels.byId[id]?.optimalNands ?: 9999-            best <= optimal-        }--        onProgressUpdated("optimal_5", optimalCount)         onProgressUpdated("all_levels", completedIds.size)-         Levels.chapters.forEach { ch ->             val count = completedIds.count { Levels.byId[it]?.chapter == ch.id }             val key = when (ch.id) {
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/util/LogicViewModel.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/util/LogicViewModel.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/util/LogicViewModel.ktindex 02eb97f4be..70f0ee76b0 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/util/LogicViewModel.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/util/LogicViewModel.kt@@ -7,14 +7,9 @@ import androidx.lifecycle.viewModelScope import com.vayunmathur.games.logicgate.data.* import com.vayunmathur.library.util.DataStoreUtils import kotlinx.coroutines.Dispatchers-import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow-import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow-import kotlinx.coroutines.flow.SharingStarted-import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow-import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import kotlinx.coroutines.withContext@@ -22,8 +17,6 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import java.util.UUID-import kotlin.math.max-import kotlin.random.Random  // Serializable persistence of circuit per level @Serializable@@ -69,18 +62,12 @@ class LogicViewModel(application: Application) : AndroidViewModel(application) {     private val _completedIds = MutableStateFlow(repo.getCompletedLevelIds())     val completedIds: StateFlow<Set<String>> = _completedIds.asStateFlow() -    private val _bestNands = MutableStateFlow<Map<String, Int>>(repo.getLevelStats().mapValues { it.value.bestScore })-    val bestNands: StateFlow<Map<String, Int>> = _bestNands.asStateFlow()-     private val _unlockedChips = MutableStateFlow(repo.unlockedChipIds())     val unlockedChips: StateFlow<Set<String>> = _unlockedChips.asStateFlow()      private val _uiState = MutableStateFlow(UiState())     val uiState: StateFlow<UiState> = _uiState.asStateFlow() -    private val _nextLevelEvent = MutableSharedFlow<String>(extraBufferCapacity = 1)-    val nextLevelEvent: SharedFlow<String> = _nextLevelEvent.asSharedFlow()-     // persisted circuits cache     private var allCircuits: MutableMap<String, Circuit> = mutableMapOf() @@ -236,25 +223,17 @@ class LogicViewModel(application: Application) : AndroidViewModel(application) {     }      private fun onLevelWon(level: LevelDef, circuit: Circuit) {-        val cost = circuit.totalNandCost()         viewModelScope.launch {             withContext(Dispatchers.IO) {-                repo.updateBestScore(level.id, cost)+                repo.markCompleted(level.id)             }             _completedIds.value = repo.getCompletedLevelIds()-            _bestNands.value = repo.getLevelStats().mapValues { it.value.bestScore }             _unlockedChips.value = repo.unlockedChipIds()              repo.incCircuitsChecked()             achievementsManager.onAchievementUnlocked("first_gate")             val allCompleted = _completedIds.value-            val optimalCount = _completedIds.value.mapNotNull { id -> Levels.byId[id] }.count { ld ->-                val best = _bestNands.value[ld.id] ?: 9999-                best <= ld.optimalNands-            }-            achievementsManager.onProgressUpdated("optimal_5", optimalCount)             achievementsManager.onProgressUpdated("all_levels", repo.totalCompleted())-            // per chapter progress             Levels.chapters.forEach { ch ->                 val count = allCompleted.count { Levels.byId[it]?.chapter == ch.id }                 val key = when (ch.id) {@@ -266,21 +245,6 @@ class LogicViewModel(application: Application) : AndroidViewModel(application) {                 }                 achievementsManager.onProgressUpdated(key, count)             }--            // cache next level-            val chapterLevelIds = Levels.chapters.find { it.id == level.chapter }?.levelIds ?: emptyList()-            val idx = chapterLevelIds.indexOf(level.id)-            if (idx >= 0 && idx < chapterLevelIds.lastIndex) {-                val nextId = chapterLevelIds[idx + 1]-                _nextLevelEvent.tryEmit(nextId)-            } else {-                // next chapter first uncompleted-                val nextChapterIdx = Levels.chapters.indexOfFirst { it.id == level.chapter } + 1-                if (nextChapterIdx < Levels.chapters.size) {-                    val nextChap = Levels.chapters[nextChapterIdx]-                    _nextLevelEvent.tryEmit(nextChap.levelIds.first())-                }-            }         }     } 
games/logicgate/src/main/res/values/strings.xml
diff --git a/games/logicgate/src/main/res/values/strings.xml b/games/logicgate/src/main/res/values/strings.xmlindex 74a7783a8a..934d6b922a 100644--- a/games/logicgate/src/main/res/values/strings.xml+++ b/games/logicgate/src/main/res/values/strings.xml@@ -10,14 +10,10 @@     <string name="check">Check</string>     <string name="level_complete">Level Complete!</string>     <string name="level_failed">Check Failed</string>-    <string name="optimal">Optimal: %1$d Gates</string>-    <string name="your_gates">Your Gates: %1$d</string>-    <string name="nand_count">NANDs: %1$d</string>     <string name="truth_table">Truth Table</string>     <string name="info">Info</string>     <string name="inventory">Inventory</string>     <string name="chips">Chips</string>-    <string name="settings">Settings</string>     <string name="next">Next</string>     <string name="prev">Prev</string>     <string name="hint">Hint</string>