View: Multi-Page Single Page

Simple Hamiltonian

Generate verified cover-all path puzzles — Square & Hex.

Complete documentation, on one page.

v1.1 · by Living Failure

Overview

Simple Hamiltonian generates grid puzzles whose solution is a single unbroken line that visits every walkable tile exactly once — a "cover-all" / Hamiltonian path. It verifies them too: a sound solver reports whether a board has exactly one solution. Square & hex grids, Free or Fixed mode with ordered checkpoints, deterministic from a seed, stored as ScriptableObjects.

Requirements

  • Unity 6000.3+.
  • Core (generation / solving / rules / data / ScriptableObjects): no package dependencies, any render pipeline.
  • Demo: Input System + TextMeshPro; Built-in pipeline (URP/HDRP users convert the demo materials).
Assembly definitionsCore, Demo, and Editor are separate asmdefs, so the generator never pulls in the demo's packages.

Quick start

No code

Open Window ▸ Living Failure ▸ Simple Hamiltonian ▸ Puzzle Generator, pick Shape / Mode / size, click Auto (sets Coverage for your grid so it verifies), click Generate, then save with Save ▾.

Code

using SimpleHamiltonian;

var settings = new GenerationSettings {
    Width = 6, Height = 6, Shape = GridShape.Hex,
    Mode = PuzzleMode.Fixed, CheckpointCount = 2, RequireUnique = true,
};
PuzzleData puzzle = HamiltonianGenerator.GenerateVerified(settings);
List<PuzzleData> pack = HamiltonianGenerator.GenerateBatch(settings, 10);

Playing

bool ok  = HamiltonianRules.IsLegalStep(puzzle, currentPath, nextCell);
bool won = HamiltonianRules.IsSolved(puzzle, currentPath);

Generating puzzles

The Generate window: Auto (sets Coverage / Checkpoints / Min-turns so the grid verifies — start here), Batch count, Clear on generate, Presets / Reset, Only unique, Target difficulty (roll to a 1–5 star rating; Parallelize roll in Advanced spreads tries across CPU cores), and Save ▾ (current puzzle / whole set / pack unique only, with an optional Save name). Generation runs off the UI thread — inline progress + Cancel, never a freeze.

Free = start/end anywhere (usually many solutions). Fixed = set start/end + ordered checkpoints; this is where uniqueness is achievable. Square is 4-neighbor, Hex is pointy-top 6-neighbor (odd-r); both are topology-aware and the solver is proven sound on each. Generation is deterministic per seed — share the seed instead of the data.

Coverage is the uniqueness dial. A near-full grid has too many paths to prove one unique (you'll get "Not verified"); obstacles constrain it until exactly one remains — the holes are what make a board uniquely solvable. Rule of thumb: it verifies while width × height × coverage² stays under ~55 (Square) / ~32 (Hex), so hex needs far lower coverage. Auto sets a value that works for your grid, and the window warns inline once you're past the cliff.

Saved assets get inspector tools: a solution-count badge (with a 1–5 difficulty rating) plus Verify (re-check; Verify All reports any changed verdicts) and Re-roll (regenerate a slot until it verifies, then replace it; Re-roll Unverified fixes a whole pack at once). Both are undoable.

For runtime generation behind a loading screen:

var levels = await HamiltonianGenerator.GenerateBatchAsync(settings, 20,
    new System.Progress<int>(done => bar.value = done / 20f));

Settings

FieldRangeMeaning
Width / Height3–20Grid size.
ShapeSquare / Hex4- or 6-neighbor.
ModeFree / FixedEndpoint constraint.
Coverage0.25–1.0Fraction walkable; rest are obstacles. The uniqueness dial — lower = easier to verify unique. Use Auto.
CheckpointCount0…Ordered checkpoints (Fixed).
MinTurns0…Twistier solutions.
RequireUniqueboolVerify a single-solution board (Fixed).
TargetDifficulty0–5Roll unique boards to this star rating; 0 = any.
SeedstringEmpty = random; reproduces the board.
UniquenessNodeBudget1k–5MSolver node cap.
UniquenessSeconds0.2–20Solver time budget.

API reference

HamiltonianGenerator

MemberReturns
Generate(settings)PuzzleData (unverified)
GenerateVerified(settings)PuzzleData (uniqueness-checked)
GenerateVerifiedAsync(settings)Task<PuzzleData>
GenerateBatch(settings, count)List<PuzzleData>
GenerateBatchAsync(settings, count, progress)Task<List<PuzzleData>>

HamiltonianRules

MemberNotes
IsLegalStep(puzzle, path, next)Walkable, no revisit, adjacent, Fixed start rule.
IsSolved(puzzle, path)Covers all; Fixed checks start/end + checkpoint order.
CheckpointsInOrder(puzzle, path)Numbered order so far.
Validate(puzzle)Well-formed data → ValidationResult.

Solver

Solver.Verify(puzzle)SolutionVerdict (Count, Verified, IsUnique, Found, Nodes). Bounded by node + time budgets. Difficulty.Stars(verdict) rates it 1–5 (0 if not verified-unique).

Types

PuzzleData (size, shape, walkable/obstacles, start/end, checkpoints, solution, verdict, Difficulty) · GenerationSettings · Cell · GridShape · PuzzleMode · SolutionCount · HamiltonianPuzzle / HamiltonianPuzzlePack (both IPuzzleProvider).

The demo

The demo is a ready-to-play scene in Assets/SimpleHamiltonian/Scenes/ — open it and press Play. The landing menu lets you pick Random (generated, with a progress bar) or Puzzle Packs, plus Square / Hex.

Controls: Square WASD/arrows · Hex QE AD ZC · drag to draw · R reset · H hide legend · F auto-solve.

Skin it by dropping your tile/player prefabs on LevelRenderer3D / PlayerController3D (empty slots fall back to primitives). One-click builders to rebuild it live in Editor/Tools but are kept off the menu — uncomment a builder's [MenuItem] line to bring it back under … ▸ Demo Setup.

Troubleshooting

  • "Not verified" — solver hit its budget; the board still plays. Enable Require Unique and hit Auto (it lowers Coverage — the real uniqueness dial), use a smaller grid, or raise the budget.
  • Magenta materials — Built-in shader in a URP/HDRP project; run Unity's material converter on the demo materials.
  • No sound — add an AudioListener to the camera.
  • Compile errors — install Input System + TextMeshPro; import TMP essentials.
  • Mouse won't move the player — hold and drag over adjacent cells.
  • Hex keys — Q E A D Z C, not WASD (no straight-up neighbor on hex).
  • F does nothing — it auto-solves; ignored on a solved level; only R cancels mid-playback.

About

Simple Hamiltonian v1.1, by Living Failure. Verify don't hope; no bloat; pipeline-agnostic; readable example code. Support: livingfailuregames@gmail.com. Distributed under the Unity Asset Store EULA.