-
Notifications
You must be signed in to change notification settings - Fork 37
/
StandardRobot Class.py
29 lines (29 loc) · 1.29 KB
/
StandardRobot Class.py
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
# Enter your code for Robot (from the previous problem)
# and StandardRobot in this box
class Robot(object):
def __init__(self, room, speed):
self.room = room
self.speed = speed
self.direction = random.randint(0,359)
self.position = room.getRandomPosition()
self.room.cleanTileAtPosition(self.position)
def getRobotPosition(self):
return self.position
def getRobotDirection(self):
return self.direction
def setRobotPosition(self, position):
self.position = position
def setRobotDirection(self, direction):
self.direction = direction
def updatePositionAndClean(self):
raise NotImplementedError # don't change this!
class StandardRobot(Robot):
def updatePositionAndClean(self):
pos = self.getRobotPosition()
newpos = pos.getNewPosition(self.getRobotDirection(), self.speed)
if self.room.isPositionInRoom(newpos):
self.setRobotPosition(newpos)
if not self.room.isTileCleaned(math.floor(newpos.getX()),math.floor(newpos.getY())):
self.room.cleanTileAtPosition(newpos)
else:
self.setRobotDirection(random.randint(0,359))