File size: 8,726 Bytes
f69e256
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# 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.