Play

play_game(teams, *, game=None, round_codes=None, round_limit=None)

Play a game of Decrypto. This function will change the game object as the rounds are played.

Parameters:
  • teams (Sequence[Team]) –

    The pair of teams participating in the game.

  • game (Game) –

    The Decrypto game object. If None, a standard game will be generated.

  • round_codes (Iterable[Sequence[Code]]) –

    Iterable of codes for each round. If None, random codes will be generated.

  • round_limit (Optional[int]) –

    The maximum number of rounds to play. If None, the game continues until completion.

Returns:
  • Game( Game ) –

    The game state after play.

/home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/play.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def play_game(teams: Sequence[Team], *, 
              game: Game = None, 
              round_codes: Iterable[Sequence[Code]] = None, 
              round_limit: Optional[int]=None
              ) -> Game:
    """Play a game of Decrypto. This function will change the game object as the rounds are played.

    Args:
        teams (Sequence[Team]): The pair of teams participating in the game.
        game (Game): The Decrypto game object. If None, a standard game will be generated.
        round_codes (Iterable[Sequence[Code]], optional): Iterable of codes for each round. If None, random codes will be generated.
        round_limit (Optional[int], optional): The maximum number of rounds to play. If None, the game continues until completion.

    Returns:
            Game: The game state after play.
    """
    game = game if game is not None else Game()
    round_codes = round_codes if round_codes is not None else RandomCodes([team.keywords for team in teams])
    for rounds_played, codes in enumerate(round_codes):
        if game.game_over() or rounds_played == round_limit:
            break
        play_round(teams, game, codes)
    return game

play_round(teams, game, codes)

Play a single round of Decrypto. The game object will be updated with the round results.

Parameters:
  • teams (Sequence[Team]) –

    The pair of teams participating in the game.

  • game (Game) –

    The Decrypto game object which encodes the current state.

  • codes (Sequence[Code]) –

    The codes for the current round.

/home/docs/checkouts/readthedocs.org/user_builds/decryptogame/envs/latest/lib/python3.10/site-packages/decryptogame/play.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def play_round(teams:Sequence[Team], game: Game, codes: Sequence[Code]):
    """Play a single round of Decrypto. The game object will be updated with the round results.

    Args:
        teams (Sequence[Team]): The pair of teams participating in the game.
        game (Game): The Decrypto game object which encodes the current state.
        codes (Sequence[Code]): The codes for the current round.
    """
    # each member may need information about its team and the game to make proper decisions
    context = [TeamContext(
                team_name=team_name, 
                keywords=team.keywords, 
                num_opponent_keywords=len(teams[not team_name].keywords),
                game=game
                )
                for team_name, team in enumerate(teams)]

    # each team's encryptor decides the clues
    clues = {}
    for team_name, code in enumerate(codes): 
        team = teams[team_name]
        # give the encryptor the context of its team and the current game state
        clues[team_name] = team.encryptor.decide_clues(code, context[team_name])

    # each team attempts to intercept the opposing team's code
    attempted_interception = {}
    for team_name, code in enumerate(codes):
        team = teams[team_name]
        # give the intercepter the context of its team and the current game state
        opponent = not team_name
        attempted_interception[team_name] = team.intercepter.intercept_clues(clues[opponent], context[team_name])

    # each team attempts to decipher the clues to their code
    attempted_decipher = {}
    for team_name, code in enumerate(codes):
        team = teams[team_name]
        # give the guesser the context of its team and the current game state
        attempted_decipher[team_name] = team.guesser.decipher_clues(clues[team_name], context[team_name])

    # each team reveals their codes and the notes are processed and added to the notesheet
    notes = [Note(clues=clues[team_name],
                  attempted_interception=attempted_interception[team_name],
                  attempted_decipher=attempted_decipher[team_name],
                  correct_code=code
                  ) 
                  for team_name, code in enumerate(codes)]
    game.process_round_notes(notes)