Skip to content

SafalNarsingh/Sudoku-Solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Sudoku-Solver

A Django-based web application that provides a comprehensive Sudoku gaming experience, featuring gameplay, puzzle generation, solving capabilities, and user management.

This project aims to serve as a learning tool to help users understand and analyze different Sudoku-solving techniques.

SudokuSolver

Table of Contents

  1. Screenshots
  2. Features
  3. Usage/Examples
  4. Algorithms
  5. Dependencies
  6. Troubleshooting
  7. Supported Operatorions
  8. Contributors
  9. To-Do List

Screenshots

HomePage

Login

Level

Play

Solver

Solved

Profile

Features

๐Ÿ‘ค User Authentication & Profile Management

Users can sign up, log in, and log out securely. Each user has a profile that tracks their high scores and game progress. Users can change their username or delete their profile if they wish.

๐Ÿง  Difficulty Levels

Players can choose from multiple difficulty levels: Beginner Easy Medium Hard Extreme

The difficulty level affects the number of pre-filled numbers on the board.

๐Ÿง Sudoku Solver

Users can manually input a puzzle or generate a new one. The solver uses two different algorithms:

  • Backtracking Algorithm โ€“ A traditional recursive approach.

  • Heuristic Solver โ€“ A smarter, faster approach for solving Sudoku puzzles.

The solver compares both methods and provides time estimates.

๐ŸŽฎ Scoring & Performance Tracking

The app tracks the best scores for each user. Score calculation is based on:

  • Number of correct inputs: The player is awarded 40 points for every correct input on the puzzle

โŒ› Game Pausing & Resuming

Users can pause a game and resume it later without losing progress.

๐Ÿ“ฑ Mobile-Friendly UI

The web app is fully responsive and optimized for mobile devices. Touch-friendly controls make playing Sudoku easy on smartphones and tablets.

For instance, below you can view the example of the web application opened through an android phone:

Home_Mobile Level_Mobile Solver_Mobile Solved_Mobile

Usage/Examples

Playing Sudoku

  1. Log in to your account.
  2. Select a difficulty level from the homepage.
  3. The Sudoku game board will load based on the selected difficulty.
  4. Click or tap on an empty cell to enter a number.
  5. Click "Save Game" to store your progress.

Solving a Sudoku Puzzle

  • Go to the Solver page.
  • Manually enter a Sudoku puzzle.
  • Click "Solve", and the app will display the solution instantly along with time analysis of backtracking and heuristic algorithm.

Algorithms

Backtracking Algorithm

The Backtracking Algorithm is a recursive brute-force approach used to solve Sudoku puzzles by trying every possible number in each empty cell until a valid solution is found. It follows a Depth-First Search (DFS) strategy, starting from the first empty cell and attempting to place numbers from 1 to 9 while checking if the placement violates Sudoku rules. If an invalid placement is encountered, it backtracks by removing the last placed number and trying the next possible value. While this method guarantees a solution if one exists, it can be computationally expensive, especially for complex puzzles, as it relies on trial and error.

Heuristic Algorithm

The Heuristic Algorithm applies intelligent rule-based techniques to solve Sudoku more efficiently. Instead of brute-force searching, it uses constraint propagation, which eliminates impossible values early based on existing numbers in rows, columns, and boxes. Additionally, it implements Most Constrained Variable (MRV) Heuristic, prioritizing solving the cells with the fewest possible options first, and Least Constraining Value (LCV) Heuristic, selecting numbers that restrict future moves the least. Forward checking is also applied to dynamically track possibilities and prevent dead ends. This approach significantly improves solving speed compared to backtracking, making it ideal for difficult puzzles. However, while heuristic methods can solve most Sudoku puzzles quickly, they may require backtracking support for extremely challenging grids.

By combining these two approaches, the Sudoku solver in this project allows for performance comparison, measuring execution times for both methods to determine which one is more efficient for a given puzzle.

Dependencies

The project relies on the following dependencies:

  • Python
  • Django (for backend logic and user management)
  • Django authentication system (for login/logout features)
  • JSON Processing (for game state storage and retrieval)
  • HTML, CSS, JavaScript (for UI and interactivity)

Installation

To install and run the Sudoku Solver locally, follow these steps:

  1. Clone the repository on your local environment:
git clone https://github.com/SafalNarsingh/Sudoku-Solver
  1. Install dependencies using:
pip install -r requirements.txt
  1. Locate the the root directory and run the following command:
py manage.py runserver

Your server should be hosted locally within the given address. Open and enjoy.

Alternatively, You can run the web app using the following link: https://solversudoku.vercel.app/

Troubleshooting

โ— Login Issues

Ensure your username is correct and not already taken. Admin users cannot log in through the standard user portal.

โ— Game Not Saving

Make sure you are logged in before trying to save the game. Check the server logs for any errors.

โ— Sudoku Solver Not Working

Ensure the input board is correctly formatted. If no solution is found, verify that the puzzle is valid and solvable.

Supported Operations

  • User Management:

    • Login, Logout, Change Username, Delete Profile
  • Game Operations:

    • Start Game, Set Difficulty, Save/Load Game State, Solve Sudoku

To-Do List

  • Add hints option, providing upto around 3 hints, to the player if stuck during a level
  • Enhance play page for mobile rendering
  • Fix the save game state function (not working currently)
  • Add real-time multiplayer Sudoku.
  • Enhance score tracking with leaderboards.
  • Implement hints and undo functionality.
  • Add more algorithms for faster performance and better understanding of more sudoku solving algorithms.

Contributors

  • Apekshya Bhattarai
  • Salina Nakarmni
  • Pooja Pathak
  • Safal Narshing Shrestha
  • Dinisha Uprety

Last updated by Safal Narshing Shrestha on March 25, 2025, 17:38.
Copyright ยฉ 2025 Apekshya Bhattarai, Salina Nakarmni, Pooja Pathak, Safal Narshing Shrestha, Dinisha Uprety. All rights reserved.

About

Sudoku Solver highlighting two algorithms: Heuristic and Backracking with performance tracking and a simple UI

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5