Spaces:
Running
Running
File size: 4,688 Bytes
466436b 502af73 466436b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# Trigo Tools
Development tools for the Trigo project.
## Random Game Generator
Generate random Trigo games in TGN (Trigo Game Notation) format for testing, development, and analysis.
### Usage
```bash
# Generate 10 games with default settings (play until territory settled)
npm run generate:games
# Generate 100 games with custom move range
npm run generate:games -- --count 100 --moves 20-80
# Generate games with exactly 30 moves each
npm run generate:games -- --moves 30 --count 50
# Generate games on 3x3x3 board (plays until settled)
npm run generate:games -- --board "3*3*3" --count 50
# Generate 2D games (9x9x1 board)
npm run generate:games -- --board "9*9*1" --count 20
# Higher pass probability
npm run generate:games -- --pass-chance 0.3
# Custom output directory
npm run generate:games -- --output "my_games" --count 50
```
### Options
| Option | Short | Default | Description |
|--------|-------|---------|-------------|
| `--count` | `-c` | 10 | Number of games to generate |
| `--moves` | `-m` | (settled) | Moves per game as "MIN-MAX" or single number. Default: play until neutral territory = 0 |
| `--pass-chance` | | 0 | Probability of passing (0.0-1.0) |
| `--board` | `-b` | "random" | Board size as "X*Y*Z" or "random" |
| `--output` | `-o` | "output" | Output directory (relative to tools/) |
| `--help` | `-h` | - | Show help message |
### How It Works
**Default Mode (no --moves specified):**
1. Creates a new Trigo game with the specified board shape
2. Plays random valid moves until the board reaches 90% coverage
3. After 90% coverage, checks territory after each move
4. Stops when neutral territory reaches 0 (game is fully settled)
5. Results in complete, finished games with all territory claimed
**Custom Move Mode (--moves specified):**
1. Creates a new Trigo game with the specified board shape
2. Randomly selects valid moves for the specified number of moves
3. Respects Go rules: Ko, suicide prevention, capture
4. Games may end early on double-pass
5. Exports each game to TGN format with metadata
### Output Format
Generated files are named using SHA-256 hash of the TGN content: `game_<HASH>.tgn`
This ensures:
- **Content-based naming**: Same game content = same filename
- **Duplicate detection**: Identical games won't overwrite each other
- **Deterministic**: Reproducible filenames independent of generation time
Example output:
```
tools/output/
├── game_a3f5c8d912e4b6f1.tgn
├── game_7b2d9e1a4c8f3605.tgn
└── game_9e4b6f1a3f5c8d91.tgn
```
### TGN Format Example
```tgn
[Event "Random Generated Game"]
[Site "Batch Generator"]
[Date "2025.11.03"]
[Black "Random Black"]
[White "Random White"]
[Board "5x5x5"]
[Rules "Chinese"]
[Application "Trigo Random Generator v1.0 (5×5×5)"]
1. 000 y00
2. 0y0 yy0
3. aaa zzz
4. Pass 0az
5. z0z Pass
```
### Performance
- **Small boards (3×3×3)**: ~250 games/second
- **Standard boards (5×5×5)**: ~75 games/second
- **Large boards (9×9×1)**: ~33 games/second
Generating 1000 games on a 5×5×5 board takes approximately 13 seconds.
### Use Cases
1. **Testing TGN parser** - Create diverse test files for import functionality
2. **Performance testing** - Generate large datasets for board rendering tests
3. **AI training** - Create training data for future AI opponent
4. **Game analysis** - Study patterns in random gameplay
5. **Format validation** - Verify TGN export works correctly across scenarios
### Board Sizes
**3D Boards:**
- `3*3*3` - Tiny cube (27 positions)
- `5*5*5` - Standard cube (125 positions)
- `7*7*7` - Large cube (343 positions)
- `9*9*2` - Wide board (162 positions)
**2D Boards (Traditional Go):**
- `9*9*1` - Small board (81 positions)
- `13*13*1` - Medium board (169 positions)
- `19*19*1` - Standard board (361 positions)
### Implementation Details
**File:** `tools/generateRandomGames.ts`
**Key Functions:**
- `generateRandomGame()` - Simulates a complete random game
- `getValidMoves()` - Finds all legal moves for current player
- `selectRandomMove()` - Randomly picks from valid moves
- `generateBatch()` - Generates multiple games in parallel
**Safety Features:**
- Validates all moves using game rules (Ko, suicide, occupation)
- Handles cases where no valid moves exist (must pass)
- Respects double-pass game end condition
- Progress indicator for large batches
- Error handling and validation
### Dependencies
- **tsx** - TypeScript execution
- **yargs** - Advanced command-line argument parsing with validation
- **TrigoGame** - Core game logic from `inc/trigo/game.ts`
- **Node.js fs/path** - File system operations
---
For more information about TGN format, see `/tests/game/trigoGame.tgn.test.ts`
|