- Node.js: Ensure that you have Node.js installed. You can download it from nodejs.org. Latest LTS version should be fine.
- Docker: You can download it from docker.com.
- Clone the Repository:
git clone https://github.com/premithk/game-of-three.git
- Backend Setup:
- Navigate to the
game-of-three
folder. - Run
npm install
to install dependencies. You can also useyarn
- Run
docker-compose up
to start the NestJS instances in Docker containers.
- Navigate to the
- To see the game running:
- There is a script called
play.js
in thescript
folder. - Run it using node to see the game in action.
node script/play.js
- There is a script called
- GameService: Manages the game logic, including starting the game, playing turns, and checking for game over.
- GameController: Exposes RESTful APIs for starting the game, playing turns, and checking if the game is over.
- Unit tests are found along with the controller and the service files.
./src/game/game.controller.spec.ts
and./src/game/game.controller.spec.ts
- E2E tests are found in
./test/app.e2e-spec.ts
. The E2E test also contains a test for the full gameplay. - You can run the unit tests using
npm run test
andnpm run test:e2e
- A random number is generated when a player starts, and the game begins.
- Players take turns to adjust the number to be divisible by 3, and the game continues until one player reaches 1.
- Two independent instances of the same NestJS application are deployed using Docker Compose to simulate two players.
- Simplified Logic: The game logic is kept simple for demonstration purposes. You may enhance it for a more complex and engaging gaming experience.
- Single Instance Interaction: The game assumes interaction between two players within the same instance. For a real-world scenario, consider integrating WebSocket or other communication methods for cross-instance communication.
- Error Handling: Basic error handling is implemented. Further enhancements can be made to handle edge cases and improve error messages.
- Security: The application does not implement advanced security measures. Ensure proper security practices for production deployment.
![game_of_3](https://private-user-images.githubusercontent.com/7926867/296611350-f53e1f66-3918-48d8-b1f6-7e69a4a106e6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM4MjY4ODcsIm5iZiI6MTcyMzgyNjU4NywicGF0aCI6Ii83OTI2ODY3LzI5NjYxMTM1MC1mNTNlMWY2Ni0zOTE4LTQ4ZDgtYjFmNi03ZTY5YTRhMTA2ZTYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgxNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MTZUMTY0MzA3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Yjk4M2M4ZWFiM2YwN2IyMjY3Y2U3NTc0OTljOTEzYjE0MjExYzE2OTU5NmU3ZGIyN2MwY2Y2NGMyOTE2NDNjOCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.Jf0QOAIZcxHOdO6LI_iViJ5nSEI0Ix5iadOEnv3t1wE)