Skip to content

Instantly share code, notes, and snippets.

@mooreniemi
Created November 26, 2012 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mooreniemi/4146168 to your computer and use it in GitHub Desktop.
Save mooreniemi/4146168 to your computer and use it in GitHub Desktop.
600x
# === Problem 3
def runSimulation(num_robots, speed, width, height, min_coverage, num_trials,
robot_type):
"""
Runs NUM_TRIALS trials of the simulation and returns the mean number of
time-steps needed to clean the fraction MIN_COVERAGE of the room.
The simulation is run with NUM_ROBOTS robots of type ROBOT_TYPE, each with
speed SPEED, in a room of dimensions WIDTH x HEIGHT.
num_robots: an int (num_robots > 0)
speed: a float (speed > 0)
width: an int (width > 0)
height: an int (height > 0)
min_coverage: a float (0 <= min_coverage <= 1.0)
num_trials: an int (num_trials > 0)
robot_type: class of robot to be instantiated (e.g. StandardRobot or
RandomWalkRobot)
"""
timeCount = 0.0
robotlist=[]
for trials in range(num_trials):
room = RectangularRoom(width,height)
coverage = (min_coverage * room.getNumTiles())
robotlist.append(robot_type(room,speed))
while coverage > room.getNumCleanedTiles():
timeCount = timeCount + 1
for robot in robotlist:
robot.updatePositionAndClean()
return timeCount / num_trials
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment