An Android Sudoku app with a Compose-based home flow (HomeActivity + StatsActivity) that launches a Java + ViewBinding game screen (MainActivity). The game logic lives in an MVVM stack powered by SudokuViewModel, LiveData, and the SudokuBoard model, keeping the UI responsive while puzzles are generated on a background thread.
| New Game Dialog | Game Screen |
|---|---|
![]() |
![]() |
- Fresh puzzles per game: Generates solvable boards with a uniqueness check before play starts.
- Difficulty selector + resume: Start a new Easy, Medium, or Hard puzzle, or resume the latest in-progress game from the Compose home screen.
- Real-time validation: Highlights wrong entries immediately; per-move scoring and an error counter keep feedback clear.
- Timer and scoring: Time-based bonus plus difficulty bonuses, with softer difficulty-scaled penalties on mistakes; score never drops below zero.
- Undo support: Revert the latest user move while keeping score in sync; the error counter remains historical across the whole game.
- Local stats: Tracks wins, best time, and best score per difficulty without introducing accounts or cloud state.
- Config-change safe: Board state, selection, timer, and counters survive rotations and process death via the ViewModel bundle.
- App-close safe: The latest in-progress game is stored locally and can be resumed after the app is fully closed.
- UI flow:
HomeActivity(Compose home), optionalStatsActivity(local statistics), thenMainActivity(ViewBinding screen + overlayedTextViews for numbers). - Rendering:
SudokuGridViewdraws the grid;HighlightOverlayViewdraws selection/highlight layers. - State + logic:
SudokuViewModelowns UI state withLiveData, delegates rules and move history toSudokuBoard/SudokuCell. - Background work: Puzzle generation runs on a single-thread executor; a
Handlerdrives the in-app timer on the main thread. - Read the full breakdown in
docs/ARCHITECTURE.md.
app/src/main/java/com/example/sudoku
├── GameStatsStore.java # SharedPreferences-backed local wins / best time / best score tracking
├── HomeActivity.kt # Compose launcher with resume, difficulty selection, and stats entry point
├── MainActivity.java # ViewBinding UI, observers, dialogs, keypad, highlight overlay hookup
├── SavedGameStore.java # SharedPreferences-backed persistence for the latest in-progress game
├── StatsActivity.kt # Compose statistics screen with overview and per-difficulty breakdown
├── SudokuGridView.java # Custom view that draws the 9x9 board background and grid lines
├── HighlightOverlayView.java # Selection, row/column, and block highlighting overlay
├── SudokuBoard.java # Core logic: puzzle generation, validation, scoring, move history
├── SudokuCell.java # Parcelable cell model (value, fixed flag, correctness, notes)
└── viewmodel/SudokuViewModel.java # LiveData state holder, timer, undo, and move handling
Resources live in app/src/main/res; Compose theme definitions are under app/src/main/java/com/example/sudoku/ui/theme.
Prerequisites: Android Studio (Koala+ recommended), JDK 21, Android SDK 36; the app currently targets and requires Android 14 (minSdk 34).
- Clone the repo:
git clone https://github.com/<your-username>/Basic_Sudoku.git - Open the project in Android Studio and let Gradle sync.
- Pick a device/emulator running Android 14+ and press Run, or build from the CLI with
./gradlew assembleDebug. If your shell defaults to JDK 25, switchJAVA_HOMEback to JDK 21 first.
- Quick build:
./gradlew assembleDebug - Release build check:
./gradlew assembleRelease - Unit/UI tests: JVM regression tests live in
app/src/test, and instrumented tests live inapp/src/androidTest; run them with./gradlew testor./gradlew connectedAndroidTest. - Repository quality gate:
make verifyrunstest,assembleDebug, andlintDebugwith JDK 21 wired in automatically on macOS. - Code style: Kotlin uses the official style; Java follows standard Android conventions and lives alongside Compose code where needed.
- More tips live in
docs/DEVELOPMENT.md.
docs/ARCHITECTURE.md: deeper dive into the UI flow, threading, scoring, and puzzle generation.docs/DEVELOPMENT.md: environment setup, build commands, and guidelines for extending the app.
This project is licensed under the MIT License - see the LICENSE file for details.

