Giter VIP home page Giter VIP logo

werewolf-ai-party-game's Introduction

Werewolf Party Game with AI Bots

Important

I'm reworking the app to the Next.js + Firebase stack. I'm throwing away the Python backend because I feel like switching to Next.js simplifies things a lot. It's a common app for both frontend and backend. Firebase gives me a database for games and chat messages which is easier to use than DynamoDb. Firebase also provides authentication and hosting. I plan to complete the redesign in 1-2 weeks. So far all the work in going on in the nextjs-with-firebase branch.

I created this repo for the Backdrop Build V3 hackathon on February 26, 2024. It was based on my other project mafia-gpt. Mafia used OpenAI Assistants API which disappointed me a lot in process of development (slow, native client freezes randomly, outages on the OpenAI side), so I replaced it with a pure completion API. This gave me flexibility to switch between models (GPT-4, Claude3 Opus, Mistral Large, Grok 1.5 for now) but forced to store the chat history in DynamoDB. I like this approach so I deprecated mafia-gpt in favor of this repo.

All projects registry: Builds

The event project page: ai-werewolf

Gameplay

What is nice about this game is complete freedom in the themes and roleplay. You can create any setting you want. A movie, a book, any historical period, or even a completely new world. The game is very flexible and can be adapted to any setting.

Here is an example of the "Terminator" theme:

Or "Lord of the Rings":

I really like these thematic dialogs and how creative the bots are.

UI is chunky and ugly yet but I'm working on it. It's a very early stage of the project. It is only possible to create a new game, to chat with bot players and to initiate a first round of voting. I have more things in the API but UI is not ready yet.

Setup

To run the project locally, you need:

  • Install Docker and Docker Compose, run local DynamoDb with docker-compose up
  • Frontend: install node.js and npm, install dependencies with npm install, and run the app by npm run web
  • Backend: install Python 3.11+ and Pypenv, install dependencies with pipenv install, and run the FastAPI server

DynamoDB

I prefer to run it with Docker Compose. There is a firebase in the root directory, just run it. You need to have docker and docker-compose installed.

docker-compose up

Backend

Install Python 3.11+ and Pipenv.

I use FastAPI Python web server and React Native frontend application. Here are my Intellij Idea run configurations:

Note: Before running Python code, rename the .env.template file into .env and fill in the values. All environmental variables from it will be loaded by functions and used to talk to the external APIs (DynamoDB, OpenAI).

Run Python functions [deprecated as I already have UI]

I don't have any better runner than Python junit tests for now. In future, I'll use a web server with UI in React Native for the local development. I'll deploy functions to Lambdas and host UI somewhere separately. Each function has a separate test. It does not make sense to run all of them, only for the function you want to run. To run tests, install Python dependencies using Pipenv (more details about it is below), then run a test you need like this:

python -m unittest test_lambda_functions.TestGameFunctions.test_init_game

Pipenv setup and dependency installation

I use pipenv to manage dependencies. Install it, create a virtual environment, activate it and install dependencies.

  1. Install pipenv using official docs. For example, on Mac:

    pip install pipenv --user
  2. Add pipenv to PATH if it's not there. For example, I had to add to the ~/.zshrc file the following line:

    export PATH="/Users/hiper2d/Library/Python/3.11/bin:$PATH"
  3. Install packages and create a virtual environment for the project:

    cd <project dir> # navigate to the project dir
    pipenv install

    This should create a virtual environment and install all dependencies from Pipfile.lock file.

    If for any reason you need to create a virtual environment manually, use the following command:

    pip install virtualenv # install virtualenv if you don't have it
    virtualenv --version # check if it's installed
    cd <virtualenv dir> # for example, my virtual envs as here: /Users/hiper2d/.local/share/virtualenvs
    virtualenv <virtualenv name> # I usually use a project name
  4. To swtich to the virtual environment, use the following command:

    cd <project dir>
    pipenv shell

    If this fails, then do the following:

    cd <virtualenv dir>/bin
    source activate

Frontend

Install node.js and npm. Navigate to the werewolf-client and run:

npm install
npm run web

This will start the frontend on the localhost:8081 address.

Setup(Windows)

To run the project locally, you need:

  • Install Docker and Docker Compose, run local DynamoDb with docker-compose up
  • Backend: install Python 3.11+
  • Frontend: install node.js and npm, navigate to the werewolf-client install dependencies with npm install, and run the app by npm run web
  • Edit environment variables in control panel and add two environment variables to python in PATH, for example:
..\AppData\Local\Programs\Python\Python312
..\AppData\Local\Programs\Python\Python312\Scripts
  • Install dependencies in root directory pip install -r requirements.txt
  • Inside .env file add keys and add AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, remove AWS_PROFILE:
AWS_ACCESS_KEY_ID=DUMMYIDEXAMPLE
AWS_SECRET_ACCESS_KEY=DUMMYEXAMPLEKEY
  • From server folder run web server: uvicorn local_server:app --reload

werewolf-ai-party-game's People

Contributors

dagontwist avatar hiper2d avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

werewolf-ai-party-game's Issues

Implement Game Loading

Add functionality to the All Games menu item:

  • Open a modal window with a list of all games (no pagination or sort for now) sorted by creation date DESC
  • Allow to select a game
  • Load the selected game with the corresponding chat history

Implement two rounds of day voting

Here is the plan:

  • A user can start the first round of voting. This is implemented via a button on UI but it requires a little change. Currently, players vote secretly. We should display votes in the chat.
  • After the first round is done, leaders should speak for themself. It the human player is among them, a dialog window should appear asking for a speech.
  • Then the second round should start automatically. It should also be open.

Update for the first phase [Apr 29, 2024]:

  • When the first phase of voting starts, UI takes all bot ids, adds some id for the human player, shuffles all of this, and starts picking ids from the list
  • Before everybody votes, UI sends a request to the backend to add a message to the chat history that the voting has started
  • For each bot id, ask the bot to vote, then post the response to the common chat (and add it to the history for all). This means that the voting is open, and each new voter can see the results of previous voters
  • When a human player needs to vote, a dialog appears. It asks to choose a name and to provide a reason. This is sent to the backend to be saved and posted to the chat
  • After everybody voted, UI calculates the leaders

The second phase should start automatically. Leaders should speak for themselves, and then everybody votes for the second time without providing reasons. The finalist is eliminated by adding information to the chat history and to the chat. The game state should be updated. Then the game night started.

Problems:

  • When the vote starts, this should change the game state. GAme reload should be able to continue from this state. Need to think how exactly.

Implement LLM Type Selection in New Game dialog

First, let's make Claude agent suitable for Bot Players. There is one problem with that described in the ClaudeAgent class in a comment.

Then, let's add a selection to the New Game dialog for GM and Bot Players types. Not sure yet how. Maybe this way: how many GPT-4 bots and Claude bots should be in the game. A bot type should be persisted to the database so it can be restored on load. Yeah... lots of work actually. But this is a super cool feature I must add.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.