A Python client for developing AI agents that play Codenames by providing clues based on the current game state.
- Clone this repository
git clone [email protected]:rmorain/codenames-ai-client.git
cd codenames-ai-client- Set up a virtual environment
python -m venv venv
source venv/bin/activate If you prefer, you can set up a Conda environment. Python 3.11 is recommended.
- Install the package in editable mode:
pip install -e .- Download
GoogleNews-vectors-negative300.bin
curl -L -o ~/Downloads/googlenewsvectorsnegative300.zip\
https://www.kaggle.com/api/v1/datasets/download/leadbest/googlenewsvectorsnegative300
unzip ~/Downloads/googlenewsvectorsnegative300.zip- Move
GoogleNews-vectors-negative300.binto the main project folder
You can delete GoogleNews-vectors-negative300.bin.gz
- Run client with Word2Vec AI spymaster From the project root directory
python client.py <GAME_ID> <TEAM>TEAM must be either 'red' or 'blue'
Example: python client.py ABCD red
This guide will help you create your own AI agent for playing Codenames.
- Create a new file in the
agentsdirectory (e.g.,my_agent.py) - Import the required base classes:
from base.assoc import Assoc
from base.constants import Team
from base.spymaster import BaseSpymasterYou need to implement two classes:
Inherit from Assoc and implement these methods:
class MyAssoc(Assoc):
def __init__(self):
super().__init__()
# Initialize your model/embeddings/data here
def getAssocs(self, pos, neg, topn):
"""
Find words associated with positive words but not negative words.
Args:
pos: List of words to associate with
neg: List of words to avoid
topn: Number of associations to return
Returns:
List of (word, score) tuples
"""
pass
def preprocess(self, w):
"""
Preprocess words before looking up associations.
Args:
w: Input word
Returns:
Processed word
"""
passInherit from BaseSpymaster and implement the clue generation:
class MySpymaster(BaseSpymaster):
def __init__(self, assoc):
super().__init__(assoc)
def makeClue(self, board, team: Team):
"""
Generate a clue for your team.
Args:
board: Dictionary with keys:
'R': List of red team's words
'U': List of blue team's words
'N': List of neutral words
'A': List of assassin words
'team': Team.RED or Team.BLUE
Returns:
tuple: ((clue_word, number_of_words), debug_info)
"""
passUpdate client.py to use your agent:
from agents.my_agent import MyAssoc, MySpymaster
def getAI():
return MySpymaster(MyAssoc())- Word Embeddings: Use models like Word2Vec, GloVe, or BERT to find semantically similar words
- Language Models: Use GPT or other LLMs to generate associations
- Knowledge Graphs: Use ConceptNet or WordNet to find related concepts
- Custom Datasets: Create your own word association database
- Use the
utils.helpers.isValid()function to check if your clue is valid - Test your agent with different board configurations
- Consider both positive and negative associations
- Remember that clues must be:
- Single English words
- Not derivatives of board words
- Not proper nouns
- Not acronyms
See agents/word2vec.py for a complete example implementation using Word2Vec embeddings.
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.