Move Functions
Move functions for lazy iteration of user-defined coordinates.
All of the functions in this module work with a user-defined class
that implements one of the abstract base classes from pygrates.abc.
The functions take one instance of said user-defined class as their
first input, along with an optional filter function, and return an
iterator with coordinates in a specific direction.
- pygrates.moves.adjacent(coords: GC, guard: Callable[[GC], bool] | None = None) Iterator[GC][source]
Iterate adjacent coordinates.
- Parameters:
coords (GC) – Generic coordinate object. Instance of a class that implements
pygrates.abc.GCoords.guard (Callable[[GC], bool], optional) – Callable from the passed coordinate type to a boolean.
- Returns:
Iterator containing coordinate objects adjacent to the input coordinate. Usable once only.
- Return type:
Iterator[GC]
- pygrates.moves.children(coords: DGC, guard: Callable[[DGC], bool] | None = None) Iterator[DGC][source]
Iterate child coordinates.
- Parameters:
coords (DGC) – Generic coordinate object. Instance of a class that implements
pygrates.abc.DGCoords.guard (Callable[[DGC], bool], optional) – Callable from the passed coordinate type to a boolean.
- Returns:
Iterator containing coordinate objects that are children of the input coordinate. Usable once only.
- Return type:
Iterator[DGC]
- pygrates.moves.parents(coords: DGC, guard: Callable[[DGC], bool] | None = None) Iterator[DGC][source]
Iterate parent coordinates.
- Parameters:
coords (DGC) – Generic coordinate object. Instance of a class that implements
pygrates.abc.DGCoords.guard (Callable[[DGC], bool], optional) – Callable from the passed coordinate type to a boolean.
- Returns:
Iterator containing coordinate objects that are parents of the input coordinate. Usable once only.
- Return type:
Iterator[DGC]
- pygrates.moves.neighborhood(coords: GC, depth: int = 1, guard: Callable[[GC], bool] | None = None) Iterable[GC][source]
Iterate neighboring coordinates to given depth.
- Parameters:
coords (GC) – Generic coordinate object. Instance of a class that implements
pygrates.abc.GCoords.depth (int, default=1) – Maximum depth of iteration.
guard (Callable[[GC], bool], optional) – Callable from the passed coordinate type to a boolean.
- Returns:
Iterator containing coordinate objects from the neighborhood of the input coordinate. Usable once only.
- Return type:
Iterator[GC]
- pygrates.moves.descendants(coords: DGC, depth: int = 1, guard: Callable[[DGC], bool] | None = None) Iterator[DGC][source]
Iterate descendant coordinates to given depth.
- Parameters:
coords (DGC) – Generic coordinate object. Instance of a class that implements
pygrates.abc.DGCoords.depth (int, default=1) – Maximum depth of iteration.
guard (Callable[[DGC], bool], optional) – Callable from the passed coordinate type to a boolean.
- Returns:
Iterator containing coordinate objects that are descendants of the input coordinate. Usable once only.
- Return type:
Iterator[DGC]
- pygrates.moves.ancestors(coords: DGC, depth: int = 1, guard: Callable[[DGC], bool] | None = None) Iterator[DGC][source]
Iterate ancestor coordinates to given depth.
- Parameters:
coords (DGC) – Generic coordinate object. Instance of a class that implements
pygrates.abc.DGCoords.depth (int, default=1) – Maximum depth of iteration.
guard (Callable[[DGC], bool], optional) – Callable from the passed coordinate type to a boolean.
- Returns:
Iterator containing coordinate objects that are ancestors of the input coordinate. Usable once only.
- Return type:
Iterator[DGC]
- pygrates.moves.explore(coords: GC, direction: Callable[[GC, Callable[[GC], bool] | None], Iterable[GC]], depth: int = 1, guard: Callable[[GC], bool] | None = None) Generator[GC, None, None][source]
Iterate coordinates in given direction to given depth.
- Parameters:
coords (GC) – Generic coordinate object. Instance of a class that implements
pygrates.abc.GCoords.depth (int, default=1) – Maximum depth of iteration.
direction (Callable[[GC, Guard | None], Iterable[GC]]) – One of the functions
adjacent,children,parents, or a custom callable from the passed coordinate type and filter function to an iterator containing coordinate objects.guard (Callable[[GC], bool], optional) – Callable from the passed coordinate type to a boolean.
- Returns:
Iterator containing coordinate objects in the given direction from the input coordinate. Usable once only.
- Return type:
Iterator[GC]