Nathan Jones (2762057)
A simplified version of the game Codenames is implemented in Python using spaCy, NLTK and Pygame to explore semantic reasoning tasks using two appraoches: word embeddings and WordNet taxonomies.
This project was implemented using Python 3. The list of required packages can be found in
requirements.txt. To install them, run the following command from the root directory of this project (preferably in a virtual environment).
$ pip3 install -r requirements.txtAfter this, the en_core_web_lg spaCy model and the WordNet NLTK corpus can be downloaded as follows:
$ python3 -m spacy download en_core_web_lg$ python3
>>> import nltk
>>> nltk.download('wordnet')
>>> exit()If you encounter the error [SSL: CERTIFICATE_VERIFY_FAILED] when using
nltk.download(), see here.
To play the main game:
$ python3 main.pyBy default, the embedding agent is used, but you can specify the model using the additional command-line argument as follows:
$ python3 main.py --model <model_choice>The other model option is
wordnet. Runpython3 main.py --helpfor details.
To explore the model outputs in more detail run:
$ python3 dev.pymain.py Implements the game loop, rendering and user input functionality in Pygame.
codenames.py Implements the rule set and coordinates the core game elements of Codenames.
gameboard.py Contains the
Boardclass used to manage the state of the game board.
embedding_agent.py Contains the
EmbeddingAgentclass which receives a clue and makes guesses using the cosine similarity of word embeddings.
wordnet_agent.py Contains the
WordNetAgentclass which receives a clue and makes guesses using Wu-Palmer Similarity in the WordNet taxonomy.
dev.py Used for testing and debugging the agents.
The rules are a simplified version of the original Codenames rules found here. This game implements the two-player version of the game, where the player is always the spymaster and the computer agent is the field operative. Your goal is to reveal all the blue cards before all the red cards are revealed without ever revealing the grey card (the assassin). See the original rules for more details.
Each turn consists of two phases: the Clue Phase and the Red Reveal Phase.
During the Clue Phase, your goal is to provide a clue that groups together as many of the blue cards as possible, while excluding the others. The clue must be entered as a single word, a space, and a number specifiying how many words the clue applies to. For example, in this case we may want to try and target RULER, CHARGE and AZTEC with the clue of 'king'. As seen in the next phase, the agent correctly identified RULER as its first guess, but calculated a higher similarity for GRACE for its second guess. As soon as a non-blue card is revealed, the phase ends regardless of the number you gave.
In the next phase, you will simulate your opponent by choosing a red card to reveal (you may want to be strategic about your choice). To do this, simply type in the word of an unrevealed red word on the board. We may want to target TAP in the next round, so it might be reasonable to remove WATER from the board.
The game can end in one of three ways.
- You reveal the assassin (LOSE).
- All the red cards get revealed (LOSE).
- All the blue cards get revealed (WIN).
In the case that you win, your score is calculated as follows:
score = (number of unrevealed red cards) + 0.2 (number of unrevealed neutral cards)

