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.

Every game of Treasure Hunt is a head-to-head race on a freshly generated 8×8 maze. You start at the top-left corner, the treasure X sits at the bottom-right corner, and an intelligent JavaScript agent races you to it. The board is full of blocked cells that neither you nor the agent can cross, so finding the right path — and taking it faster than the agent — is the whole challenge. Invalid moves cost you reward points without moving you forward, and the game tracks a minimum reward threshold that signals a loss state when your score drops too far.
Start on Easy difficulty to get a feel for the maze layout and controls before moving up. On Easy, the agent has a 1600 ms start delay and a 42 % chance of making an exploratory detour on every move, giving you meaningful time to learn the path before the AI becomes a real threat.

Objective

Reach the treasure cell at position [7, 7] — the bottom-right corner of the 8×8 grid — before the CompetitiveAgent does. Both you and the agent start at cell [0, 0], the top-left corner. Open cells can be entered freely; blocked cells (0 in the maze matrix) cannot be entered by either side.

Controls

Keyboard

You can control your player with either the arrow keys or WASD at any time during an active race.
KeyDirection
ArrowLeft or aMove left
ArrowUp or wMove up
ArrowRight or dMove right
ArrowDown or sMove down
Keyboard input is captured by a keydown listener on the document. Recognized keys call event.preventDefault() so the page does not scroll while you play.

On-Screen Direction Buttons

Four directional buttons are rendered in the Player Controls panel on the right side of the game layout. Each button carries a data-action attribute that maps to a movement direction.
Button labeldata-action valueDirection
upMove up
downMove down
leftMove left
rightMove right
Click or tap any button to move one cell in that direction. The same movement rules apply as with keyboard input — attempting to move into a blocked cell incurs a reward penalty but does not change your position.

HUD Elements

The heads-up display around the maze board updates after every player move and every agent move. Each element surfaces a different piece of live race data.
HUD ElementDOM IDWhat it shows
Difficulty#difficulty-labelThe label for the currently active difficulty setting (Easy, Medium, or Hard)
Reward#reward-labelYour current cumulative reward, formatted to two decimal places (e.g. −1.23)
Player Steps#player-steps-labelThe number of valid moves you have made this race (invalid moves are not counted)
Agent Steps#agent-steps-labelThe total number of cells the agent has moved to this race — hesitations and blocked turns are not counted
Shortest Route#path-length-labelThe BFS-optimal path length for the current maze, in moves (recalculated each render)
Race Lead#player-lead-labelComparative step count: Even, Player +N, or Agent +N
Agent move#agent-move-labelDescription of the agent’s last action, e.g. exploited right, explored down, or hesitated
Game Log#training-logA scrolling list of the last 9 game events, newest first
The Game Log shows entries such as player move results with per-step and cumulative reward, agent release messages, difficulty change notices, maze load confirmations, and race outcome messages.

Reward System

The TreasureMaze class tracks your cumulative reward in totalReward and applies the following values on every move:
Move resultReward
Reach the treasure cell [7, 7]+1.0
Valid move to an unvisited cell−0.04
Valid move to a previously visited cell−0.25
Invalid move (into a blocked cell or out of bounds)−0.75
Blocked — no valid adjacent cells existminReward − 1 (≈ −33 on the standard board)
An invalid move applies the −0.75 penalty to totalReward but does not change your position on the board. Your Player Steps counter is also not incremented for invalid moves. The minimum reward threshold is calculated as minReward = −0.5 × rows × cols. On the standard 8×8 board this equals −32. TreasureMaze.gameStatus() returns "lose" when totalReward drops below this threshold, and the Reward counter in the HUD will reflect that negative total.

Win and Lose Conditions

ConditionStatus pill textTrigger
You reach [7, 7]You Found the Xenv.gameStatus() returns "win"
Agent reaches [7, 7]Agent Found the Xagent.hasReachedTreasure() returns true
When either race-ending condition is met, the agent timer is cleared, the Start Race button is re-enabled, and the final result is written to the Game Log with both players’ step counts.
TreasureMaze.gameStatus() also returns "lose" when totalReward drops below minReward (−32 on the standard board), which is reflected in the Reward HUD counter. However, app.js does not call endRace() for this state — the race continues and you can keep moving even if your reward reaches deeply negative values.

Game Controls

Three buttons in the Race Setup panel manage the game state.
ButtonIDBehaviour
Start Race#start-raceActivates the race, starts the agent timer after startDelay ms, and disables itself until the race ends or is reset
New Maze#new-mazeGenerates a fresh randomized 8×8 maze, resets both players to [0, 0], and logs the new shortest route length
Reset#reset-raceResets both players and reward on the current maze without generating a new board

Difficulty Selection

The Agent Difficulty dropdown (#difficulty-select) controls how the CompetitiveAgent behaves. Changing the difficulty mid-session calls resetRace() automatically so the new settings take effect from a clean state.
DifficultyMove delayStart delayMistake rateHesitate rateAgent behaviour
Easy1150 ms1600 ms42 %20 %Explores frequently, hesitates sometimes, gives the player a head start
Medium780 ms900 ms18 %8 %Usually follows the optimal route but makes occasional exploration choices
Hard470 ms350 ms0 %0 %Exploits the BFS-optimal path aggressively with no hesitation or detours
On Hard, the agent starts after only 350 ms and follows the exact shortest path on every move with no mistakes. On a maze with a short optimal route, the agent can reach the treasure before you have time to make more than a few moves. Always learn the board layout on Easy or Medium first.

Build docs developers (and LLMs) love