flatland.core.grid.grid8 module#

class flatland.core.grid.grid8.Grid8Transitions(transitions)[source]#

Bases: Transitions

Grid8Transitions class derived from Transitions.

Special case of Transitions over a 2D-grid (FlatLand). Transitions are possible to neighboring cells on the grid if allowed. GridTransitions keeps track of valid transitions supplied as transitions list, each represented as a bitmap of 64 bits.

0=North, 1=North-East, etc.

get_direction_enum() IntEnum[source]#
get_transition(cell_transition, orientation, direction)[source]#

Get the transition bit (1 value) that determines whether an agent oriented in direction orientation and inside a cell with transitions cell_transition’ can move to the cell in direction `direction relative to the current cell.

Parameters#

cell_transitionint

64 bits used to encode the valid transitions for a cell.

orientationint

Orientation of the agent inside the cell.

directionint

Direction of movement whose validity is to be tested.

Returns#

int

Validity of the requested transition: 0/1 allowed/not allowed.

get_transitions(cell_transition, orientation)[source]#

Get the 8 possible transitions.

Parameters#

cell_transitionint

64 bits used to encode the valid transitions for a cell.

orientationint

Orientation of the agent inside the cell.

Returns#

tuple

List of the validity of transitions in the cell.

get_type()[source]#
rotate_transition(cell_transition, rotation=0)[source]#

Clockwise-rotate a 64-bit transition bitmap by rotation={0, 45, 90, 135, 180, 225, 270, 315} degrees.

Parameters#

cell_transitionint

64 bits used to encode the valid transitions for a cell.

rotationint

Angle by which to clock-wise rotate the transition bits in cell_transition by. I.e., rotation={0, 45, 90, 135, 180, 225, 270, 315} degrees.

Returns#

int

An updated bitmap that replaces the original transitions bits with the equivalent bitmap after rotation.

set_transition(cell_transition, orientation, direction, new_transition, remove_deadends=False)[source]#

Set the transition bit (1 value) that determines whether an agent oriented in direction orientation and inside a cell with transitions cell_transition’ can move to the cell in direction `direction relative to the current cell.

Parameters#

cell_transitionint

64 bits used to encode the valid transitions for a cell.

orientationint

Orientation of the agent inside the cell.

directionint

Direction of movement whose validity is to be tested.

new_transitionint

Validity of the requested transition: 0/1 allowed/not allowed.

Returns#

int

An updated bitmap that replaces the original transitions validity of cell_transition’ with `new_transitions, for the appropriate orientation.

set_transitions(cell_transition, orientation, new_transitions)[source]#

Set the possible transitions.

Parameters#

cell_transitionint

64 bits used to encode the valid transitions for a cell.

orientationint

Orientation of the agent inside the cell.

new_transitionstuple

Tuple of new transitions validitiy for the cell.

Returns#

int

An updated bitmap that replaces the original transitions validity of cell_transition’ with `new_transitions, for the appropriate orientation.

class flatland.core.grid.grid8.Grid8TransitionsEnum(value)[source]#

Bases: IntEnum

An enumeration.

EAST = 2#
NORTH = 0#
NORTH_EAST = 1#
NORTH_WEST = 7#
SOUTH = 4#
SOUTH_EAST = 3#
SOUTH_WEST = 5#
WEST = 6#