Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / games / solitaire / AGENTS.md
| 1 | # AGENTS.md — games/solitaire/ (':games:solitaire') |
| 2 | |
| 3 | > Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `games/solitaire/` + allowed shared modules. Do not root-scan. |
| 4 | |
| 5 | _Install: ./install games/solitaire (dev by default)._ |
| 6 | - Gradle: :games:solitaire / dir: games/solitaire/ |
| 7 | - Package roots present: ui, data, domain, platform |
| 8 | - Entry files: MainActivity.kt, Route.kt, Navigation.kt |
| 9 | - Deps: :sdk:games |
| 10 | - Metadata: metadata_data/games-solitaire.md (present) |
| 11 | - Rust: no / screenshotTest: yes |
| 12 | |
| 13 | ## Overview |
| 14 | **Purpose:** Multi-variant solitaire — Klondike, FreeCell, Spider (+ Pyramid ops present), on-device deals, undo, win overlay. 100% offline. |
| 15 | **Game shape:** Per-variant boards (`KlondikeBoard`, `FreeCellBoard`, `SpiderBoard`, `PyramidBoard`) over shared card/drag components → `platform/SolitaireViewModel` + per-variant `*Ops` → `data/` game state + stats; achievements → `:sdk:games` → hub. |
| 16 | **Entry points:** `Route` → `MainActivity.kt` → `Navigation.kt` → `ui/GameBoardScreen.kt` → `platform/SolitaireViewModel.kt` → `data/GameState.kt`. |
| 17 | **Gotchas:** Variant rules live in `platform/Solitaire*Ops` — shared board components must stay variant-agnostic. Every new deal comes from a table of solver-proven seeds, so **any rule change in the `*Ops` files means regenerating the tables** (see "Solvable deals"). |
| 18 | |
| 19 | ## Key files |
| 20 | ### Root — entry + navigation |
| 21 | - com/vayunmathur/games/solitaire/MainActivity.kt |
| 22 | - com/vayunmathur/games/solitaire/Navigation.kt |
| 23 | - com/vayunmathur/games/solitaire/Route.kt |
| 24 | ### data/ — state + stats + settings |
| 25 | - com/vayunmathur/games/solitaire/data/GameState.kt |
| 26 | - com/vayunmathur/games/solitaire/data/CardModels.kt |
| 27 | - com/vayunmathur/games/solitaire/data/CardColorScheme.kt |
| 28 | - com/vayunmathur/games/solitaire/data/SolitaireStatsRepository.kt |
| 29 | - com/vayunmathur/games/solitaire/data/SolitaireSettingsRepository.kt |
| 30 | ### domain/ — pure Kotlin: deals, solvers, seed tables (no Android) |
| 31 | - com/vayunmathur/games/solitaire/domain/SolitaireDeals.kt (seed → starting board; the only deal code) |
| 32 | - com/vayunmathur/games/solitaire/domain/SolvableDeals.kt (table keys, `solvable_deals.bin` format, pick / daily mapping) |
| 33 | - com/vayunmathur/games/solitaire/domain/DealProofs.kt (what "proven" means: solver + pass-limit ladder) |
| 34 | - com/vayunmathur/games/solitaire/domain/SolverSearch.kt (DFS / beam / portfolio search engine) |
| 35 | - com/vayunmathur/games/solitaire/domain/KlondikeSolver.kt, FreeCellSolver.kt, SpiderSolver.kt, PyramidSolver.kt |
| 36 | ### platform/ — ViewModel + per-variant rules |
| 37 | - com/vayunmathur/games/solitaire/platform/SolitaireViewModel.kt |
| 38 | - com/vayunmathur/games/solitaire/platform/SolitaireUiContract.kt |
| 39 | - com/vayunmathur/games/solitaire/platform/SolitaireKlondikeOps.kt |
| 40 | - com/vayunmathur/games/solitaire/platform/SolitaireFreeCellOps.kt |
| 41 | - com/vayunmathur/games/solitaire/platform/SolitaireSpiderOps.kt |
| 42 | - com/vayunmathur/games/solitaire/platform/SolitairePyramidOps.kt |
| 43 | - com/vayunmathur/games/solitaire/platform/SolitaireDealSource.kt (new game = random table seed; `restartDeal()`) |
| 44 | - com/vayunmathur/games/solitaire/platform/SolitaireDragOps.kt |
| 45 | - com/vayunmathur/games/solitaire/platform/SolitaireFlight.kt — in-flight moves (visual only; game state updates first) |
| 46 | - com/vayunmathur/games/solitaire/platform/SolitaireAchievementsManager.kt |
| 47 | - com/vayunmathur/games/solitaire/platform/AppBackupAgent.kt |
| 48 | ### ui/ — boards + shared card/drag components |
| 49 | - com/vayunmathur/games/solitaire/ui/GameBoardScreen.kt |
| 50 | - com/vayunmathur/games/solitaire/ui/GameScreen.kt |
| 51 | - com/vayunmathur/games/solitaire/ui/HomeScreen.kt |
| 52 | - com/vayunmathur/games/solitaire/ui/KlondikeBoard.kt |
| 53 | - com/vayunmathur/games/solitaire/ui/FreeCellBoard.kt |
| 54 | - com/vayunmathur/games/solitaire/ui/SpiderBoard.kt |
| 55 | - com/vayunmathur/games/solitaire/ui/PyramidBoard.kt |
| 56 | - com/vayunmathur/games/solitaire/ui/TableauColumn.kt |
| 57 | - com/vayunmathur/games/solitaire/ui/FreeCellTableauColumn.kt |
| 58 | - com/vayunmathur/games/solitaire/ui/FoundationSlot.kt |
| 59 | - com/vayunmathur/games/solitaire/ui/FreeCellSlot.kt |
| 60 | - com/vayunmathur/games/solitaire/ui/CardView.kt |
| 61 | - com/vayunmathur/games/solitaire/ui/DraggableCard.kt — pick-up/tap source; hidden while it is carried or in flight |
| 62 | - com/vayunmathur/games/solitaire/ui/DropTarget.kt |
| 63 | - com/vayunmathur/games/solitaire/ui/CardMotionLayer.kt — top-level layer drawing the drag + every flight (outside the scroll clip) |
| 64 | - com/vayunmathur/games/solitaire/ui/PileLayout.kt — card slot offsets shared by piles (draw) and flights (land) |
| 65 | - com/vayunmathur/games/solitaire/ui/GameActionBar.kt |
| 66 | - com/vayunmathur/games/solitaire/ui/GameModeDisplayName.kt |
| 67 | - com/vayunmathur/games/solitaire/ui/WinOverlay.kt |
| 68 | - com/vayunmathur/games/solitaire/ui/SettingsScreen.kt |
| 69 | - com/vayunmathur/games/solitaire/ui/dialogs/GameConfigDialog.kt |
| 70 | |
| 71 | ## Verify (this module only) |
| 72 | ``` |
| 73 | ./gradlew :games:solitaire:compileDevKotlin |
| 74 | ./gradlew :games:solitaire:lint |
| 75 | ./gradlew :games:solitaire:checkMetadata |
| 76 | ``` |
| 77 | |
| 78 | ## Solvable deals |
| 79 | Every new game deals a seed from `src/main/assets/solvable_deals.bin`: one sorted |
| 80 | table per mode × option (8 Klondike draw/pass configs, Spider 1/2/4 suits, |
| 81 | FreeCell, Pyramid relaxed/single-pass), keyed by the stats variant |
| 82 | (`KLONDIKE__DRAW_THREE_HARD`, ...). Each seed is proven to a full win offline |
| 83 | by `domain/DealProofs` (the mode's solver, climbing the pass-limit ladder: |
| 84 | a win with fewer passes is a win with more). Seeds deal through |
| 85 | `createShuffledDeck(seed)` / `createSpiderDeck(suits, seed)`, |
| 86 | so a seed deals the same board everywhere; the state keeps it (`seed`), and |
| 87 | `restartDeal()` replays it. |
| 88 | |
| 89 | `SolverReplayTest` / `SolvableDealTablesTest` replay solver lines from table |
| 90 | seeds through the real ViewModel ops. If they fail after a rules change (or a |
| 91 | solver change), regenerate: |
| 92 | |
| 93 | ``` |
| 94 | ./gradlew :games:solitaire:testDevUnitTest \ |
| 95 | --tests 'com.vayunmathur.games.solitaire.domain.SolvableSeedTableGenerator' \ |
| 96 | -PsolitaireSeedGen=$PWD/analysis/soldeal -PsolitaireSeedGenThreads=64 |
| 97 | cp analysis/soldeal/solvable_deals.bin games/solitaire/src/main/assets/ |
| 98 | ``` |
| 99 | Optional: `-PsolitaireSeedGenTarget=10000` (seeds per config), |
| 100 | `-PsolitaireSeedGenGroups=klondike-draw1,klondike-draw3,pyramid,freecell,spider1,spider2,spider4` |
| 101 | (subset; merge by hand), `-PsolitaireSeedGenHeap=40g` (test JVM heap). |
| 102 | `analysis/soldeal/solvable_deals_report.txt` has per-config solvable rates |
| 103 | (Klondike draw-1 86% unlimited .. 19% one pass, draw-3 79% .. 2.6%, |
| 104 | FreeCell 99.9%, Pyramid 83% relaxed / 12.8% single pass, Spider 84/83/71% for |
| 105 | 1/2/4 suits; proven within budget). |
| 106 | Output is deterministic for a given solver and budget (any thread count). |
| 107 | It is CPU-heavy (about 25 min on 64 cores at 10 000 per config; the build |
| 108 | hook turns off coverage and -ea for it, which otherwise make it ~10x slower): |
| 109 | on the shared build box run it in the toolchain container under |
| 110 | the heavy-build lock, e.g. |
| 111 | `MEM_CAP=60g GEXCL="" ~/release-opt2/gbuild.sh soldeal-gen ~/code/Modern-Apps <branch> ":games:solitaire:testDevUnitTest --tests com.vayunmathur.games.solitaire.domain.SolvableSeedTableGenerator -PsolitaireSeedGen=/work/out -PsolitaireSeedGenThreads=64 -PsolitaireSeedGenHeap=44g"` |
| 112 | (output in `~/release-opt2/runs/soldeal-gen/work/out/`). |