This repository contains a full-stack implementation of the classic board game Reversi. It consists of a Node.js backend with Socket.IO for real-time communication.
- Add a spectator mode for other users to watch ongoing games.
- Implement a ranking system for players.
- Add more AI difficulty levels.
- Implement MySQL Database to store game results.
- Create a 3D Reversi game with Node.js, React.js, and Three.js (8x8x6 grid).
- Develop mobile versions to support Android and iOS platforms.
- Add support for Helm Chart for K8s deployment.
-
Game Modes:
- Human vs Human
- Human vs AI
-
Multiplayer Functionality:
- Join rooms using unique room IDs
- Real-time game updates using Socket.IO
-
Game Board:
- 8x8 grid
- Visual representation of black and white pieces
- Highlighting of legal moves
-
Game Logic:
- Implemented on the server-side (not shown in the provided code)
- Handles move validation, turn switching, and game ending conditions
-
Chat System:
- Real-time chat functionality for players in the same room
-
Game Information Display:
- Current player turn
- Player color assignment
- Score tracking (number of pieces for each player)
-
Move History:
- Navigate through previous game states
- View the current game state
-
I18n:
- Supports multiple languages (English and Traditional Chinese)
-
Responsive Design:
- Adapts to different screen sizes (CSS not provided in the given code)
- Frontend: React.js
- State Management: React Hooks (useState, useEffect)
- Routing: React Router
- Real-time Communication: Socket.IO client
- Internationalization: react-i18next
- Ensure you have Node.js and npm installed on your system.
- Clone the repository to your local machine.
- Navigate to the project directory and run
npm ci
to install dependencies. - Start the development server with
npm start
. - The app should now be running on
http://localhost:3000
.
Note: This frontend application requires a corresponding backend server running on http://localhost:3001
to handle game logic and Socket.IO connections.
- Enter a room ID and select a game mode (Human vs Human or Human vs AI).
- Click "Join Room" to enter the game.
- The game starts when two players join the room (or one player for AI mode).
- Click on a highlighted cell to make a move during your turn.
- Use the chat feature to communicate with your opponent.
- The game ends when no more moves are possible. The player with the most pieces wins.
The server is a Node.js application that handles game logic, real-time communication, and persistent storage using Redis.
- Socket.IO for real-time game updates
- Redis for game state persistence
- Support for both player vs player and player vs AI modes
- Robust game logic implementation including move validation
- Player management and turn control
- Chat functionality
- Logging with Winston
- Express
- Socket.IO
- ioredis
- Winston
- dotenv
- Install dependencies: npm ci
- Set up environment variables:
Create a
.env
file in the root directory and add the following: - Start the server: npm run start
The server will be running on
http://localhost:3001
(or the port specified in your .env file).
The game implements the standard Reversi rules, including:
- Valid move checking
- Piece flipping
- Turn management
- Win condition checking
joinRoom
: Join a game roommakeMove
: Make a move on the boardsendMessage
: Send a chat messagegetLegalMoves
: Get legal moves for the current playerupdateBoard
: Receive updated board stateswitchTurn
: Notify of turn changegameStart
: Notify that the game has startedgameOver
: Notify of game end and winnerskipTurn
: Notify when a player's turn is skippedplayerDisconnected
: Notify when a player disconnects
The game includes a simple AI opponent that:
- Chooses moves based on the number of pieces flipped
- Has a delay before making moves to simulate "thinking"
Game states are stored in Redis with a TTL of 1 hour.
The application uses Winston for logging. Logs are written to:
error.log
for error-level logscombined.log
for all logs
In non-production environments, logs are also output to the console.
To run the server in development mode: npm run start