TheDocumentation 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.
CompetitiveAgent is not a fixed opponent — its behavior is governed by a DIFFICULTY_SETTINGS configuration object that controls four independent dials: how long it waits between moves, how long it waits before making its first move at all, how often it abandons the optimal path to explore, and how often it simply skips a turn. Tuning all four values together produces three distinct characters: a forgiving, slow-starting agent on Easy; a balanced but occasionally unpredictable opponent on Medium; and a relentless, near-perfect runner on Hard.
The DIFFICULTY_SETTINGS Object
What Each Property Controls
moveDelay (milliseconds) — the interval between consecutive agent moves after the race has started. A lower value means the agent ticks faster. Easy gives the player a comfortable 1.15 seconds between enemy steps; Hard fires every 470 ms.
startDelay (milliseconds) — how long the agent waits after the race begins before taking its very first move. This is the window where the player can build an early lead. Easy’s 1.6-second head start is generous; Hard’s 350 ms is barely a blink.
mistakeRate (0–1 probability) — the chance that the agent will call chooseExplorationMove() instead of choosePolicyMove() on any given turn. An exploration move picks a random unvisited valid neighbor rather than following the BFS shortest path. At 0.42, Easy will explore on nearly half of all turns; Hard never explores at all.
hesitateRate (0–1 probability) — the chance that the agent skips a move entirely for that tick, logging "hesitated" without advancing. Easy hesitates 20% of the time; Hard never hesitates.
Difficulty Comparison Table
| Property | Easy | Medium | Hard |
|---|---|---|---|
moveDelay (ms) | 1150 | 780 | 470 |
startDelay (ms) | 1600 | 900 | 350 |
mistakeRate | 0.42 | 0.18 | 0 |
hesitateRate | 0.20 | 0.08 | 0 |
How move() Uses These Values
Each agent tick calls move(), which applies the difficulty settings in a strict decision order:
Hesitation roll
Math.random() < hesitateRate — if true, the agent logs "hesitated" and returns without moving. The race timer continues ticking.Exploration vs. policy roll
Math.random() < mistakeRate — if true, chooseExplorationMove() picks a random unvisited valid neighbor. Otherwise choosePolicyMove() runs a fresh BFS from the agent’s current position and returns the next cell on the shortest path.Safety fallback
If the chosen move resolves to
null (e.g., exploration found no unvisited neighbors), the engine falls back to choosePolicyMove(), then to chooseExplorationMove(). If still null, the agent is blocked and logs "blocked".Mode Descriptions
| Mode | Description |
|---|---|
| Easy | The agent explores more, hesitates sometimes, and gives the player a head start. |
| Medium | The agent usually follows the learned route but still makes occasional exploration choices. |
| Hard | The agent exploits the optimal path aggressively and rarely gives the player breathing room. |