Bobby Liu.
← All projects

Project case study

Automatic Sudoku Solver

A Python script that solves web-based Sudoku puzzles and enters the answers automatically.

Project brief

Built to expand my Python knowledge by improving an existing solver with safer, faster interaction controls.

Core improvements

  • Selects and activates the correct Sudoku browser window before running.
  • Adds an Escape-key emergency stop for safer automation.
  • Reduces PyAutoGUI's action delay from 0.1 seconds to 0.01 seconds.

Window targeting

The original code only worked when the Sudoku window was already in the foreground. I added a window-selection step so the script looks for a window with “Sudoku” in its title and activates it before starting.

This also gives the script a basic check that the expected site is open before it begins clicking and typing.

windowselect = pyautogui.getWindowsWithTitle("Sudoku")[1]
windowselect.activate()

Safe interruption

There was no way to stop the original script after it started. I added an Escape-key check so the process can be stopped when something goes wrong.

Because the check runs between automated actions, another letter or number pressed while the script is typing may prevent the quit key from being registered immediately.

import keyboard

if keyboard.is_pressed('esc'):
    quit()

Faster input

PyAutoGUI pauses for 0.1 seconds after each action by default. Setting the pause to 0.01 seconds makes the step that fills the web Sudoku grid about ten times faster.

pyautogui.PAUSE = 0.01

Project demos

Click an image to expand
Original code
Improved version with less delay
Emergency stop using the Escape key