# Survo Matrix Filling Game

## Game Description

Survo is a matrix filling game with the following rules:

1. Given an n*n two-dimensional matrix where some positions are pre-filled with numbers, and the remaining positions are marked with 'X' (represented internally as 0).
2. The numbers in the last row and last column represent the sum of all preceding numbers in that row or column.
3. Given a set of candidate numbers, these numbers need to be filled into the positions marked with 'X'.
4. Each candidate number can only be used once.
5. After filling, it must be ensured that the sum of each row and column equals the last element.

## Example

```
There is a 3*3 two-dimensional matrix where the last element of each row and column equals the sum of the other elements in that row and column. The matrix is:
[[1,X,3,6],[1,X,3,6],[1,X,3,6],[3,6,9,18]]
where some elements are replaced with X. There is a set of candidate numbers [2,2,2] that can be filled into the X positions in the matrix to satisfy the corresponding rules. Please fill them in, with each number used only once, and provide the filled matrix.
```

## Core Logic

### Game Generation Logic

1. First generate a complete n*n matrix where:
   - Randomly fill all positions of the (n-1)*(n-1) submatrix
   - Calculate the sum of each row and column, fill into the last row and last column
   - Calculate the bottom-right element (n-1, n-1)

2. Randomly select x positions, replace them with 0 (displayed as 'X'), and record the replaced numbers as candidate numbers.

3. Generate game prompts, including matrix description and candidate numbers.

### Verification Logic

The verifier checks whether the submitted answer meets the following conditions:

1. Whether the matrix dimensions are correct
2. Whether the pre-filled elements in the original matrix are preserved
3. Whether the filled numbers match the candidate numbers (quantity and values)
4. Whether the sum of each row and column is correct

### Answer Extraction Logic

Methods for extracting matrix answers from model responses include:

1. Extract matrix from Python code blocks
2. Extract matrix from general code blocks
3. Directly extract possible matrix representations from text

## Usage

1. Run the game generator:

```bash
python -m games.tasks.survo.scripts.survo --num_of_data 100 --n 4 --x 3 --min_num 1 --max_num 9
```

Parameter explanations:
- `num_of_data`: Number of game data to generate
- `n`: Matrix dimensions
- `x`: Number of digits to be filled
- `min_num`: Minimum value of numbers in the matrix
- `max_num`: Maximum value of numbers in the matrix

## Game Features

1. Each generated game is guaranteed to have a solution
2. Randomly selects Chinese or English prompts
3. Diversified prompt templates
4. Strong fault tolerance when verifying answers