CodenamesGPT

Codenames GPT is a simple word-guessing game based on the rules of Codenames Duet. The user plays cooperatively with the computer to guess the 15 hidden words on the game board. Some of the words on the board are colored black and loose instantly, and other words are neutral.

Screenshot

The project was created as a way to explore Next.js and to play with the OpenAI APIs.

Prompts

The guidance library was used in order to ensure the output is correctly structured. It is not supported by newer OpenAI models, so the demo no longer functions. The text-davinci-003 model is used.

In the demo, the model is also asked to explain it’s reasoning for giving any hints. This is not allowed in the regular game, but makes the demo more interesting.

There are two prompts, one for when the AI is the hint giver and one for when the AI is the hint receiver. The hint generation would exceed Vercel’s timeouts so the prompt is split into two calls. The output of one call is fed into the next so the LLM has more time to continue completing the response.

Hint Prompt

You are a clue-giver playing the game codenames. Choose a word which shares a specific concept with only three words chosen from the list below. The words chosen from this list are target words. The way the concept is related may be different for each target word. The chosen word should not relate to any of the non-target words. Any reasoning given should explain how the chosen word relates to the three target words, and should not mention any non-target words.

For example, the word state relates to the words California, Russia and emotional because California and Russia are political states and emotional is a state of mind. As another example, the word animal relates to the words lab and vet because a lab is a breed of dog and a vet is a doctor who treats animals.

The possible target words are: {~#each clueWords}

  • {this}{/each}

The chosen word absolutely must not relate to the following words: {~#each loseWords}

  • {this}{/each}

The chosen word must avoid relating to the following words: {~#each neutralWords}

  • {this}{/each}

Without making a decision, let’s quickly come up with five possibilities with ordinary, simple and well-known relations. The target words can come from anywhere in the list.

  • {gen "possibilities" temperature=0.8}

Without choosing, let’s give each possibility a rating for how ordinary, simple and well-known the relationship is. The best rated word will be chosen.

  • {gen "ratings" stop="\\n" temperature=0.5}
  • {gen "ratings" stop="\\n" temperature=0.5}
  • {gen "ratings" stop="\\n" temperature=0.5}
  • {gen "ratings" stop="\\n" temperature=0.5}
  • {gen "ratings" stop="\\n" temperature=0.5}

Chosen word: {gen "connecting word" stop="\\n" temperature=0.8} Target words: {#geneach "connected words" join=" and " num_iterations=3}{select "this" options=clueWords}{/geneach} Explanation: {~gen "reason" temperature=0.2}

Guess Prompt

You are a guesser playing the game codenames. Given a hint word, you must choose the most likely {count} target words from the list below.

For example, the hint word state relates to the words California, Russia and emotional because California and Russia are political states and emotional is a state of mind. As another example, the hint word animal relates to the words lab and vet because a lab is a breed of dog and a vet is a doctor who treats animals.

The possible target words are: {~#each words}

  • {this}{/each}

Given the hint word {hint}, the most likely target words are {#geneach "guess" join=" and " num_iterations=count}{select "this" options=words}{/geneach} because {~gen "reason" temperature=0.2}