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.
TreasureMaze class is the authoritative rulebook for every game of Treasure Hunt. It manages an 8×8 matrix of open and blocked cells, tracks the player’s position, marks which cells have been visited, and enforces which moves are legal on every turn. Every player action passes through updateState() before a reward is issued, ensuring the maze’s physical rules are never bypassed regardless of how a move is requested — from a keyboard press, an on-screen button, or the agent’s own logic.
Grid Structure
The maze is stored as an 8×8 two-dimensional array where each cell holds one of two values:| Value | Meaning |
|---|---|
1 | Open cell — the player or agent may stand here |
0 | Blocked cell / wall — movement into this cell is forbidden |
[0, 0] (top-left) and the treasure target is always at [7, 7] (bottom-right). Both cells are guaranteed to be open before a game begins.
The ORIGINAL_MAZE Constant
When randomized generation fails after 70 attempts, the engine falls back to this hand-crafted layout:
Action Constants and Deltas
Four named integer constants represent every possible direction of movement. Each constant maps to a[rowDelta, colDelta] pair in ACTION_DELTAS that describes how the player’s grid position changes when that action is applied:
LEFT = 0 moves one column to the left, UP = 1 moves one row up, RIGHT = 2 moves one column to the right, and DOWN = 3 moves one row down.
Cell Validation: canStandOn(row, col)
Before any move is accepted, the engine checks whether the destination cell is a legal standing position. A cell passes this check only when both conditions are true:
- The coordinates are within the 8×8 boundary (
isInsidereturnstrue). - The base maze value at that position equals
1(open, not a wall).
Computing Valid Actions: validActions()
validActions() returns an array of all action integers that would move the player onto a legal cell from the current position. It iterates over the four action constants, applies each delta, and keeps only those where canStandOn returns true for the resulting coordinates:
"blocked" state.
Applying a Move: updateState(action)
updateState(action) is the core movement function. It records the current cell as visited, evaluates the action, and sets the resulting game mode:
| Outcome | Condition | Mode set | Position changes? |
|---|---|---|---|
| Successful move | Action is in validActions() | "valid" | Yes |
| Wall / boundary hit | Action not in validActions() but list is non-empty | "invalid" | No |
| Fully trapped | validActions() returns [] | "blocked" | No |
Game Modes
Thestate.mode field describes what happened on the most recent turn. The engine uses four named string modes throughout its reward and status logic:
| Mode | When it is set |
|---|---|
"start" | Initial state after reset() is called |
"valid" | The last action moved the player to a new open cell |
"invalid" | The last action pointed at a wall or outside the grid |
"blocked" | There are no valid actions from the current cell |
Observing the Board: observe()
observe() returns a flat 64-element array — a serialized snapshot of the current board state. The maze values (0 or 1) are preserved as-is, except the player’s current cell, which is overwritten with 0.5 to distinguish it from both walls and normal open cells:
Creating and Stepping Through a TreasureMaze
The
act(action) method is the public entry point for all moves. It calls updateState(), then getReward(), accumulates totalReward, evaluates gameStatus(), and returns all five values together so the caller never needs to invoke internal methods directly.