Exemple #1
0
    def explore(self):
        start = time.time()
        while True:
            # Only update the UPDATED GRIDS, based on the sensor reading
            updatedGrids = self.robot.readSensors(self.completeMap)
            for n in updatedGrids:
                x, y = n[0], n[1]
                self.ui.drawGrid(x, y)

            # This checking must be done here because if not, there will be one extra ROBOT drawing (including one moveForward())
            # If the checking is done in ui.drawRobot(), the moveForward() cannot be prevented although the robot should have stopped already before moving forward
            if self.ui.checkTimeout() == False or self.ui.setMapPercentage() == False:
                break

            initialState = State(copy.deepcopy(self.robot))
            actions = Algorithm.A_star(initialState)

            for action in actions:
                r = self.robot.do(action)
                if r == False:
                    break

                self.ui.drawRobot()
                # Only update the UPDATED GRIDS, based on the sensor reading
                updatedGrids = self.robot.readSensors(self.completeMap)
                for n in updatedGrids:
                    x, y = n[0], n[1]
                    self.ui.drawGrid(x, y)

        end = time.time()
        print("RUNNING TIME:", end - start)