# Arrow Maze

## Game Description

Arrow Maze is a logic puzzle game with the following rules:

The maze consists of an n x m grid, where:
- X represents empty cells
- Numbers represent the starting points of ray arrow strings

Players need to fill in arrows in the empty cells. Arrows can extend upward (↑), downward (↓), left (←), right (→), or diagonally (↖, ↗, ↘, ↙).

Each number represents the starting point of ray arrow strings, and the total number of arrows in all ray arrow strings originating from that number equals the number.

All arrows must be covered by some ray arrow string.

## Example

Original maze:
```
[
    ["X", "9", "X", "X", "X", "X", "X", "X"],
    ["X", "X", "X", "X", "7", "X", "X", "X"],
    ["6", "X", "X", "X", "X", "2", "X", "X"],
    ["X", "X", "X", "X", "X", "X", "X", "X"],
    ["X", "X", "X", "X", "X", "1", "X", "7"],
    ["X", "X", "X", "X", "X", "X", "8", "X"],
    ["X", "X", "X", "6", "X", "X", "X", "X"],
    ["X", "X", "9", "X", "X", "X", "X", "X"]
]
```

The solution requires filling in arrows in the empty cells (X) so that the total number of arrows in all ray arrow strings originating from each number equals that number.

## Code Implementation

This project implements the generation and verification logic for the Arrow Maze game. The project structure is as follows:

### Core Components

1. **ArrowMaze Class** (`scripts/arrow_maze.py`)
   - Implements the game generation logic
   - Provides a `generate` method to randomly generate mazes and their solutions
   - Provides an `extract_answer` method to extract answers from model responses

2. **ArrowMazeVerifier Class** (`scripts/arrow_maze_verifier.py`)
   - Implements the answer verification logic
   - Verification conditions include:
     - Answer grid size matches the original puzzle
     - Number positions match the original maze
     - All empty cells are filled with arrows
     - Arrow symbols are valid
     - The total number of arrows in ray strings equals the starting number
     - All arrows can be covered by ray strings

3. **Prompt Generation** (`scripts/arrow_maze_prompt.py`)
   - Provides templates for game descriptions in Chinese and English
   - Dynamically generates game prompts

### Verification Logic

The verification logic for Arrow Maze includes the following steps:

1. Check if the answer grid size matches the problem grid
2. Check if the number cells in the answer grid match the number cells in the problem grid
3. Check if the empty cells ("X") in the problem grid are filled with arrows in the answer grid
4. Check if the arrow symbols are valid (↑, ↓, ←, →, ↖, ↗, ↘, ↙)
5. Check if the pre-filled arrows in the answer grid match those in the problem grid
6. Check if all arrows can be covered by ray arrow strings
7. Check if the total length of ray arrow strings originating from each number equals that number

## How to Run

1. Generate game data:
   ```bash
   python -m games.tasks.arrow_maze.scripts.arrow_maze --num_of_data 100 --width 8 --height 8 --arrow_fill_rate 0.3
   ```
   
   Parameter description:
   - `num_of_data`: Number of puzzles to generate
   - `width`: Maze width
   - `height`: Maze height
   - `arrow_fill_rate`: Pre-filled arrow ratio (between 0.0-1.0), controls game difficulty. Higher values mean more pre-filled arrows and lower difficulty

2. Or use the script to run with one command:
   ```bash
   ./run.sh
   ```