Sudoku Final
Sudoku Final
PROJECT
WORK
Submitted by
SUDHARSHAN S
722824244056
BATCH
2024 - 2028
Under the Guidance of
Ms.M.VAISHALI M.E.,
BONAFIDE CERTIFICATE
Certified that this Report titled “SUDOKU GAME” is the bonafide work of
supervision.
SIGNATURE SIGNATURE
R.SURESH M.Sc,M.Phil,Ph.D,SET Ms.M.VAISHALI M.E.,
PROFESSOR SUPERVISOR
HEAD OF THE DEPARTMENT ASSISTANT PROFESSOR
SCIENCE AND HUMANITIES
COMPUTER SCIENCE AND BUSINESS
Sri Eshwar College of Engineering,
SYSTEMS
Coimbatore – 641 202.
Sri Eshwar College of Engineering,
Coimbatore – 641 202.
…………………..
ABSTRACT
LIST OF FIGURES
1 INTRODUCTION
1.1 OBJECTIVES
3 PROJECT DESCRIPTION
4 IMPLEMENTATION
The primary objective of this project is to develop an interactive Sudoku Solver using Python,
Tkinter, and PyGame that provides an engaging way to generate, solve, and interact with
Sudoku puzzles. The system ensures an intuitive interface, enabling users to solve puzzles
efficiently while offering features such as difficulty selection, timer tracking, and hint-based
solving assistance.
For players, the application provides a dynamic puzzle generator with adjustable difficulty
settings (Easy, Medium, Hard). It features a solver algorithm to assist users when stuck and a
validation mechanism to check for correct inputs.
This system aims to enhance logical reasoning, improve puzzle-solving strategies, and provide an
accessible digital tool for Sudoku enthusiasts, ultimately contributing to an enjoyable and
intuitive gaming experience.
The Sudoku Solver is designed to provide an interactive and efficient way to generate, solve,
and validate Sudoku puzzles using Python, Tkinter, and PyGame. It offers an intuitive interface for users
to engage with Sudoku puzzles, supporting various difficulty levels and dynamic puzzle generation. The
system ensures seamless grid interactions, optimized solving algorithms, and an engaging user experience.
The application integrates grid-based rendering and real-time validation to assist players in solving
puzzles effectively. The solver algorithm employs backtracking techniques, ensuring correct and
efficient solutions while maintaining a smooth visual flow within the graphical interface.
Data is processed dynamically, allowing users to generate random puzzles, validate entries, and
interact with hints or timer-based challenges. The platform is built with modular flexibility,
supporting future enhancements like multiplayer modes, AI-driven puzzle hints, mobile app
adaptation, graphical analytics, and performance tracking. This system enhances logical reasoning,
encourages strategic problem-solving, and delivers a polished and interactive Sudoku experience.
CHAPTER 2
SYSTEM ANALYSIS AND SPECIFICATION
Sudoku enthusiasts, especially beginners, often struggle with solving puzzles efficiently due to
the complexity of logical reasoning required. Many find it challenging to determine the correct
placement of numbers, recognize patterns, and apply solving techniques without assistance.
Traditional Sudoku-solving methods rely heavily on manual trial-and-error, which can lead to
frustration and errors, especially in difficult puzzle variations.
Additionally, there is no unified interactive platform where users can generate random Sudoku
puzzles, receive hints, track solving time, and validate their solutions in real-time. The absence of
intuitive tools for step-by-step solving guidance, adjustable difficulty levels, and automated
puzzle validation further limits the learning experience. These gaps affect user engagement,
problem-solving confidence, and long-term interest in logical puzzle-solving.
The Sudoku Solver project aims to address these challenges by offering an interactive,
algorithm-driven platform using Python, Tkinter, and PyGame. It enables users to input
numbers, receive hints, and validate their solutions instantly, fostering an engaging and structured
approach to Sudoku. The system also supports timer-based tracking and dynamic puzzle
generation, ensuring a seamless learning and gaming experience.
Develop an intuitive GUI using PyGame, allowing users to select difficulty levels and
play Sudoku seamlessly.
Support grid-based interactions, enabling users to fill cells and validate their inputs in real
time.
Provide a hint system to assist users by suggesting possible moves when requested.
Offer three difficulty levels: Easy (4×4), Intermediate (9×9), Hard (16×16),
dynamically adjusting puzzle complexity.
Implement random puzzle generation ensuring a unique Sudoku experience each time.
Validate Sudoku rules—each row, column, and sub-grid must contain unique numbers
without repetition.
Ensure smooth integration of game state persistence, reducing the need for replays.
Enhance difficulty level customization, allowing users to tweak settings like hint
frequency, error highlighting, etc.
Integrate AI-driven Sudoku solving, enabling an automatic solution feature for learning
and assistance.
Prepare for mobile-responsiveness or porting to a web-based platform for broader
accessibility.
1. HARDWARE REQUIREMENTS:
2. SOFTWARE REQUIREMENTS:
• Python
• PyGame
• Tkinter
o NON-FUNCTIONAL REQUIREMENT
1. PERFORMANCE
The system should provide fast responses to user interactions, such as inputting
numbers, validating solutions, generating new puzzles, and using the solver
feature. It must ensure smooth performance even with complex puzzles and
multiple simultaneous actions.
2. SCALABILITY
The system must ensure consistent performance with high uptime and minimal
service disruption. Backup mechanisms and proper error handling should be in
place to prevent data loss, ensuring the Sudoku Game remains available and
functional at all times.
4. SECURITY
The system must ensure consistent performance with high uptime and minimal
service disruption. Backup mechanisms and proper error handling should be in
place to prevent data loss, ensuring the Sudoku Game remains available and
functional at all times.
5. USABILITY
The system must ensure consistent performance with high uptime and minimal
service disruption. Backup mechanisms and proper error handling should be in
place to prevent data loss, ensuring the Sudoku Game remains available and
functional at all times.
CHAPTER 3
PROJECT DESCRIPTION
3.1.1 USER
The User module allows players to register, log in, and manage their profiles.
Users can track their game progress, set difficulty preferences, and view their previously
completed puzzles. This ensures a personalized gaming experience and enhances user
engagement.
The Timer & Scoring module monitors the time taken to complete puzzles and
rewards players based on their performance. It introduces competitive elements by tracking
high scores, fastest completion times, and accuracy statistics.
The PyGame module is responsible for rendering graphics, handling user input,
and creating a visually appealing interface for the Sudoku game. It ensures smooth
interactions and transitions between menu selection, puzzle-solving, and game features.
The Settings Menu module allows users to customize their game experience.
Players can adjust sound settings, toggle hints, set difficulty preferences, change themes for
visual customization, and manage timer options. This module ensures flexibility and
accessibility in gameplay.
CHAPTER 4
IMPLEMENTATION
main.py
import PyGame
from settings_menu import SettingsMenu
from sudoku_game import SudokuGame
def main():
PyGame.init()
running = True
while running:
screen = PyGame.display.set_mode((600, 400))
PyGame.display.set_caption("Sudoku Settings")
settings = SettingsMenu(screen)
difficulty = settings.run()
if difficulty is None:
running = False
break
if difficulty == 4 or difficulty == 9:
grid_pixels = 600
else:
grid_pixels = 800
PyGame.quit()
if __name__ == "__main__":
main()
sudoku_board.py
import random
import math
class SudokuBoard:
def __init__(self, size):
self.size = size
self.base = int(math.sqrt(size))
self.solution = self._generate_solution()
self.givens = [
[(self.puzzle[r][c] != 0) for c in range(self.size)]
for r in range(self.size)
]
def _get_clues_count(self):
if self.size == 4:
return 6
elif self.size == 9:
return 25
elif self.size == 16:
return 60
else:
return self.size * self.size // 4
def _generate_solution(self):
N = self.size
base = self.base
r_base = range(base)
rows = [
g * base + r
for g in random.sample(r_base, base)
for r in random.sample(r_base, base)
]
cols = [
g * base + c
for g in random.sample(r_base, base)
for c in random.sample(r_base, base)
]
nums = random.sample(range(1, N + 1), N)
board = [
[nums[pattern(r, c)] for c in cols]
for r in rows
]
return board
for i in range(to_remove):
r, c = positions[i]
self.puzzle[r][c] = 0
sudoku_game.py
import PyGame
from sudoku_board import SudokuBoard
high_score = 0
class SudokuGame:
def __init__(self, screen, size):
self.screen = screen
self.size = size
self.board = SudokuBoard(size)
if size == 4:
self.point_value = 2
elif size == 9:
self.point_value = 3
else:
self.point_value = 5
self.score = 0
if size == 4:
self.total_time = 120 # 2 minutes
elif size == 9:
self.total_time = 300 # 5 minutes
else:
self.total_time = 600 # 10 minutes
self.start_ticks = PyGame.time.get_ticks()
self.game_active = True
self.grid_pixels = self.screen.get_width()
self.window_width = self.screen.get_width()
self.window_height = self.screen.get_height()
self.cell_size = self.grid_pixels // self.size
self.grid_origin_x = (self.window_width - self.cell_size * self.size) // 2
self.grid_origin_y = 40 # leave room at top for the timer
self.selected = None
self.input_buffer = ""
def run(self):
global high_score
clock = PyGame.time.Clock()
running = True
while running:
for ev in PyGame.event.get():
if ev.type == PyGame.QUIT:
return
if ev.type == PyGame.KEYDOWN:
if ev.key == PyGame.K_ESCAPE:
return
try:
val = int(self.input_buffer)
except ValueError:
val = None
if self.board.is_valid_move(r, c, val):
if not self.locked[r][c]:
self.locked[r][c] = True
if self.game_active:
self.score += self.point_value
else:
if self.game_active:
self.score -= 1
self.input_buffer = ""
else:
if self.input_buffer != "" and (val is None or val > self.size):
self.input_buffer = ""
self.board.current[r][c] = 0
if self.game_active:
self.input_buffer = ""
self.selected = None
for rr in range(self.size):
for cc in range(self.size):
cell_x = self.grid_origin_x + cc * self.cell_size
cell_y = self.grid_origin_y + rr * self.cell_size
cell_rect = PyGame.Rect(cell_x, cell_y, self.cell_size, self.cell_size)
if cell_rect.collidepoint(mx, my):
if not self.locked[rr][cc]:
self.selected = (rr, cc)
break
if self.selected:
break
if self.exit_rect.collidepoint(mx, my):
return
if self.action_rect.collidepoint(mx, my) and self.game_active:
self.game_active = False
running = False
if self.game_active:
elapsed = (PyGame.time.get_ticks() - self.start_ticks) / 1000
remaining = max(int(self.total_time - elapsed), 0)
if remaining == 0:
self.game_active = False
running = False
else:
elapsed = (PyGame.time.get_ticks() - self.start_ticks) / 1000
remaining = max(int(self.total_time - elapsed), 0)
for rr in range(self.size):
for cc in range(self.size):
x = self.grid_origin_x + cc * self.cell_size
y = self.grid_origin_y + rr * self.cell_size
rect = PyGame.Rect(x, y, self.cell_size, self.cell_size)
if self.board.givens[rr][cc]:
bg = (200, 200, 200) # Grey for givens
elif self.locked[rr][cc]:
bg = (180, 255, 180) # Light green for correct/locked
else:
bg = (255, 255, 255) # White for empty
val = self.board.current[rr][cc]
if val != 0:
text = str(val)
txt_surf = self.font.render(text, True, (0, 0, 0))
txt_rect = txt_surf.get_rect(center=rect.center)
self.screen.blit(txt_surf, txt_rect)
minutes = remaining // 60
seconds = remaining % 60
time_text = f"Time: {minutes:02d}:{seconds:02d}"
time_surf = self.score_font.render(time_text, True, (0, 0, 0))
time_rect = time_surf.get_rect(
center=(
self.window_width // 2,
self.grid_origin_y + self.size * self.cell_size + 20
)
)
self.screen.blit(time_surf, time_rect)
PyGame.display.flip()
clock.tick(30)
self._show_final_screen(high_score)
clock = PyGame.time.Clock()
done = False
PyGame.display.flip()
clock.tick(30)
settings_menu.py
import PyGame
class SettingsMenu:
def __init__(self, screen):
self.screen = screen
self.selected = 4
w, h = self.screen.get_size()
def run(self):
clock = PyGame.time.Clock()
while True:
for ev in PyGame.event.get():
if ev.type == PyGame.QUIT:
return None
if ev.type == PyGame.KEYDOWN:
if ev.key == PyGame.K_ESCAPE:
return None
if self.easy_rect.collidepoint(mx, my):
self.selected = 4
elif self.med_rect.collidepoint(mx, my):
self.selected = 9
elif self.hard_rect.collidepoint(mx, my):
self.selected = 16
self.screen.fill(self.bg_color)
PyGame.display.flip()
clock.tick(30)
CHAPTER 5
RESULTS AND DISCUSSIONS
LANDING PAGE: Handles a clean interface with difficulty level selection (Easy,
Intermediate, Hard) and options to start or exit the Sudoku game.
The Sudoku Game is an intelligent platform designed to assist users in solving and
generating Sudoku puzzles efficiently. It provides features such as puzzle validation, AI-
powered solving algorithms, difficulty level selection, and secure user authentication,
allowing users to interact with the system based on their preferences and expertise. Users
can input puzzles, receive instant solutions with step-by-step breakdowns, and track their
solving history, fostering an engaging and educational experience. The integrated
challenge module encourages users to practice and improve their puzzle-solving skills,
while all data, including user profiles and completed puzzles, is securely stored in a
database for easy retrieval and analysis.
Looking ahead, the system can be enhanced with features like personalized solving tips
based on user patterns, adaptive difficulty adjustments, and integration with interactive
tutorials to guide beginners through logical techniques. Developing a mobile application
would increase accessibility, allowing users to solve and track puzzles on the go.
Additionally, incorporating AI-driven puzzle generation could create unique and
progressively challenging Sudoku grids tailored to individual users. These future
enhancements would significantly improve user engagement, scalability, and
effectiveness of the system, making it an indispensable tool for Sudoku enthusiasts and
learners alike.
REFERENCES:
https://www.geeksforgeeks.org/sudoku-problem-in-python/
2. PyGame Tutorial
https://www.tutorialspoint.com/PyGame/index.htm/
3. Tkinter Tutorial
https://www.geeksforgeeks.org/python-tkinter-tutorial/
https://www.geeksforgeeks.org/sudoku-backtracking-7/
https://www.w3schools.com/python/python_math.asp/