-
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
15 changed files
with
306 additions
and
33 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,72 @@ | ||
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 | ||
from solvers.cli import CLIGuesser # noqa | ||
from solvers.models import ( # noqa | ||
DEFAULT_MODEL_ADAPTER, | ||
HEBREW_SUFFIX_ADAPTER, | ||
IS_STEMMED_ENV_KEY, | ||
MODEL_NAME_ENV_KEY, | ||
ModelIdentifier, | ||
load_language_async, | ||
load_model_async, | ||
) | ||
from solvers.naive import NaiveGuesser, NaiveHinter # noqa | ||
from solvers.other.naive_cli_guesser import ModelAwareCliGuesser # noqa | ||
|
||
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: F405 | ||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Empty file.
Oops, something went wrong.