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.

all_defeated() bool
Returns:

True if all characters are defeated.

all_elems() set[Element]
Returns:

the set of elements its characters belongs to.

char_id_valid(char_id: int) bool
Returns:

True if the char_id is legal.

contains(char: Character | type[Character]) bool
Returns:

True if char can be found.

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_active_character() None | Character
Returns:

the active character.

get_active_character_id() None | int
Returns:

the active character’s id.

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_alive_characters() tuple[Character, ...]
Returns:

the alive characters (from left to right)

get_by_id(id: int) None | Character

Same as .get_character().

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_characters() tuple[Character, ...]
Returns:

the tuple of characters.

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.

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.

just_get_character(id: int) Character
Returns:

character with id. An exception is thrown if id is not found.

num_characters() int
Returns:

the number of character.