Skip to content

Mikescher/HexSolver

Repository files navigation

HexSolver (an Hexcells solver)

An automatic solver for Hexcells, Hexcells Plus and Hexcells Infinite.
The idea is to automatically parse the game state, find the next (valid) step and execute it.
(Rinse and Repeat until everything is solved)

Execution Animation

Usage

  • Start HexCells Infinite (should also work with the other Hexcell games)
  • I recommend window-mode with 1440x900 resolution (for the OCR to work best)
  • Load a level
  • Start HexSolver
  • Press Recapture
  • If you want to completely solve the level press Execute (All)
  • Don't manually move your mouse until finished (press ESC to abort)
  • If you just want to see the next step press Solve (Can take around 5-10 seconds)

Troubleshooting

  • HexSolver needs an minimum amount of orange cells to recognize the layout
  • HexSolver only works when all cells are in an uniform grid (click Calculate to see the grid)
  • Only click Recapture when the fading in effect is finished - otherwise no cells can be recognized
  • If you find the (uncommon) case of two row-hint in one cell, HexSolver will fail (sorry)
  • If HexSolver fails to solve a configuration or the OCR module fails, please send me an full-resolution screenshot of the game.

Features

  • Automatic finding of game window and capturing of its graphical output
  • Dynamically finding the hexagon layout
  • With an custom crafted OCR module recognition of the cell values
  • 3-Step solving of the current configuration (tested on the original levels and many of the generated ones)
  • Finding the optimal execution path by solving the corresponding TSP
  • Automatic execution by programmatically moving the mouse
  • Saving the current (captured) state as an *.hexcells file

HexSolvers internal steps

Step 1 - Capture

Shot1 (Captured Screenshot)

Step 2 - Find Hexagons

Shot2 (Binarizing Image to find hexagons)

Shot3 (Putting Hexagon Grid over screenshot)

Step 3 - Recognize Types

Shot4 (Find the layout and the cell types)

Step 4 - Image Processing

Shot5 (Find the cells with numbers and extract them)

Step 5 - Text Recognition

Shot6 (OCR the numbers with my own HexCells-OCR engine)

Shot7 (the OCR distance of the different numbers)

Step 6 - Puzzle Solving

Shot8 (Show all the current active hints)

Shot9 (Find solutions for the current configuration)

Shot10 (Find an optimal execution path by TSP algorithm)

Step 7 - Solution Executing