| # Maze Dataset Generation |
|
|
| ## Goal |
|
|
| Generate an image-based puzzle dataset where: |
|
|
| - A rectangular grid maze is rendered as a black-and-white image. |
| - The maze has exactly two connected openings on its border — the correct entry and exit. |
| - Additional decoy openings lead into isolated dead-end pockets with no path to any other opening. |
| - The task can only be solved by visually tracing the interior path from one opening to another. |
|
|
| This dataset is intended to test visual maze navigation under clutter, decoy paths, and structural ambiguity. |
|
|
| ## Core Puzzle Definition |
|
|
| Each sample contains: |
|
|
| - A grid maze of `rows × cols` cells. |
| - Between `min_openings` and `max_openings` labeled border openings. |
| - Exactly one connected pair among all openings — the two that share an interior path. |
| - All other openings lead to isolated dead-end regions that cannot reach any exit. |
|
|
| Recommended defaults: |
|
|
| - `rows, cols ∈ [8, 20]` |
| - `num_openings ∈ [3, 6]` |
|
|
| The main question for a sample can be one of: |
|
|
| - Identify which two labeled openings are connected. |
| - Given one opening label, identify the opening it connects to. |
| - Verify whether a proposed pair of labels is connected. |
|
|
| ## Visual Structure |
|
|
| ### Grid Layout |
|
|
| - Each cell is rendered as a square of fixed `cell_size` pixels. |
| - Walls are drawn as filled black rectangles of `wall_width` pixels. |
| - A uniform `margin` is applied outside the grid boundary. |
| - Additional label padding is added outside the margin to accommodate opening labels. |
|
|
| ### Border Openings |
|
|
| - Each opening is a gap in the outer border wall at a specific column (top/bottom) or row (left/right). |
| - Openings are placed at least one cell from each corner (`corner_buffer = 1`). |
| - Each opening is labeled with a consecutive uppercase letter (A, B, C, …). |
| - Labels are rendered just outside the maze boundary, adjacent to their opening. |
|
|
| ### Interior Walls |
|
|
| Walls are drawn using two arrays: |
|
|
| - `vertical_walls[r][c]`: wall on the right side of cell `(r, c)`. |
| - `horizontal_walls[r][c]`: wall on the bottom of cell `(r, c)`. |
|
|
| The outer border is always fully walled except at openings. |
|
|
| ## Difficulty Requirements |
|
|
| The puzzle should be hard for both humans and models. |
|
|
| ### Required difficulty factors |
|
|
| - Long interior path between the connected pair. |
| - Many dead-end branches throughout the maze. |
| - Decoy openings that visually resemble the true entry/exit. |
| - No color coding or directional hints. |
| - Decoy regions large enough to require exploration before rejection. |
|
|
| ### Important anti-shortcut rule |
|
|
| The connected pair must not be predictable by position: |
|
|
| - The two connected openings must not always be the first two labels. |
| - Opening label order is shuffled after placement. |
| - The connected pair should not always appear on opposite sides. |
|
|
| Allowed variation: |
|
|
| - Random grid size within the configured range. |
| - Variable path length depending on grid size. |
|
|
| Not allowed: |
|
|
| - Any visual cue distinguishing the connected openings from decoys. |
| - Labels ordered to reveal the answer by position or alphabetical proximity. |
|
|
| ## Path Design |
|
|
| ### Connected Pair |
|
|
| The connected pair is selected to maximize interior path length: |
|
|
| - A minimum path length of `(rows × cols) / 3` cells is enforced. |
| - All border cell pairs are evaluated; those meeting the threshold are candidates. |
| - One candidate is chosen at random. |
|
|
| ### Decoy Openings |
|
|
| Each decoy opening leads to an isolated subtree: |
|
|
| - The subtree is grown from the decoy cell using open maze passages. |
| - It is then walled off from the rest of the maze. |
| - Minimum decoy size: 3 cells. Maximum: `max(12, (rows × cols × 3) / 5)` cells. |
| - Decoy subtrees must not overlap the main path cells or each other. |
|
|
| ### Validation |
|
|
| After placement, each sample is verified: |
|
|
| - The connected pair must be reachable from each other. |
| - Each decoy opening must not reach either connected opening. |
| - Samples failing validation have their decoys dropped rather than discarded entirely. |
|
|
| ## Appearance Constraints |
|
|
| ### Background |
|
|
| - Plain white background. |
| - No textures, gradients, or background elements. |
|
|
| ### Wall styling |
|
|
| - All walls use the same solid black fill. |
| - Wall thickness is uniform across the entire image (`wall_width` pixels). |
| - No anti-aliasing or blur applied to walls. |
|
|
| ### Text styling |
|
|
| - Opening labels use a readable sans-serif font (Arial or DejaVu Sans fallback). |
| - Font size is fixed at 16pt. |
| - Labels are rendered in black on the white margin area. |
| - No decorative fonts, colors, or size variation. |
|
|
| ## Data Generation Procedure |
|
|
| ### 1. Generate maze |
|
|
| - Use recursive DFS (backtracking) starting from cell `(0, 0)`. |
| - All cells are visited; the result is a perfect maze (no loops, fully connected). |
|
|
| ### 2. Select connected pair |
|
|
| - Enumerate all border cell pairs. |
| - Compute BFS path length between each pair. |
| - Collect pairs with path length ≥ `(rows × cols) / 3`. |
| - Randomly select one qualifying pair as the main connected pair. |
|
|
| ### 3. Place decoy openings |
|
|
| - Enumerate remaining border cells not on the main path. |
| - For each candidate, grow an isolated subtree using existing maze passages. |
| - Wall off the subtree from the rest of the maze. |
| - Accept the decoy if the subtree meets the minimum size and does not overlap forbidden cells. |
| - Continue until the desired number of openings is reached or candidates are exhausted. |
|
|
| ### 4. Shuffle label order |
|
|
| - Concatenate the connected pair and all accepted decoy openings. |
| - Randomly permute the full list to assign labels A, B, C, … in shuffled order. |
| - Record the indices of the connected pair in the shuffled order. |
|
|
| ### 5. Render image |
|
|
| - Draw outer border walls with gaps at each opening position. |
| - Draw interior vertical and horizontal walls cell by cell. |
| - Draw opening labels in the margin outside each gap. |
| - Export final image as PNG. |
|
|
| ## Annotation Format |
|
|
| Each image has machine-readable metadata. |
|
|
| JSON fields per record: |
|
|
| ```json |
| { |
| "image": "images/maze_00000.png", |
| "rows": 12, |
| "cols": 15, |
| "cell_size": 32, |
| "wall_width": 5, |
| "margin": 8, |
| "num_openings": 4, |
| "openings": [ |
| {"label": "A", "side": "top", "index": 3, "is_connected": false}, |
| {"label": "B", "side": "left", "index": 5, "is_connected": true}, |
| {"label": "C", "side": "bottom", "index": 9, "is_connected": true}, |
| {"label": "D", "side": "right", "index": 2, "is_connected": false} |
| ], |
| "connected_pair": ["B", "C"], |
| "answer": "B-C", |
| "path_length": 67, |
| "difficulty": "hard" |
| } |
| ``` |
|
|
| Optional extra annotations: |
|
|
| - Full wall arrays (`vertical_walls`, `horizontal_walls`) |
| - Opening pixel coordinates |
| - BFS path cell list |
| - Decoy subtree cell lists |
|
|
| ## Difficulty Levels |
|
|
| ### Easy |
|
|
| - Small grid (≤ 10 × 10) |
| - Fewer openings (≤ 3) |
| - Shorter paths |
| - Fewer dead-end branches |
|
|
| ### Medium |
|
|
| - Moderate grid size (≤ 16 × 16) |
| - Up to 5 openings |
| - Moderate path complexity |
|
|
| ### Hard |
|
|
| - Larger grid (> 16 × 16) |
| - Many openings (> 5) |
| - Long winding paths |
| - Dense dead-end regions near decoy openings |
|
|
| Difficulty classification: |
|
|
| - Easy: `rows × cols ≤ 100` and `num_openings ≤ 3` |
| - Medium: `rows × cols ≤ 256` and `num_openings ≤ 5` |
| - Hard: otherwise |
|
|
| ## Quality Checks |
|
|
| Reject or degrade samples if: |
|
|
| - The connected pair is not reachable from each other. |
| - A decoy opening can reach a connected opening. |
| - The path length is below the minimum threshold. |
| - Any label overlaps significantly with a wall or another label. |
| - The grid is too small to accommodate the requested number of openings. |
|
|
| Recommended automated checks: |
|
|
| - BFS reachability between connected pair |
| - BFS isolation check for each decoy |
| - Minimum path length enforcement |
| - Minimum endpoint separation (corner buffer) |
| - Label render bounds within image dimensions |
|
|
| ## Recommended Dataset Variants |
|
|
| Create separate controlled variants: |
|
|
| - Small grids (8–12) vs large grids (14–20) |
| - Few openings (3–4) vs many openings (5–6) |
| - Connected pair always on opposite sides vs any sides |
| - Fixed grid size vs variable grid size |
| - Thick walls vs thin walls |
|
|
| ## Output Organization |
|
|
| Suggested structure: |
|
|
| ```text |
| maze/ |
| creation.py |
| creation.md |
| annotations.jsonl |
| images/ |
| maze_00000.png |
| maze_00001.png |
| ... |
| ``` |
|
|
| ## Implementation Notes |
|
|
| - Use recursive DFS for maze generation; set a random seed for reproducibility. |
| - Store both rendered images and structured annotations. |
| - Apply rejection logic only for hard validity failures (disconnected pair, reachable decoy). |
| - Use Pillow (`PIL`) for rendering; no external rendering dependencies required. |
|
|
| ## Summary |
|
|
| This dataset should produce maze navigation puzzles where the only reliable strategy is to trace the interior path through the maze grid from one labeled opening to another, ignoring dead-end pockets connected to decoy openings. |
|
|