A modern C++ implementation of the Gomoku game with a client-server architecture, featuring WebSocket communication, AI optimization, and a clean separation of concerns.
This project has been refactored from a monolithic C application into a modern C++ client-server architecture with the following components:
- Board: Game board management and validation
- GameState: Complete game state management
- AIEngine: Advanced AI with optimizations (transposition tables, killer moves, etc.)
- JSONSerializer: JSON serialization/deserialization for network communication
- HTTPServer: HTTP request handling and session management
- WebSocketHandler: Real-time WebSocket communication
- GameSession: Individual game session management
- RedisPublisher: Optional Redis integration for pub/sub
- TerminalUI: Console-based user interface
- WebSocketClient: WebSocket client for real-time updates
- HTTPClient: HTTP client for game state synchronization
- GameController: Client-side game orchestration
- Modern C++20: Leverages latest C++ features and best practices
- Single Responsibility Principle: Each class has a focused, well-defined purpose
- Real-time Communication: WebSocket-based real-time updates
- Advanced AI: Optimized AI engine with multiple search optimizations
- Stateless Server: Server maintains minimal state, relying on client-provided game state
- Cross-platform: Works on Linux, macOS, and Windows
- Optional Redis: Can use Redis for additional pub/sub capabilities
Install the required dependencies:
Ubuntu/Debian:
make install-depsmacOS:
make install-deps-macosCentOS/RHEL/Fedora:
make install-deps-rhelUsing Make (Recommended):
# Build both server and client
make
# Build with debug flags
make debug
# Enable Redis support
USE_REDIS=1 makeUsing CMake:
mkdir build && cd build
cmake ..
make# Using Make
make run-server
# Or directly
./bin/gomoku-server -p 3030 -b 0.0.0.0# Using Make
make run-client
# Or directly
./bin/gomoku-client -h localhost -p 3030 -l hard- Client starts: Connects to server via HTTP and WebSocket
- Game initialization: Client sends game configuration to server
- Human move: Client sends move via HTTP POST to
/games/gomoku/play - AI thinking: Server processes move and starts AI calculation
- Real-time updates: Server sends AI progress via WebSocket
- AI move: Server sends completed AI move via WebSocket
- Game continues: Process repeats until game ends
POST /games/gomoku/start- Start a new gamePOST /games/gomoku/play- Make a move
MOVE_MADE- Move completed notificationAI_PROGRESS- AI thinking progress updateGAME_OVER- Game completion notificationERROR- Error notificationPING- Keep-alive ping
-p, --port: Server port (default: 3030)-b, --bind: Bind address (default: 0.0.0.0)-v, --verbose: Enable verbose logging
-h, --host: Server host (default: localhost)-p, --port: Server port (default: 3030)-l, --level: AI difficulty level (easy, medium, hard)-t, --timeout: Move timeout in seconds-s, --size: Board size (15 or 19)
{
"move": {
"game_id": "uuid",
"session_id": "uuid",
"game_type": "gomoku",
"name": "Gomoku",
"status": "in_progress",
"players": {
"x": {"name": "Human", "type": "human"},
"o": {"name": "Computer", "type": "ai"}
},
"depth": 5,
"moves": [
{"x": [10, 10], "timing": 34.34},
{"o": [11, 12], "timing": 0.00, "moves_evaluated": 1}
],
"current_player": "o"
}
}The AI engine includes several advanced optimizations:
- Transposition Tables: Cache evaluated positions
- Killer Moves: Prioritize moves that caused beta cutoffs
- Iterative Deepening: Start with shallow searches and deepen
- Alpha-Beta Pruning: Efficient search space reduction
- Move Ordering: Sort moves for better pruning
- Threat-Space Search: Focus on threatening positions
- Null-Move Pruning: Skip moves to detect zugzwang
gomoku-cpp/
├── include/ # Header files
│ ├── shared/ # Shared library headers
│ ├── server/ # Server headers
│ └── client/ # Client headers
├── src/ # Source files
│ ├── shared/ # Shared library implementation
│ ├── server/ # Server implementation
│ └── client/ # Client implementation
├── tests/ # Test files
├── build/ # Build artifacts
├── bin/ # Executables
├── lib/ # Libraries
├── CMakeLists.txt # CMake configuration
└── Makefile # Make configuration
# Run tests (when implemented)
make test- Follow modern C++ best practices
- Use RAII and smart pointers
- Prefer const correctness
- Use meaningful names and documentation
- Follow the Single Responsibility Principle
The AI engine is optimized for:
- Search Depth: Up to 8 plies in reasonable time
- Move Evaluation: 1000+ positions per second
- Memory Usage: Efficient transposition table management
- Network Latency: Minimal overhead for real-time play
- Fork the repository
- Create a feature branch
- Make your changes following the coding standards
- Add tests for new functionality
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- libwebsockets: WebSocket library for C/C++
- jsoncpp: JSON parsing and generation
- hiredis: Redis client library (optional)
- Google Test: Testing framework