nathanael-fijalkow commited on
Commit
e268213
·
1 Parent(s): b3ea7f0

Exposes number of guesses for the guesser

Browse files
Files changed (2) hide show
  1. codenames/challenge_runner.py +6 -3
  2. my_guesser.py +4 -3
codenames/challenge_runner.py CHANGED
@@ -18,8 +18,9 @@ def play_challenge(
18
  Play a challenge game with LLM spymaster and student guesser code.
19
 
20
  The guesser_fn should have signature:
21
- guesser_fn(clue: str, board_state: list[str]) -> Optional[str]
22
- where board_state is a list of unrevealed word strings.
 
23
  """
24
  game = ChallengeGame(dictionary=dictionary, seed=seed)
25
  master = MasterPlayer(dictionary, model_name=model_name)
@@ -57,13 +58,15 @@ def play_challenge(
57
  while not game.won and not game.lost and game.clue_word is not None:
58
  unrevealed = [c.word for c in game.board.cards if not c.revealed]
59
  try:
60
- guess_word = guesser_fn(game.clue_word, unrevealed)
61
  except Exception as e:
62
  if verbose:
63
  print(f"Guesser error: {e}")
 
64
  break
65
 
66
  if guess_word is None:
 
67
  break
68
 
69
  role, msg = game.guess(guess_word)
 
18
  Play a challenge game with LLM spymaster and student guesser code.
19
 
20
  The guesser_fn should have signature:
21
+ guesser_fn(clue: str, board_state: list[str], number: int) -> Optional[str]
22
+ where board_state is a list of unrevealed word strings and number is the
23
+ spymaster's clue number (max guesses = number + 1).
24
  """
25
  game = ChallengeGame(dictionary=dictionary, seed=seed)
26
  master = MasterPlayer(dictionary, model_name=model_name)
 
58
  while not game.won and not game.lost and game.clue_word is not None:
59
  unrevealed = [c.word for c in game.board.cards if not c.revealed]
60
  try:
61
+ guess_word = guesser_fn(game.clue_word, unrevealed, game.clue_number)
62
  except Exception as e:
63
  if verbose:
64
  print(f"Guesser error: {e}")
65
+ game.end_round()
66
  break
67
 
68
  if guess_word is None:
69
+ game.end_round()
70
  break
71
 
72
  role, msg = game.guess(guess_word)
my_guesser.py CHANGED
@@ -9,9 +9,10 @@ _dictionary = load_dictionary()
9
  _index = EmbeddingIndex(_dictionary)
10
 
11
 
12
- def guesser(clue: str, board_state: list[str]) -> Optional[str]:
13
  """
14
- Given a clue word and list of unrevealed board words,
15
- return a word.
 
16
  """
17
  return board_state[0]
 
9
  _index = EmbeddingIndex(_dictionary)
10
 
11
 
12
+ def guesser(clue: str, board_state: list[str], number: int) -> Optional[str]:
13
  """
14
+ Given a clue word, list of unrevealed board words, and the spymaster's
15
+ number, return a word to guess, or None to stop guessing.
16
+ You can make up to (number + 1) guesses per round.
17
  """
18
  return board_state[0]