Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/apursley2012/treasure-hunt-game/llms.txt

Use this file to discover all available pages before exploring further.

Treasure Hunt is built from three focused ES modules that talk to each other through clean import boundaries. The maze engine knows nothing about the DOM; the agent brain knows nothing about buttons or timers; the UI layer owns rendering and input but delegates every rule to the modules below it. This separation means you can swap out the agent difficulty logic, rewrite the renderer, or generate mazes independently without touching the other two files.

Module Dependency Graph

The dependency tree is strictly layered — dependencies only flow downward, and there are no circular imports.
app.js
├── imports from treasure-maze.js
│     (TreasureMaze, createRandomMaze, findShortestPath,
│      LEFT, UP, RIGHT, DOWN, ACTION_NAMES, key)
└── imports from q-agent.js
      (CompetitiveAgent, DIFFICULTY_SETTINGS)

            └── imports from treasure-maze.js
                  (ACTION_DELTAS, ACTION_NAMES,
                   findShortestPath, key)

treasure-maze.js  ← no internal dependencies
treasure-maze.js sits at the base of the tree. q-agent.js builds on top of it to power BFS-based policy moves. app.js sits at the top, pulling from both and connecting everything to the browser DOM.

File Structure

assets/js/
├── treasure-maze.js   # Game engine & maze utilities
├── q-agent.js         # CompetitiveAgent & difficulty settings
└── app.js             # UI wiring, input handling, render loop

How Modules Are Loaded

The entry point is a single <script type="module"> tag in index.html. The browser resolves the import chain natively — no bundler, no build step, no transpilation required.
<script type="module" src="./assets/js/app.js"></script>
Because app.js is loaded as an ES module, all three files are fetched and evaluated in dependency order. The .nojekyll file in the repository root prevents GitHub Pages from interfering with the JavaScript module paths.

Public Exports

treasure-maze.js

ExportKindDescription
LEFTconstantAction integer 0
UPconstantAction integer 1
RIGHTconstantAction integer 2
DOWNconstantAction integer 3
ACTION_NAMESconstantMaps action int → string name
ACTION_DELTASconstantMaps action int → [dr, dc] delta
ORIGINAL_MAZEconstant8×8 fallback maze array
cloneMazefunctionDeep-copies a maze array
keyfunctionSerializes (row, col) to "row,col" string
sameCellfunctionCompares two [row, col] pairs
shufflefunctionFisher-Yates in-place shuffle
isInsidefunctionBounds check for a grid cell
openNeighborCountfunctionCounts passable neighbors of a cell
findShortestPathfunctionBFS path from start to target
createRandomMazefunctionProcedurally generates a solvable 8×8 maze
TreasureMazeclassFull game-environment class

q-agent.js

ExportKindDescription
DIFFICULTY_SETTINGSconstantThree-level config object (easy / medium / hard)
CompetitiveAgentclassBFS-driven AI opponent with hesitation and exploration

Module Pages

TreasureMaze Module

Full API reference for treasure-maze.js — the TreasureMaze class, createRandomMaze, findShortestPath, and all exported constants.

Q-Agent Module

Full API reference for q-agent.js — the CompetitiveAgent class and DIFFICULTY_SETTINGS that power the AI opponent.

App Module

How app.js wires the game engine and agent to the DOM — rendering, input handling, race timer, and HUD updates.

Build docs developers (and LLMs) love