Created
November 26, 2012 17:25
-
-
Save max-giro/4149507 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RandomWalkRobot(Robot): | |
""" | |
A RandomWalkRobot is a robot with the "random walk" movement strategy: it | |
chooses a new direction at random at the end of each time-step. | |
""" | |
def updatePositionAndClean(self): | |
""" | |
Simulate the raise passage of a single time-step. | |
Move the robot to a new position and mark the tile it is on as having | |
been cleaned. | |
""" | |
prev_pos = self.pos | |
self.setRobotPosition(self.getRobotPosition().getNewPosition(random.randrange(360), self.speed)) | |
if (self.room.isPositionInRoom(self.pos)): | |
self.room.cleanTileAtPosition(self.pos) | |
else: | |
self.pos = prev_pos | |
self.setRobotDirection(random.randrange(360)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment