Skip to content

Commit

Permalink
Update GPT hint verification.
Browse files Browse the repository at this point in the history
  • Loading branch information
asaf-kali committed Sep 28, 2023
1 parent 1ec869b commit b5d899d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[tool.poetry]
name = "codenames-solvers"
version = "1.4.8"
version = "1.4.9"
description = "Solvers implementation for Codenames board game in python."
authors = ["Asaf Kali <[email protected]>"]
readme = "README.md"
Expand Down
30 changes: 19 additions & 11 deletions solvers/gpt/gpt_hinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,26 @@ def pick_hint(self, game_state: HinterGameState) -> Hint:
return hint

def _verify_hint(self, hint: Hint, game_state: HinterGameState):
good_hint = True
for word in hint.for_words:
try:
card = game_state.board[word]
except KeyError:
log.warning(f"Hint {hint} is referring to a word that is not on the board: {word}")
continue
if card.revealed:
log.warning(f"Hint {hint} is referring to a word that is already revealed: {word}")
continue
if card.color != self.team_color.as_card_color:
log.warning(f"Hint {hint} is referring to a word that is not of the team's color: {word}")
continue
if not self._card_valid_for_hinting(hint=hint, game_state=game_state, word=word):
good_hint = False
if good_hint:
log.info(f"Hint {hint} is valid")

def _card_valid_for_hinting(self, hint: Hint, game_state: HinterGameState, word: str) -> bool:
try:
card = game_state.board[word]
except KeyError:
log.warning(f"Hint {hint} is referring to a word that is not on the board: {word}")
return False
if card.revealed:
log.warning(f"Hint {hint} is referring to a word that is already revealed: {word}")
return False
if card.color != self.team_color.as_card_color:
log.warning(f"Hint {hint} is referring to a word that is not of the team's color: {word}")
return False
return True

@classmethod
def build_board_repr(cls, board: Board) -> str:
Expand Down

0 comments on commit b5d899d

Please sign in to comment.