Aldous Broder
Module: terminaltexteffects.utils.spanningtree.algo.aldousbroder
Aldous-Broder spanning tree generator.
This module provides the AldousBroder spanning tree generator.
The algorithm performs a random walk over the terminal character graph, linking each newly encountered character to the current tree. The walk continues until every reachable terminal character has been linked.
AldousBroder
Bases: SpanningTreeGenerator
Aldous-Broder spanning tree generator.
The generator starts from a provided character or from a random character resolved from a random canvas coordinate. It then performs a random walk across neighboring characters, linking only characters that have not yet been linked into the tree.
Attributes:
| Name | Type | Description |
|---|---|---|
char_last_linked |
EffectCharacter | None
|
Character most recently linked into the tree.
During initialization this is the starting character. On later steps it is |
char_link_order |
list[EffectCharacter]
|
Characters in the order they were linked into the tree, beginning with the starting character. |
linked_char_last_visited |
EffectCharacter | None
|
Character most recently visited without creating a new link. During initialization this is the starting character. On later steps it is set only when the random walk moves to a character that already has at least one link. |
complete |
bool
|
Whether the algorithm is complete. |
Source code in terminaltexteffects/utils/spanningtree/algo/aldousbroder.py
__init__(terminal, starting_char=None)
Initialize the algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
terminal
|
Terminal
|
TTE Terminal. |
required |
starting_char
|
EffectCharacter | None
|
Starting character for the random
walk. When |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
No starting character could be resolved. |
Source code in terminaltexteffects/utils/spanningtree/algo/aldousbroder.py
step()
Advance the random walk by one neighboring character.
If the chosen neighbor is not yet linked, it is linked to the current
character and recorded in char_link_order. Otherwise,
linked_char_last_visited records the already-linked character that
was visited.
Note
If all characters have already been linked, this method sets
complete to True and returns immediately without advancing
the walk.