-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
260 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import logging | ||
import random | ||
|
||
from codenames.game.color import TeamColor | ||
from codenames.game.exceptions import QuitGame | ||
from codenames.game.player import GamePlayers | ||
from codenames.game.runner import GameRunner | ||
from codenames.online.codenames_game.runner import CodenamesGameRunner | ||
|
||
from playground.boards.english import * # noqa | ||
from playground.boards.hebrew import * # noqa | ||
from playground.printer import print_results | ||
from solvers.cheater.cheaters import CheaterGuesser, CheaterHinter | ||
|
||
random.seed(42) | ||
log = logging.getLogger(__name__) | ||
|
||
|
||
def get_cheaters() -> GamePlayers: | ||
blue_hinter = CheaterHinter(name="Yoda", team_color=TeamColor.BLUE) | ||
red_hinter = CheaterHinter(name="Einstein", team_color=TeamColor.RED) | ||
blue_guesser = CheaterGuesser(name="Anakin", team_color=TeamColor.BLUE, hinter=blue_hinter) | ||
red_guesser = CheaterGuesser(name="Newton", team_color=TeamColor.RED, hinter=red_hinter) | ||
return GamePlayers.from_collection([blue_hinter, blue_guesser, red_hinter, red_guesser]) | ||
|
||
|
||
def run_offline(board: Board = ENGLISH_BOARDS[2]): # noqa | ||
log.info("Running cheaters game...") | ||
log.setLevel(logging.INFO) | ||
game_runner = None | ||
try: | ||
players = get_cheaters() | ||
game_runner = GameRunner(players=players, board=board) | ||
game_runner.run_game() | ||
except QuitGame: | ||
log.info("Game quit") | ||
except: # noqa | ||
log.exception("Error occurred") | ||
finally: | ||
print_results(game_runner) # type: ignore | ||
|
||
|
||
def run_online(): | ||
log.info("Running online game...") | ||
online_manager = runner = None | ||
try: | ||
players = get_cheaters() | ||
online_manager = CodenamesGameRunner(*players.hinters, *players.guessers, show_host=True) | ||
runner = online_manager.auto_start() | ||
except QuitGame: | ||
log.info("Game quit") | ||
except: # noqa | ||
log.exception("Error occurred") | ||
finally: | ||
print_results(runner) | ||
online_manager.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
run_online() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.