Characters
from dgisim import Characters
__eq__ and __hash__ are implemented so that any two Characters with the
equivalent content are equal to each other and have the same hash.
- class Characters(characters: tuple[Character, ...], active_character_id: None | int)
A class for holding characters.
It always assumes n characters are numbered from 1 to n from left to right.
- factory() CharactersFactory
- Returns:
a factory for the current game state.
- find_first_character(char_type: type[Character]) None | Character
- Returns:
the first character (from left to right) that is of char_type.
- classmethod from_default(characters: tuple[Character, ...]) Characters
Same as Characters(characters, None).
- classmethod from_iterable(characters: Iterable[type[Character]]) Characters
- Returns:
characters with auto-assigned ids. (1 to n from left to right), active_character_id is None.
- get_alive_character_in_activity_order() tuple[Character, ...]
- Returns:
the ordered tuple of alive characters based on their activity.
Same as .get_character_in_activity_order() but filters out defeated characters.
- get_alive_character_in_activity_order_last_active() tuple[Character, ...]
- Returns:
the ordered tuple of alive characters based on their activity.
Same as .get_alive_character_in_activity_order() but the active character is ranked the last.
- get_character(id: int) None | Character
- Returns:
character with id. None is returned if id is not found.
- get_character_in_activity_order() tuple[Character, ...]
- Returns:
the ordered tuple of characters based on their activity.
The order is starting from the active character, count from left to right. If among characters (1, 2, 3), 2 is the active character, (2, 3, 1) is returned.
- get_character_ordered_from_id(char_id: int) tuple[Character, ...]
- Returns:
the ordered characters starting from char_id. (left to right)
- get_chars_in_order(ordered: bool = False, from_id: None | int = None, active: bool = False, non_active: bool = False, alive: bool = False) tuple[Character, ...]
- Parameters:
ordered – if True, characters are ordered based on their activity.
from_id – if not None, characters are ordered starting from from_id.
active – if True, only the active character is returned.
non_active – if True, only the non-active characters are returned.
alive – if True, only the alive characters are returned.
- Retruns:
characters satisfying the conditions.
- get_id(character: Character) None | int
- Returns:
the id of the character.
The exact same characer object needs to be in the characters.
- get_none_active_characters() tuple[Character, ...]
- Returns:
the none active characters (from left to right)
- get_nth_next_alive_character_in_activity_order(n: int) Character
- Returns:
the nth alive character after the active one.
- get_nth_prev_alive_character_in_activity_order(n: int) Character
- Returns:
the nth alive character before the active one.
- get_required_chars(activity_order: bool = False, alive: bool = False, non_active: bool = False) tuple[Character, ...]
- Parameters:
activity_order – characters needs to be in activity order.
alive – characters needs to be alive.
non_active – characters needs to be non-active.
- Returns:
characters as required by parameters.
- just_get_active_character() Character
- Returns:
the active character. If there is not one, an exception is thrown.
- just_get_active_character_id() int
- Returns:
the active character’s id. If the id is None, an exception is thrown.