An AI-powered intelligent Taboo game that creates card sets dynamically from custom topics and difficulty levels.
taibu is an ai-driven taboo game in which the user tries to guess a secret word generated by ai based on ai-generated clues while avoiding certain “forbidden” words generated by ai. The game provides a personalized gaming experience by dynamically generating word sets based on user-selected topics and difficulty levels.
- Dynamic Word Generation: AI generates target words and corresponding banned words based on the chosen topic and difficulty.
- Intelligent Hint Generation: The AI provides contextual hints that adapt to previous guesses, becoming more specific with each wrong attempt.
- Real-time Gameplay: Instant feedback is provided as players make guesses.
- Multiple Difficulty Levels: Options for easy, medium, and hard difficulties offer varied levels of challenge.
- Custom Topic Selection: Users can specify topics for a personalized gaming experience.
- Limited Attempts: Each word can be attempted a maximum of 5 times.
- Timer: Each round has a timer to add to the challenge.
- Similarity Check: Guesses are checked for similarity to the target word, allowing for approximate wins.
- User Interface: The game features a user-friendly interface with a setup screen, a game screen showing hints and input fields, and a result screen.
- Setup:
- Select a difficulty level from the dropdown (easy, medium, or hard).
- Enter a topic (e.g., foods, animals, countries, etc.) in the text field.
- Click the "Start Game" button.
- Gameplay:
- The game will display a hint for the secret word.
- Type your guess in the input field and press Enter.
- If your guess is incorrect, a new, more specific hint will be generated.
- Previous wrong guesses are displayed for reference.
- The game ends when you correctly guess the word, make a close guess, run out of attempts, or if the timer runs out.
- Results:
- The result screen will display whether you won or lost.
- Banned words for the round will be displayed for review.
- You can click the "Replay" button to start a new game with the same topic and difficulty.
The game logic is handled by the TabooGame class in main.py and operates in two main stages, with client-side interactions managed by static/script.js:
Word Generation:
- The user initiates the game setup through the HTML interface (
templates/index.html), selecting a difficulty and providing a topic. - Upon clicking "Start Game,"
static/script.jssends a POST request to the/gameendpoint with the selected difficulty and topic. - The FastAPI backend (
main.py) receives the request and, within thestart_gamefunction, creates agame_configobject. - The
generate_taboomethod of theTabooGameclass is called with thegame_config. This method:- Loads a system prompt from
system_prompts/system_prompt_wordgen.txt, which guides the AI in generating the word and banned words. - Sends a request to the OpenAI API (or a compatible service) using the specified model (defined in
.envasMODEL_NAME). The request includes the system prompt and user-provided topic and difficulty. - Receives the AI's JSON response, which includes the target word and a list of banned words.
- Parses the JSON response, extracts the target word and banned words, and stores the target word in
self.current_word. The method then returns a dictionary containingwordandbannedproperties.
- Loads a system prompt from
- The backend responds with the generated word and banned words as a JSON object to the frontend.
- The frontend (
static/script.js) stores these properties inthis.gamePropsand transitions to the game screen, displaying the difficulty and topic.
Hint Generation:
- After the game screen is displayed,
static/script.jscalls the/hintsendpoint to request a new hint. - The
get_hintfunction inapp.pyis called, which receives apropsobject (containing the target word and banned words) and an optional list ofprevious_guesses. - The
generate_hintmethod is called within theTabooGameclass. This method:- Loads a system prompt from
system_prompts/system_prompt_hintgen.txt, which guides the AI in hint generation. - Sends a request to the OpenAI API using the specified model, including the system prompt, the current word, banned words, and previous guesses.
- Parses the AI's response to extract a new hint. If the response is not a standard JSON, it attempts to clean and extract the hint.
- Returns the new hint as a string to the
/hintsendpoint.
- Loads a system prompt from
- The backend responds with the hint as a JSON object, including a "hint" key.
- The frontend (
static/script.js) receives the hint, which is displayed in the hint box with a fade-in effect, and sets the hint box height dynamically based on the hint length. - When the user makes a guess,
static/script.jscalculates the similarity with the target word using the Levenshtein distance. If the similarity exceeds a threshold (default %70) (defined bySIMILARITY_THRESHOLDinstatic/script.js), the game ends with a win. - If the guess is incorrect, the guess is added to the
previousGuesseslist, and the game requests a new hint via the/hintsendpoint. - This process continues until the player guesses the target word or the maximum number of attempts is reached, or the timer runs out, which is managed by the
startTimerfunction instatic/script.js.
- Backend: FastAPI (Python)
- Frontend: JavaScript, HTML, CSS
- AI Integration: OpenAI API compatible service
- Data Handling: JSON for API communications
- Python 3.12+
- OpenAI API key (or compatible)
git clone https://github.com/mdonmez/taibu.git
cd taibu
pip install -r requirements.txtCreate a .env file with the following:
BASE_URL=your_api_base_url
API_KEY=your_api_key
MODEL_NAME=your_model_nameuvicorn main:appAnd go to the http://127.0.0.1:8000 to start using the app.
Or just go to the hosted version: taibu
This project is licensed under the MIT License - See LICENSE for details.
This game was primarily developed using AI.