Skip to content

Arena

Represents the physical play space containing all card zones of all players.

Warning

In technicality the Comprehensive Rules document defines the arena to be the "collection of all the arms, chest, combat chain, head, hero, legs, permanent, and weapon zones", and that the "arsenal, banished, deck, graveyard, hand, pitch, and stack zones are not part of the arena". However for convenience, this library bundles all zones into a single object. When reading cards or evaluating game rules, it is important to keep this distinction in mind.

Attributes:

Name Type Description
combat_chain CombatChain

The global combat chain.

player_spaces dict[str, PlayerSpace]

A dict of player spaces, organized by an arbitrary name.

Source code in fab/arena.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
@dataclasses.dataclass
class Arena:
    '''
    Represents the physical play space containing all card zones of all players.

    Tip: Warning
      In technicality the _Comprehensive Rules_ document defines the arena to be
      the "collection of all the arms, chest, combat chain, head, hero, legs,
      permanent, and weapon zones", and that the "arsenal, banished, deck,
      graveyard, hand, pitch, and stack zones are not part of the arena".
      However for convenience, this library bundles all zones into a single
      object. When reading cards or evaluating game rules, it is important to
      keep this distinction in mind.

    Attributes:
      combat_chain: The global combat chain.
      player_spaces: A `dict` of player spaces, organized by an arbitrary name.
    '''
    combat_chain: CombatChain = CombatChain.empty()
    player_spaces: dict[str, PlayerSpace] = dataclasses.field(default_factory=dict)

    def add_player_space(self, name: str, space: Optional[PlayerSpace] = None) -> None:
        '''
        Adds the specified player's space to the arena.

        Args:
          name: The arbitrary name string of the player to add.
          space: An optional player space instance to assign to the player, creating a new blank one if `None`.
        '''
        if not name in self.player_spaces:
            self.player_spaces[name] = space if not space is None else PlayerSpace()
        else:
            raise Exception(f'player "{name}" already exists in the arena')

    def remove_player_space(self, name: str) -> PlayerSpace:
        '''
        Removes the specified player space, by name.

        Args:
          name: The name of the player space to remove.

        Returns:
          A reference to the `PlayerSpace` object that was removed.
        '''
        if name in self.player_spaces:
            return self.player_spaces.pop(name)
        else:
            raise Exception(f'specified player space "{name}" does not exist')

    def reset_combat_chain(self) -> None:
        '''
        Resets (empties) the global combat chain.
        '''
        self.combat_chain = CombatChain.empty()

    def reset_player_spaces(self) -> None:
        '''
        Resets the player spaces to their original configuration.

        This method calls the `.reset_zones()` method on each player space. See
        that method for more details.
        '''
        for s in self.player_spaces.values():
            s.reset_zones()

add_player_space(name, space=None)

Adds the specified player's space to the arena.

Parameters:

Name Type Description Default
name str

The arbitrary name string of the player to add.

required
space Optional[PlayerSpace]

An optional player space instance to assign to the player, creating a new blank one if None.

None
Source code in fab/arena.py
38
39
40
41
42
43
44
45
46
47
48
49
def add_player_space(self, name: str, space: Optional[PlayerSpace] = None) -> None:
    '''
    Adds the specified player's space to the arena.

    Args:
      name: The arbitrary name string of the player to add.
      space: An optional player space instance to assign to the player, creating a new blank one if `None`.
    '''
    if not name in self.player_spaces:
        self.player_spaces[name] = space if not space is None else PlayerSpace()
    else:
        raise Exception(f'player "{name}" already exists in the arena')

remove_player_space(name)

Removes the specified player space, by name.

Parameters:

Name Type Description Default
name str

The name of the player space to remove.

required

Returns:

Type Description
PlayerSpace

A reference to the PlayerSpace object that was removed.

Source code in fab/arena.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def remove_player_space(self, name: str) -> PlayerSpace:
    '''
    Removes the specified player space, by name.

    Args:
      name: The name of the player space to remove.

    Returns:
      A reference to the `PlayerSpace` object that was removed.
    '''
    if name in self.player_spaces:
        return self.player_spaces.pop(name)
    else:
        raise Exception(f'specified player space "{name}" does not exist')

reset_combat_chain()

Resets (empties) the global combat chain.

Source code in fab/arena.py
66
67
68
69
70
def reset_combat_chain(self) -> None:
    '''
    Resets (empties) the global combat chain.
    '''
    self.combat_chain = CombatChain.empty()

reset_player_spaces()

Resets the player spaces to their original configuration.

This method calls the .reset_zones() method on each player space. See that method for more details.

Source code in fab/arena.py
72
73
74
75
76
77
78
79
80
def reset_player_spaces(self) -> None:
    '''
    Resets the player spaces to their original configuration.

    This method calls the `.reset_zones()` method on each player space. See
    that method for more details.
    '''
    for s in self.player_spaces.values():
        s.reset_zones()