Package: codenames
CodenamesCode infrastructure for the Codenames board game.Designed to serve as a base for implementing players (agents) with different strategies and algorithms.See thecodenames-solversrepository for such examples.InstallationInstall from PyPI using pip:pip install codenamesUsageHere is a simple example of command-line based players, and aGameRunnerthat runs a game between them:importloggingimportsysfromcodenames.boards.builderimportgenerate_boardfromcodenames.game.colorimportTeamColorfromcodenames.game.moveimportGuess,Hintfromcodenames.game.playerimportGuesser,Hinter,GamePlayersfromcodenames.game.runnerimportGameRunnerfromcodenames.game.stateimportGuesserGameState,HinterGameStatelogging.basicConfig(level=logging.INFO,format="%(message)s",stream=sys.stdout)# Implement basic playersclassCLIHinter(Hinter):defpick_hint(self,game_state:HinterGameState)->Hint:print("Board state:\n"+game_state.board.printable_string)hint_word=input("Enter hint word: ")card_amount=int(input("Enter card amount: "))returnHint(word=hint_word,card_amount=card_amount)classCLIGuesser(Guesser):defguess(self,game_state:GuesserGameState)->Guess:print(game_state.board.printable_string)card_word=input("Enter card word: ")card_index=game_state.board.find_card_index(word=card_word)returnGuess(card_index=card_index)# Run gamedefrun_cli_game():language="english"board=generate_board(language=language)blue_hinter,blue_guesser=CLIHinter("Yoda",TeamColor.BLUE),CLIGuesser("Luke",TeamColor.BLUE)red_hinter,red_guesser=CLIHinter("Einstein",TeamColor.RED),CLIGuesser("Newton",TeamColor.RED)players=GamePlayers.from_collection([blue_hinter,blue_guesser,red_hinter,red_guesser])runner=GameRunner(players=players,board=board)winner=runner.run_game()print(f"Winner:{winner}")if__name__=="__main__":run_cli_game()Example output:[Blue] turn.
Board state:
+------------+------------+--------------+-------------+-------------------+
|   ‎🟦 tax   |  ‎⬜ drama  |   ‎⬜ thick   |  ‎🟥 africa  | ‎💀 transformation |
+------------+------------+--------------+-------------+-------------------+
| ‎⬜ project | ‎🟦 athlete | ‎🟥 vegetable | ‎⬜ engineer |     ‎🟥 human      |
+------------+------------+--------------+-------------+-------------------+
|  ‎⬜ chain  |  ‎🟦 cake   |   ‎🟦 shift   |  ‎🟦 study   |      ‎🟥 will      |
+------------+------------+--------------+-------------+-------------------+
| ‎🟥 outcome |  ‎🟥 desk   |  ‎🟥 soviet   |   ‎⬜ rare   |     ‎🟥 youth      |
+------------+------------+--------------+-------------+-------------------+
| ‎🟦 account | ‎🟦 couple  |   ‎⬜ solve   | ‎🟦 academic |     ‎🟦 stable     |
+------------+------------+--------------+-------------+-------------------+
Enter hint word: example
Enter card amount: 2
Hinter: [example] 2 card(s)
+---------+---------+-----------+----------+----------------+
|   ‎tax   |  ‎drama  |   ‎thick   |  ‎africa  | ‎transformation |
+---------+---------+-----------+----------+----------------+
| ‎project | ‎athlete | ‎vegetable | ‎engineer |     ‎human      |
+---------+---------+-----------+----------+----------------+
|  ‎chain  |  ‎cake   |   ‎shift   |  ‎study   |      ‎will      |
+---------+---------+-----------+----------+----------------+
| ‎outcome |  ‎desk   |  ‎soviet   |   ‎rare   |     ‎youth      |
+---------+---------+-----------+----------+----------------+
| ‎account | ‎couple  |   ‎solve   | ‎academic |     ‎stable     |
+---------+---------+-----------+----------+----------------+
Enter card word: account
Guesser: '🟦 account', correct!
+------------+---------+-----------+----------+----------------+
|    ‎tax     |  ‎drama  |   ‎thick   |  ‎africa  | ‎transformation |
+------------+---------+-----------+----------+----------------+
|  ‎project   | ‎athlete | ‎vegetable | ‎engineer |     ‎human      |
+------------+---------+-----------+----------+----------------+
|   ‎chain    |  ‎cake   |   ‎shift   |  ‎study   |      ‎will      |
+------------+---------+-----------+----------+----------------+
|  ‎outcome   |  ‎desk   |  ‎soviet   |   ‎rare   |     ‎youth      |
+------------+---------+-----------+----------+----------------+
| ‎🟦 account | ‎couple  |   ‎solve   | ‎academic |     ‎stable     |
+------------+---------+-----------+----------+----------------+
Enter card word: rare
Guesser: '⬜ rare', wrong!
Guesser wrong, turn is over
...