Spaces:
Running
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
- Clone the repository:
git clone [repository-url]
cd trigo-web
- Install all dependencies:
npm run install:all
This will install dependencies for the root, frontend, and backend.
Development
Run both frontend and backend in development mode:
npm run dev
Or run them separately:
# 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:
npm run build
Testing
The project includes comprehensive unit tests for the game logic (TrigoGame class).
Run all tests once:
npm run test:run
Run tests in watch mode (auto-rerun on file changes):
npm test
Run tests with UI dashboard:
npm run test:ui
Run specific test file:
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 operationstrigoGame.history.test.ts- History and navigationtrigoGame.rules.test.ts- Go game rules implementationtrigoGame.state.test.ts- State persistence and callbacks
Code Formatting
Format all code with Prettier:
npm run format
Check formatting without making changes:
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:
- The game is played on a 5x5x5 cubic board
- Players take turns placing stones (black and white)
- Stones are captured when completely surrounded in 3D space
- The goal is to control more territory than your opponent
API Endpoints
REST API
GET /health- Health checkGET /api/rooms- List active game roomsGET /api/rooms/:roomId- Get specific room details
WebSocket Events
Client → Server
joinRoom- Join or create a game roomleaveRoom- Leave current roommakeMove- Make a game movepass- Pass turnresign- Resign from gamechatMessage- Send chat message
Server → Client
roomJoined- Successfully joined roomgameUpdate- Game state updateplayerJoined- Another player joinedplayerLeft- Player left roomchatMessage- Incoming chat messagegameEnded- 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
- Create feature branch from
main - Make changes and test locally
- Format code with
npm run format - Commit with descriptive messages
- 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.