File size: 6,107 Bytes
466436b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
502af73
466436b
 
 
 
 
 
502af73
466436b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
502af73
466436b
 
 
 
 
502af73
466436b
 
 
 
 
502af73
466436b
 
 
 
 
502af73
466436b
 
 
 
 
502af73
466436b
 
 
 
 
 
 
502af73
466436b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
502af73
466436b
 
 
 
 
 
 
 
 
 
502af73
466436b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
502af73
466436b
 
 
 
 
 
 
502af73
466436b
 
 
 
 
 
 
 
502af73
466436b
 
 
 
 
 
 
 
 
 
502af73
466436b
 
 
 
 
 
 
502af73
466436b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
502af73
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# Trigo - 3D Go Board Game

A modern web implementation of Go played on a three-dimensional board, built with Vue 3, TypeScript, Node.js, and Three.js.

## Features

- **3D Board**: Play Go on a 5x5x5 three-dimensional board
- **Multiplayer**: Real-time online gameplay via WebSocket
- **Single Player**: Play against AI opponents
- **Game Replay**: Review and analyze completed games
- **Modern Tech Stack**: Vue 3, TypeScript, Three.js for WebGL rendering

## Project Structure

```
trigo-web/
├── app/                # Frontend application (Vue 3)
│   ├── src/
│   │   ├── components/ # Vue components
│   │   ├── views/      # Page views
│   │   ├── game/       # Game logic and 3D rendering
│   │   ├── store/      # Pinia state management
│   │   └── services/   # API and WebSocket services
│   └── package.json
├── backend/            # Backend server (Node.js)
│   ├── src/
│   │   ├── controllers/
│   │   ├── services/   # Game logic and room management
│   │   ├── sockets/    # Socket.io handlers
│   │   └── server.ts   # Main server entry
│   └── package.json
├── inc/                # Shared code between frontend and backend
│   ├── trigo/          # Core game logic and types
│   │   ├── types.ts    # TypeScript interfaces
│   │   ├── gameUtils.ts # Game utility functions (capture, Ko, territory)
│   │   ├── game.ts     # TrigoGame class - main game state management
│   │   └── ab0yz.ts    # TGN coordinate encoding
├── tests/              # Test files
│   └── game/           # Game logic tests (TrigoGame)
├── vitest.config.ts    # Vitest test configuration
├── tsconfig.json       # TypeScript configuration
└── package.json        # Root package.json with dev scripts
```

## Getting Started

### Prerequisites

- Node.js (v18+ recommended)
- npm or yarn

### Installation

1. Clone the repository:

```bash
git clone [repository-url]
cd trigo-web
```

2. Install all dependencies:

```bash
npm run install:all
```

This will install dependencies for the root, frontend, and backend.

### Development

Run both frontend and backend in development mode:

```bash
npm run dev
```

Or run them separately:

```bash
# Frontend only (runs on http://localhost:5173)
npm run dev:app

# Backend only (runs on http://localhost:3000)
npm run dev:backend
```

### Building for Production

Build both frontend and backend:

```bash
npm run build
```

### Testing

The project includes comprehensive unit tests for the game logic (TrigoGame class).

**Run all tests once:**

```bash
npm run test:run
```

**Run tests in watch mode (auto-rerun on file changes):**

```bash
npm test
```

**Run tests with UI dashboard:**

```bash
npm run test:ui
```

**Run specific test file:**

```bash
npm exec vitest -- run tests/game/trigoGame.core.test.ts
```

**Test Coverage:**

- **109/109 tests passing (100%)**
- Core functionality (35 tests) - Drop, pass, surrender, reset
- History management (21 tests) - Undo, redo, jump to step
- Game rules (18 tests) - Capture, Ko rule, suicide, territory calculation
- State management (32 tests) - Serialization, callbacks, session storage

**Test Files Location:** `tests/game/`

- `trigoGame.core.test.ts` - Basic game operations
- `trigoGame.history.test.ts` - History and navigation
- `trigoGame.rules.test.ts` - Go game rules implementation
- `trigoGame.state.test.ts` - State persistence and callbacks

### Code Formatting

Format all code with Prettier:

```bash
npm run format
```

Check formatting without making changes:

```bash
npm run format:check
```

## Technology Stack

### Frontend

- **Vue 3** - Progressive JavaScript framework
- **TypeScript** - Type-safe JavaScript
- **Three.js** - 3D graphics library for WebGL
- **Pinia** - State management
- **Vue Router** - Client-side routing
- **Socket.io Client** - WebSocket communication
- **Vite** - Fast build tool
- **SASS** - CSS preprocessor

### Backend

- **Node.js** - JavaScript runtime
- **Express** - Web framework
- **Socket.io** - Real-time bidirectional communication
- **TypeScript** - Type-safe JavaScript
- **UUID** - Unique ID generation

## Game Rules

Trigo extends the traditional Go game into three dimensions:

1. The game is played on a 5x5x5 cubic board
2. Players take turns placing stones (black and white)
3. Stones are captured when completely surrounded in 3D space
4. The goal is to control more territory than your opponent

## API Endpoints

### REST API

- `GET /health` - Health check
- `GET /api/rooms` - List active game rooms
- `GET /api/rooms/:roomId` - Get specific room details

### WebSocket Events

#### Client → Server

- `joinRoom` - Join or create a game room
- `leaveRoom` - Leave current room
- `makeMove` - Make a game move
- `pass` - Pass turn
- `resign` - Resign from game
- `chatMessage` - Send chat message

#### Server → Client

- `roomJoined` - Successfully joined room
- `gameUpdate` - Game state update
- `playerJoined` - Another player joined
- `playerLeft` - Player left room
- `chatMessage` - Incoming chat message
- `gameEnded` - Game finished

## Development Guidelines

### Code Style

- Uses Prettier for consistent formatting
- Tab indentation (following prototype style)
- Double quotes for strings
- No trailing commas
- Semicolons always

### Git Workflow

1. Create feature branch from `main`
2. Make changes and test locally
3. Format code with `npm run format`
4. Commit with descriptive messages
5. Create pull request

## Based On

This project is a modern reimplementation of the original Trigo prototype found in `third_party/klstrigo/`, updating the technology stack while preserving the core game mechanics and 3D gameplay experience.

## License

MIT License - See LICENSE file for details

## Contributing

Contributions are welcome! Please read the contributing guidelines before submitting pull requests.

## Support

For issues, questions, or suggestions, please open an issue on GitHub.