flatland.core.grid.grid8 module¶
-
class
flatland.core.grid.grid8.
Grid8Transitions
(transitions)[source]¶ Bases:
flatland.core.transitions.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_transition
(self, 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_transition : int
64 bits used to encode the valid transitions for a cell.
- orientation : int
Orientation of the agent inside the cell.
- direction : int
Direction of movement whose validity is to be tested.
Returns: - int
Validity of the requested transition: 0/1 allowed/not allowed.
-
get_transitions
(self, cell_transition, orientation)[source]¶ Get the 8 possible transitions.
Parameters: - cell_transition : int
64 bits used to encode the valid transitions for a cell.
- orientation : int
Orientation of the agent inside the cell.
Returns: - tuple
List of the validity of transitions in the cell.
-
rotate_transition
(self, 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_transition : int
64 bits used to encode the valid transitions for a cell.
- rotation : int
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
(self, 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_transition : int
64 bits used to encode the valid transitions for a cell.
- orientation : int
Orientation of the agent inside the cell.
- direction : int
Direction of movement whose validity is to be tested.
- new_transition : int
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
(self, cell_transition, orientation, new_transitions)[source]¶ Set the possible transitions.
Parameters: - cell_transition : int
64 bits used to encode the valid transitions for a cell.
- orientation : int
Orientation of the agent inside the cell.
- new_transitions : tuple
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.
-