Skip to content

Latest commit

ย 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿงฉ Sudoku Solver Game

A fully-featured Java Sudoku game with intelligent puzzle generation, backtracking solver, hint system, and a rich performance analytics dashboard.

Java Swing AWT License Course Platform


๐Ÿ” Overview

This project is a complete Sudoku Solver Game built in Java with a Swing-based GUI. It was developed as a course project for Software Construction & Development, demonstrating key software engineering principles including:

  • Separation of Concerns โ€” Board logic, solver, generator, and GUI are each in their own class
  • Object-Oriented Design โ€” Clean encapsulation and responsibility delegation
  • Algorithm Design โ€” Backtracking-based puzzle solving and generation
  • User Experience โ€” Real-time feedback, error highlighting, hints, and a post-game analytics dashboard

โœจ Features

๐ŸŽฎ Gameplay

  • Generate puzzles at three difficulty levels: Easy, Medium, and Hard
  • Manual puzzle entry support
  • Real-time error highlighting for invalid number placements
  • Row, column, and 3ร—3 box cell highlighting on focus
  • Hint system that reveals the correct number for any empty cell
  • Auto-solve button that completes the puzzle instantly
  • Board validation to check if a completed puzzle is correct

โฑ๏ธ Statistics Tracking

  • Live game timer tracking time elapsed
  • Hints used counter
  • Mistakes made counter

๐Ÿ† Performance Dashboard (Post-Game)

  • Key Performance Indicators: accuracy, efficiency, correct moves
  • Donut chart visualization of performance breakdown
  • Achievements system with unlockable badges
  • Game history comparison across multiple sessions (Overview, Detailed, Charts, Statistics tabs)
  • Report generation โ€” export a .txt performance report
  • CSV data export for game history
  • Practice mode with targeted improvement tips
  • Share results dialog

๐Ÿ“ Project Structure

sudoku-solver-game/
โ”‚
โ”œโ”€โ”€ SudokuGUI.java              # Main application window and game controller
โ”œโ”€โ”€ SudokuBoard.java            # Board state management and game logic
โ”œโ”€โ”€ SudokuSolver.java           # Backtracking solver and solution counter
โ”œโ”€โ”€ PuzzleGenerator.java        # Random puzzle generation by difficulty
โ”œโ”€โ”€ finalWindow.java            # Post-game performance analytics dashboard
โ”‚
โ”œโ”€โ”€ README.md                   # Project documentation
โ”œโ”€โ”€ .gitignore                  # Ignore compiled class files
โ”œโ”€โ”€ LICENSE                     # MIT License
โ”‚
โ””โ”€โ”€ screenshots/
    โ”œโ”€โ”€ 01_game_board.png
    โ”œโ”€โ”€ 02_easy_board.png
    โ”œโ”€โ”€ 03_medium_board.png
    โ”œโ”€โ”€ 04_hard_board.png
    โ”œโ”€โ”€ 05_hint.png
    โ”œโ”€โ”€ 06_mistake.png
    โ”œโ”€โ”€ 07_solve_automatically.png
    โ”œโ”€โ”€ 08_performance_dashboard.png
    โ”œโ”€โ”€ 09_performance_visualization.png
    โ”œโ”€โ”€ 10_additional_features.png
    โ”œโ”€โ”€ 11_generate_report.png
    โ”œโ”€โ”€ 12_compare_games_overview.png
    โ”œโ”€โ”€ 13_compare_games_detailed.png
    โ”œโ”€โ”€ 14_compare_games_stats.png
    โ”œโ”€โ”€ 15_compare_games_charts.png
    โ”œโ”€โ”€ 16_achievements.png
    โ”œโ”€โ”€ 17_practice_mode.png
    โ””โ”€โ”€ 18_share_results.png

๐Ÿ—๏ธ Architecture

The project follows a clean layered architecture:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚            SudokuGUI.java            โ”‚  โ† Presentation Layer (Swing UI)
โ”‚    (Game window, controls, events)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚          SudokuBoard.java            โ”‚  โ† Domain Layer (State & Rules)
โ”‚  (Board state, user moves, hints)    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                 โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ SudokuSolver    โ”‚  โ”‚ PuzzleGenerator โ”‚  โ† Logic Layer
โ”‚ (Backtracking)  โ”‚  โ”‚ (Generation)    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                   โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚          finalWindow.java            โ”‚  โ† Analytics Layer
โ”‚   (Dashboard, charts, history)       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Getting Started

Prerequisites

  • Java JDK 8 or higher
  • Any Java IDE (IntelliJ IDEA, Eclipse, VS Code with Java extension) or command line

Running from Command Line

# Clone the repository
git clone https://github.com/YOUR_USERNAME/Sudoku-Solver-Game.git
cd Sudoku-Solver-Game

# Compile all Java files
javac *.java

# Run the application
java SudokuGUI

Running from an IDE

  1. Open your IDE and import the project folder
  2. Make sure all 5 .java files are in the same package/directory
  3. Run SudokuGUI.java as the main class

๐ŸŽฏ How to Play

  1. Generate a Puzzle โ€” Click Easy, Medium, or Hard to generate a new puzzle
  2. Fill Cells โ€” Click any empty cell and type a number (1โ€“9)
  3. Use Hints โ€” Click "Get Hint" to auto-fill the next empty cell with the correct number
  4. Check Your Work โ€” Click "Check Board" when all cells are filled
  5. Win! โ€” If correct, the performance dashboard opens with your stats

Keyboard & Mouse

  • Click a cell to focus and highlight its row, column, and box
  • Type 1โ€“9 to enter a number; Backspace or Delete to clear
  • Puzzle clue cells (pre-filled, shaded blue) cannot be edited

Color Guide

Color Meaning
๐Ÿ”ต Light Blue Original puzzle clue (read-only)
โฌœ White Empty or valid user-entered cell
๐ŸŸข Light Green Hint-filled cell
๐Ÿ”ด Light Red Invalid/conflicting number
๐ŸŸก Yellow Highlighted row/column/box

๐Ÿ“– Class Descriptions

SudokuBoard.java

Manages the complete board state. Maintains three parallel grids:

  • board[][] โ€” current numbers (clues + user entries + hints)
  • originalPuzzle[][] โ€” immutable clue values
  • userFilled[][] / hintCells[][] โ€” tracks cell origin

Key methods: putNumber(), setNumber(), putHint(), canPlace(), checkBoard(), isValidBoard(), clearUserCell(), clearAllUserCells()


SudokuSolver.java

Implements a recursive backtracking algorithm to solve any valid Sudoku puzzle.

Key methods:

  • solve(board) โ€” fills in a solution in-place; returns true if solvable
  • canPlace(board, row, col, num) โ€” validates Sudoku row/column/box constraints
  • getHint(board, row, col) โ€” returns the correct value for a specific cell
  • countSolutionsLimited(board, limit) โ€” checks if puzzle has a unique solution (used during generation)

PuzzleGenerator.java

Creates random, valid Sudoku puzzles with guaranteed unique solutions.

Algorithm:

  1. Fill the three diagonal 3ร—3 boxes with random shuffled numbers (they are independent)
  2. Use backtracking to fill remaining cells
  3. Remove cells one by one (random order), verifying uniqueness after each removal
  4. Stop when the target cell count for the chosen difficulty is reached
Difficulty Cells Removed Empty Cells
๐ŸŸข Easy 25 25
๐ŸŸก Medium 45 45
๐Ÿ”ด Hard 57 57

SudokuGUI.java

The main application window built with Java Swing. Responsibilities:

  • Renders the 9ร—9 grid as JTextField cells
  • Handles all user input events (key presses, mouse clicks, focus changes)
  • Manages the game timer, hint counter, and mistake counter
  • Coordinates between SudokuBoard, SudokuSolver, and PuzzleGenerator
  • Launches finalWindow upon successful puzzle completion

finalWindow.java

A rich post-game Performance Analytics Dashboard displayed after solving a puzzle.

Panels & Features:

  • KPI Cards โ€” time, accuracy, efficiency, hints, mistakes, correct moves
  • Donut Chart โ€” multi-ring visualization of performance metrics
  • Game History Comparison โ€” tabbed view with Overview, Detailed Table, Progress Charts, and Advanced Statistics
  • Achievements โ€” badge system (Perfect Game, Hintless Hero, Accuracy Master, etc.)
  • Generate Report โ€” saves a formatted .txt performance report
  • Export CSV โ€” exports all game history data
  • Practice Mode โ€” gives targeted tips based on your weak areas
  • Share Results โ€” generates a shareable summary text

๐Ÿ› ๏ธ Technologies Used

Technology Purpose
Java SE 8+ Core programming language
Java Swing GUI components โ€” JFrame, JPanel, JTextField, JButton
Java AWT Custom charts โ€” Graphics2D, Arc2D, BasicStroke
Java Timer Live game timer implementation
Java I/O Report generation and CSV export
Java Collections Game history and list management
Git Source control
GitHub Code hosting

๐Ÿ”ง Key Algorithms

Backtracking Solver

solve(board):
  find first empty cell
  for num in 1..9:
    if canPlace(board, row, col, num):
      place num
      if solve(board): return true
      undo placement (backtrack)
  return false  โ† trigger backtrack in caller

Unique Solution Verification

During puzzle generation, countSolutionsLimited(puzzle, 1) is called after each cell removal. If more than 1 solution exists, the removal is undone โ€” guaranteeing every generated puzzle has exactly one solution.


๐Ÿ‘จโ€๐Ÿ’ป Author

Khansa Bint-e-Zia

๐Ÿ“„ License

This project is licensed under the MIT License โ€” see the LICENSE file for details.


Built with โ˜• Java and a love for puzzles.

โญ If you found this project helpful, please consider giving it a star!

About

A Java Sudoku game with puzzle generation, backtracking solver, hint system, and post-game performance analytics dashboard. Built with Java Swing.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages