|
@@ -1,24 +1,29 @@
|
|
|
import random
|
|
|
import warnings
|
|
|
|
|
|
-DIRECTIONS = ['N', 'E', 'S', 'W']
|
|
|
+HEADINGS = ['N', 'E', 'S', 'W']
|
|
|
|
|
|
class Location:
|
|
|
|
|
|
- def __init__(self, x, y, direction):
|
|
|
+ def __init__(self, x, y, heading):
|
|
|
self.x = x
|
|
|
self.y = y
|
|
|
- self.direction = direction
|
|
|
+ self.heading = heading
|
|
|
|
|
|
|
|
|
class Rover:
|
|
|
|
|
|
- def __init__(self, x=None, y=None, direction=None):
|
|
|
- if all((x, y, direction)):
|
|
|
- self.location = Location(x, y, direction)
|
|
|
+ def __init__(self, x=None, y=None, heading=None):
|
|
|
+ if all((x, y, heading)):
|
|
|
+ self.location = Location(x, y, heading)
|
|
|
else:
|
|
|
warnings.warn("Landing at a random place")
|
|
|
self.location = Location(random.randint(-10, 10),
|
|
|
random.randint(-10, 10),
|
|
|
- DIRECTIONS[random.randint(0,
|
|
|
- len(DIRECTIONS) - 1)])
|
|
|
+ HEADINGS[random.randint(0,
|
|
|
+ len(HEADINGS) - 1)])
|
|
|
+
|
|
|
+ def move(self, command):
|
|
|
+ for item in command:
|
|
|
+ if item == 'F' and self.location.heading == 'E':
|
|
|
+ self.location.x += 1
|