This bowling game API project allows users to create games, record rolls, get the current score, and request a natural language summary using a Large Language Model (LLM). The game follows standard bowling rules, and the LLM summarizes the game state.
-
Clone the Repository
git clone https://github.com/Unique-01/Bowling_Game_API.git cd Bowling_Game_API -
Setting Up a Virtual Environment
-
Create a Virtual Environment
- Open your terminal or command prompt.
python -m venv venv
This command creates a new directory called venv in your project folder containing the virtual environment.
-
Activate the Virtual Environment
-
For macOS and Linux:
source venv/bin/activate -
For Windows(Command Prompt):
venv\Scripts\activate
-
For Windows (PowerShell):
.\venv\Scripts\Activate
Note: Make sure you have Python installed on your system. If you have multiple versions of Python installed, you might need to use
pythonorpython3as per your installation. -
-
-
Install Dependencies
pip install -r requirements.txt
-
Set up Environmental variables
Create a.envfile in the project root directory with the following keys:SECRET_KEY=your-django-secret-key OPENAI_API_KEY=your-openai-api-key
SECRET_KEY: Django secret key for cryptography.OPENAI_API_KEY: API key for accessing OpenAI's GPT model.
-
Apply Migrations
python manage.py migrate
-
Run the server
python manage.py runserver
-
GET /games/
-
Description: Retrieve a list of created games.
-
Request Body: None
-
Response:
[ { "id": 1, "title": "Game title", "created_at": "2024-10-20T20:15:04.306397Z", "completed": false }, { "id": 1, "title": "Game title", "created_at": "2024-10-20T20:15:04.306397Z", "completed": false } ]
-
-
POST /games/
-
Description: Create a new game
-
Request Body (Optional):
{ "title": "Game title" } -
Response:
{ "id": 1, "title": "Game title", "created_at": "2024-10-20T20:15:04.306397Z", "completed": false }
-
-
POST /games/{game_id}/rolls/
-
Description: Record a roll for a specific game.
-
Request Body:
{ "knocked_down_pins": 5 } -
Response:
{ "message": "Roll recorded successfully", "data": { "id": 1, "game": 1, "frame": 1, "roll_number": 1, "knocked_down_pins": 5, "created_at": "2024-10-20T21:14:01.014099Z" } }
-
-
GET /games/{game_id}/score/
-
Description: Get the current score of the game.
-
Request Body: None
-
Response:
{ "game_id":1, "score": 5 }
-
-
GET /games/{game_id}/summary/
-
Description: Get the summary of the current game.
-
Request Body: None
-
Response:
{ "game_id":1, "summary": "In Game ID 1, there has been 1 roll so far in Frame 1, where 5 pins were knocked down. The game is currently in progress." }
-
-
Run Tests: Use the Django
manage.pycommand to run the test suitepython manage.py test -
Test Cases: The test suite covers the following cases:
- Listing games.
- Creating new games
- Recording rolls
- Handling edge cases like completed games, invalid rolls and nonexistent games.
- Fetching scores
- Generating natural language summaries using the LLM.