This is a Twitter bot that plays the game of (Iterated) Prisoner's Dilemma created by Vladimir Haltakov. The interface to the bot is implemented using tweets and replies. The bot is deployed on Twitter @DilemmaBot.
- The bot uses the Twitter Search API to listen for mentions of its Twitter handle @DilemmaBot.
- When mentioned together with the word "play" in the text, it will start a new game and reply with the rules.
- When the user replies with their move (either "cooperate" or "defect"), the bot plays as well and replies with the outcome and the current score.
- The bot will play 10 rounds of the Prisoner's Dilemma game and store the results in a file.
This section explains how you can deploy the bot yourself.
The bot currently plays the tit-for-tat strategy. It will always start cooperating and will then copy the opponents last move.
New strategies can be easily implemented using an abstracted interface.
- Create a file
.env
in the root folder containing you Twitter API tokens
API_KEY=xxx
API_SECRET=yyy
ACCESS_TOKEN=zzz
ACCESS_TOKEN_SECRET=uuu
- Create a Python virual environment and source it
python3 -m venv .venv
source .venv/bin/activate
- Install the requirements
pip3 install -r requirements.txt
- Run the Twitter client
export PYTHONPATH="."
python3 prisonersdilemma/twitter_client.py
Run the Twitter cliend with the -h
option to get a detailed usage instructions.
The bot will create several files containing its state (if you need to stop it and start it again) and some statistics:
twitter_bot_state.json
- the last tweet ID that the bot replied to. This is important to avoid replying twice to a tweet and to speed up the search.active_games.json
- dictionary specifying the games that the bot is currently playingtwitter_bot.log
- log file dumparchive.json
- list of completed games
For more information about the game of Prisoner's Dilemma check out this thread.