flatland.core.grid.grid4_utils module#

flatland.core.grid.grid4_utils.direction_to_point(pos1: Tuple[int, int], pos2: Tuple[int, int]) Grid4TransitionsEnum[source]#

Returns the closest direction orientation of position 2 relative to position 1 :param pos1: position we are interested in :param pos2: position we want to know it is facing :return: direction NESW as int N:0 E:1 S:2 W:3

flatland.core.grid.grid4_utils.find_connected_cells(grid_map: GridTransitionMap, open_set: Set[Tuple[int, int]], forbidden_cells: Set[Tuple[int, int]] = None) Set[Tuple[int, int]][source]#

Flood-fill from a set of starting cells (open set) to find all cells connected to them in the grid via valid transitions, without passing through forbidden_cells.

Parameters#

grid_mapGridTransitionMap

Grid Map to search in.

open_setSet[IntVector2D]

Starting cells (row,column) to search from. Always included in the result, even if also listed in forbidden_cells.

forbidden_cellsOptional[Set[IntVector2D]]

Set of cells the search must not pass through. Used to avoid certain areas of the Grid map.

Returns#

Set[IntVector2D]

Set of all cells (row,column) connected to the open set via valid transitions, excluding any forbidden_cells other than the starting cells themselves.

flatland.core.grid.grid4_utils.get_direction(pos1: Tuple[int, int], pos2: Tuple[int, int]) Grid4TransitionsEnum[source]#

Assumes pos1 and pos2 are adjacent location on grid. Returns direction (int) that can be used with transitions.

flatland.core.grid.grid4_utils.get_new_position(position, movement)[source]#

Get new (r,c) when exiting in direction movement.

flatland.core.grid.grid4_utils.get_old_position(position, movement)[source]#

Get old (r,c) when entering in direction movement.

flatland.core.grid.grid4_utils.is_neighbor_cell(pos1: Tuple[int, int], pos2: Tuple[int, int]) bool[source]#

Check whether pos1 and pos2 are adjacent to each other, top/bottom or left/right, no diagonal.

flatland.core.grid.grid4_utils.mirror(dir)[source]#