Skip to content

Instantly share code, notes, and snippets.

@max-giro
Created November 26, 2012 17:25
Show Gist options
  • Save max-giro/4149507 to your computer and use it in GitHub Desktop.
Save max-giro/4149507 to your computer and use it in GitHub Desktop.
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