rover.py
1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class Rover(object):
"""
This Mars Rover should keep track of its current position, its heading, and
the size of the grid
"""
def __init__(self, start, route, boundaries):
b = boundaries.split()
self.boundaries = [[0, 0], [0, 0]]
# we may want to do some type checking and data format validation here
self.boundaries[1][0] = int(b[0])
self.boundaries[1][1] = int(b[1])
s = start.split()
# also, some type checking, and see if the coordinates fit in the
# boundaries
self.coordinates = [int(s[0]), int(s[1])]
# check if the provided heading actually exists
self.heading = s[2]
print self.coordinates, self.heading
# some convenient properties to access the boundaries lists
@property
def min_x(self):
return self.boundaries[0][0]
@property
def min_y(self):
return self.boundaries[0][1]
@property
def max_x(self):
return self.boundaries[1][0]
@property
def max_y(self):
return self.boundaries[1][1]