A cyclic direction class to make rotations easier.

class Direction[source]

Direction(directions=['NORTH', 'EAST', 'SOUTH', 'WEST'], idx=None)

A cyclic direction class to make rotation easier.

The directions are written in a specific order of North, East, South, West instead of North, South, East, West to make rotation simpler.

To rotate the direction clockwise, this class simply updates the idx to idx+1. To rotate the direction clockwise, this class simply updates the idx to idx-1.

Returns: An instance of itself with the updated direction on calling either left or right.

d = Direction(idx=0)
#currently facing north
assert d.get_idx()==0
assert repr(d.f) == "'NORTH'"
#calling left changes idx to 3 and str representation to 'WEST'
assert d.left().get_idx()==3
assert repr(d.left().f) == "'WEST'"
#can do multiple lefts or left and right combination
assert d.left().left().get_idx()==2
assert d.left().right().get_idx()==0
from nbdev.export import * 
notebook2script()
Converted 01_direction.ipynb.
Converted 02_robot.ipynb.
Converted 03_main.ipynb.
Converted 04_tests.ipynb.
Converted index.ipynb.