Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# GitHub Copilot Instructions

This project is a Flask-based Sudoku application.

When generating code:

- Follow PEP 8 coding standards.
- Preserve the existing project structure.
- Keep functions modular and reusable.
- Avoid breaking existing functionality.
- Add concise comments only when they improve readability.
- Prefer readable and maintainable code over clever code.
- Ensure compatibility with Flask and the existing Sudoku logic.
- Suggest Pythonic solutions whenever possible.
- Keep HTML, CSS, and JavaScript clean and organized.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ Thumbs.db

# Ignore Python virtual environment
.venv/
__pycache__/
__pycache__/
*.py[cod]
Binary file added screenshots/01_difficulty_levels.png.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/01_home_page.png.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/02_hint_feature.png..png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/03_immediate_validation.png.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/04_timer_feature.png.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 95 additions & 23 deletions starter/app.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,111 @@
from flask import Flask, render_template, jsonify, request
import sudoku_logic
import random

app = Flask(__name__)

# Keep a simple in-memory store for current puzzle and solution
CURRENT = {
'puzzle': None,
'solution': None
"puzzle": None,
"solution": None
}

@app.route('/')

@app.route("/")
def index():
return render_template('index.html')
return render_template("index.html")


@app.route('/new')
@app.route("/new")
def new_game():
clues = int(request.args.get('clues', 35))
puzzle, solution = sudoku_logic.generate_puzzle(clues)
CURRENT['puzzle'] = puzzle
CURRENT['solution'] = solution
return jsonify({'puzzle': puzzle})
difficulty = request.args.get("difficulty", "easy").lower()

if difficulty not in sudoku_logic.DIFFICULTY_LEVELS:
difficulty = "easy"

puzzle, solution = sudoku_logic.generate_puzzle(difficulty)

CURRENT["puzzle"] = puzzle
CURRENT["solution"] = solution

return jsonify({
"difficulty": difficulty,
"puzzle": puzzle
})


@app.route("/hint")
def get_hint():
puzzle = CURRENT["puzzle"]
solution = CURRENT["solution"]

if puzzle is None or solution is None:
return jsonify({"error": "No active game"}), 400

empty = []

for r in range(sudoku_logic.SIZE):
for c in range(sudoku_logic.SIZE):
if puzzle[r][c] == 0:
empty.append((r, c))

if not empty:
return jsonify({"message": "Puzzle already completed"})

row, col = random.choice(empty)

value = solution[row][col]

puzzle[row][col] = value

return jsonify({
"row": row,
"col": col,
"value": value
})

@app.route('/check', methods=['POST'])

# ---------- NEW ROUTE ----------
@app.route("/validate", methods=["POST"])
def validate_cell():

if CURRENT["solution"] is None:
return jsonify({"error": "No active game"}), 400

data = request.get_json()

row = int(data["row"])
col = int(data["col"])
value = int(data["value"])

correct = CURRENT["solution"][row][col] == value

return jsonify({
"correct": correct
})


@app.route("/check", methods=["POST"])
def check_solution():
data = request.json
board = data.get('board')
solution = CURRENT.get('solution')
if solution is None:
return jsonify({'error': 'No game in progress'}), 400

if CURRENT["solution"] is None:
return jsonify({"error": "No game in progress"}), 400

data = request.get_json()

board = data.get("board", [])

incorrect = []
for i in range(sudoku_logic.SIZE):
for j in range(sudoku_logic.SIZE):
if board[i][j] != solution[i][j]:
incorrect.append([i, j])
return jsonify({'incorrect': incorrect})

if __name__ == '__main__':
for row in range(sudoku_logic.SIZE):
for col in range(sudoku_logic.SIZE):
if board[row][col] != CURRENT["solution"][row][col]:
incorrect.append([row, col])

return jsonify({
"correct": len(incorrect) == 0,
"incorrect": incorrect
})


if __name__ == "__main__":
app.run(debug=True)
Loading