Move the robot to a new position and mark the tile it is on as having been cleaned. """ newPos = self.pos.getNewPosition(self.direction, self.speed) newPos = Position(newPos.getX(),newPos.getY()) if self.room.isPositionInRoom(newPos): self.room.cleanTileAtPosition(newPos) self.pos = newPos self.setRobotDirection(self.getRobotDirection()) else: self.setRobotDirection(random.randrange(360)) self.updatePositionAndClean() # Uncomment this line to see your implementation of StandardRobot in action! testRobotMovement(StandardRobot, RectangularRoom) # === 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)
newPos = Position(saveWidth, saveHeight) self.setRobotPosition(newPos) self.room.cleanTileAtPosition(newPos) #print "Found new tile that was not clean! current direc. " + str(self.direction) #print "tile location x = " + str(saveWidth) + " y = " + str(saveHeight) keepTryingNewDirection = False else: keepTryingNewDirection = False #print "all tiles clean! stop cleaning!-- do not look for new direction! should be done." #for tile in tilesCleaned: #print tile # Uncomment this line to see your implementation of StandardRobot in action! testRobotMovement(StandardRobot, RectangularRoom) # === 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)
If you can move to a valid spot, do it. If you can't, change direction once. Return. you said you rewrite your code a lot. I suggest writing pseudo code first, understanding exactly what you are trying to accomplish, and then fill in the actual code. Save yourself some hassle. """ bub = self.position.getNewPosition(self.direction, self.speed) if self.room.isPositionInRoom(bub): self.room.cleanTileAtPosition(self.position) self.position = self.position.getNewPosition( self.direction, self.speed) else: #self.direction = random.randrange(0,359) self.direction = random.randrange(0, 359) # Uncomment this line to see your implementation of StandardRobot in action! testRobotMovement(RandomWalkRobot, RectangularRoom) # === 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)
""" bub = self.position.getNewPosition(self.direction,self.speed) if self.room.isPositionInRoom(bub): self.room.cleanTileAtPosition(self.position) self.position = self.position.getNewPosition(self.direction,self.speed) else: #self.direction = random.randrange(0,359) self.direction = random.randrange(0,359) # Uncomment this line to see your implementation of StandardRobot in action! testRobotMovement(RandomWalkRobot, RectangularRoom) # === 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)