Number Puzzle Game (Sudoku)
Number Puzzle Game (Sudoku)
SECTION: E
ROLL NO: 79
ENROLLMENT NUMBER: 12024052011068
SUBJECT NAME: Introduction to AI and Data Science
using Python
SUBJECT CODE: IVC183
NUMBER PUZZLE GAME(e.g. SUDOKU)
Generate Puzzle:
Fills diagonal grids and solves the board to create a complete Sudoku.
Solve Puzzle
Display Board
Source Code
import random
class Sudoku:
def _init_(self):
# Check row
if num in self.board[row]:
return False
# Check column
if self.board[i][j] == num:
return False
return True
def solve(self):
if self.board[row][col] == 0:
self.board[row][col] = num
if self.solve():
return True
self.board[row][col] = 0
return False
return True
self.fill_diagonal_grid(i, i)
# Solve the board to ensure it's valid
self.solve()
self.remove_numbers(difficulty)
for i in range(3):
for j in range(3):
for _ in range(remove_count):
while self.board[row][col] == 0:
self.board[row][col] = 0
def display(self):
game.generate_puzzle(difficulty="medium")
print("Sudoku Puzzle:")
game.display()
print("\nSolved Sudoku:")
game.solve()
game.display()
OUTPUT