Codenames board game logic implementation in python.
Project description
Codenames
Code infrastructure for the Codenames board game.
Installation
pip install codenames
Usage
Here is a simple example of players implementation for CLI:
import logging
import sys
from codenames.boards.builder import generate_board
from codenames.game.move import Guess, Hint
from codenames.game.player import Guesser, Hinter
from codenames.game.runner import GameRunner
from codenames.game.state import GuesserGameState, HinterGameState
logging.basicConfig(level=logging.INFO, format="%(message)s", stream=sys.stdout)
# Implement basic players
class CLIHinter(Hinter):
def pick_hint(self, game_state: HinterGameState) -> Hint:
print(game_state.board.printable_string)
hint_word = input("Enter hint word: ")
card_amount = int(input("Enter card amount: "))
return Hint(word=hint_word, card_amount=card_amount)
class CLIGuesser(Guesser):
def guess(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)
return Guess(card_index=card_index)
# Run game
def run_cli_game():
language = "english"
board = generate_board(language=language)
red_hinter, red_guesser = CLIHinter(name="Einstein"), CLIGuesser(name="Newton")
blue_hinter, blue_guesser = CLIHinter(name="Yoda"), CLIGuesser(name="Luke")
runner = GameRunner(
blue_hinter=blue_hinter,
blue_guesser=blue_guesser,
red_hinter=red_hinter,
red_guesser=red_guesser,
)
runner.run_game(language=language, board=board)
if __name__ == "__main__":
run_cli_game()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
codenames-4.0.1.tar.gz
(26.7 kB
view details)
Built Distribution
codenames-4.0.1-py3-none-any.whl
(36.1 kB
view details)
File details
Details for the file codenames-4.0.1.tar.gz
.
File metadata
- Download URL: codenames-4.0.1.tar.gz
- Upload date:
- Size: 26.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd36b1b2feaec2605d3ccd73e2498f6d67e22d2c4ede23f834ad094badeaf78c |
|
MD5 | fe7ecf544b23b0a14517dd33e2b07e10 |
|
BLAKE2b-256 | fa7bba68d5d09fb5c23704697af8dbdfe7324810580b2843fa6cbc6eb85b6f03 |
File details
Details for the file codenames-4.0.1-py3-none-any.whl
.
File metadata
- Download URL: codenames-4.0.1-py3-none-any.whl
- Upload date:
- Size: 36.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc29e6dd6ad008fb9573d904b91f1087b51a4a8c3d5cb2edc064e204399aaf65 |
|
MD5 | f4aecc4a0c5ff1e9dac04cf1d7af2269 |
|
BLAKE2b-256 | d223e549c97bdaf25c87cbe318f239d0f90e9c680d5c41c783da7de38cedcdf3 |