class Compass(Enum):
NORTH = (0, 'N')
WEST = (1, 'W')
SOUTH = (2, 'S')
EAST = (3, 'E')
def __init__(self, id, shortname):
self.id = id
self.shortname = shortname
@staticmethod
def tovalue():
return list(map(lambda c: c.value, Compass))
@staticmethod
def tolist():
return list(map(lambda c: c.shortname, Compass))
@staticmethod
def toint():
return list(map(lambda c: c.id, Compass))
def succ(self):
int_list = Compass.toint()
max_int = max(int_list)
min_int = min(int_list)
v = self.id +1
if v > max_int:
v = self.id = min_int
for thing in self.tovalue():
if v in thing:
return thing
class Rover:
def __init__(self, x: int, y: int, compass):
self.x = x
self.y = y
self.compass = compass
for thing in Compass.tovalue():
if self.compass in thing:
self.compass = Compass(thing)
compass_pairs = Compass.tovalue()
def left(self):
new_compass = Compass((self.compass.succ()))
self.compass = new_compass
a = Rover(1,2,'N')
print(a.compass)
a.left()
print(a.compass)
a.left()
print(a.compass)
a.left()
print(a.compass)
a.left()
print(a.compass)
a.left()
print(a.compass)
a.left()
print(a.compass)
a.left()
print(a.compass)
a.left()
print(a.compass)
So basically I create a rover here and turn it left So 4 turns naturally bring you back to the starting direction Which is North in this case The code works for the first 4 turns But the next cycle it fucks up for some reason
Compass.NORTH
Compass.WEST
Compass.SOUTH
Compass.EAST
Compass.NORTH
Compass.WEST
Compass.SOUTH
Compass.NORTH
Compass.WEST
this is the result of the prints The first north is not a turn its the staring position So it should've been South to east but its south to north