예제 #1
0
파일: ps6.py 프로젝트: dtbinh/Sharkat
    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.
        """

        self.robotPosition = Position.getNewPosition(self.robotPosition, Robot.getRobotDirection(self), self.speed) #make the robot get a new position

        
        while RectangularRoom.isPositionInRoom(self.room, self.robotPosition) == False: #ensures that the new robot position is inside the room
            direction = Robot.getRobotDirection(self) #if the new position is not inside the room, make the robot go back to where it started and pick a new random direction
            direction = direction + 180
            if direction > 360:
                direction = direction = direction-360

            self.robotPosition = Position.getNewPosition(self.robotPosition, direction, self.speed)

            direction = random.randrange(0,360)
            self.robotDirection = direction 
            self.robotPosition = Position.getNewPosition(self.robotPosition, self.robotDirection, self.speed)


        RectangularRoom.cleanTileAtPosition(self.room, self.robotPosition)
예제 #2
0
파일: ps6.py 프로젝트: dtbinh/Sharkat
    def setRobotPosition(self, position):
        """
        Set the position of the robot to POSITION.

        position: a Position object.
        """

        posW = Position.getX(position)
        posH = Position.getY(position)

        self.robotPosition = Position(posW,posH)
예제 #3
0
파일: ps6.py 프로젝트: dtbinh/Sharkat
        def checkpos(robotPosition): #checks to see if new position is in the room, if not in the room, it moves robot back to original position and re-calculates a new position until the new position is inside the room
            while RectangularRoom.isPositionInRoom(self.room, self.robotPosition) == False:
                direction = Robot.getRobotDirection(self)
                direction = direction + 180
                if direction > 360:
                    direction = direction = direction-360
                self.robotPosition = Position.getNewPosition(self.robotPosition, direction, self.speed)

                direction = random.randrange(0,360) #calculates a new random direction, once robot hits a wall and moves back to original location
                self.robotDirection = direction 
                self.robotPosition = Position.getNewPosition(self.robotPosition, self.robotDirection, self.speed)
예제 #4
0
    def isPositionInRoom(self, pos):
        """
        Return True if pos is inside the room.

        pos: a Position object.
        returns: True if pos is in the room, False otherwise.
        """
        w = Position.getX(pos)
        h = Position.getY(pos)

        if w < self.width and h < self.height and w >= 0 and h >= 0:
            return True
        else:
            return False
예제 #5
0
    def cleanTileAtPosition(self, pos):
        """
        Mark the tile under the position POS as cleaned.

        Assumes that POS represents a valid position inside this room.

        pos: a Position
        """

        w = Position.getX(pos)  #shorter notation = pos.getX()
        h = Position.getY(pos)

        w = math.floor(w)
        h = math.floor(h)

        self.room[(w, h)] = 'clean'
예제 #6
0
    def getRandomPosition(self):
        """
        Return a random position inside the room.

        returns: a Position object.
        """
        w = random.uniform(
            0, self.width)  #returns a random position, with decimal points
        h = random.uniform(0, self.height)

        return Position(w, h)
예제 #7
0
파일: ps6.py 프로젝트: dtbinh/Sharkat
    def updatePosition(self):
        """ update the position for the duck without cleaning the room """
        self.robotPosition = Position.getNewPosition(self.robotPosition, \
            Robot.getRobotDirection(self), self.speed) 

        while RectangularRoom.isPositionInRoom(\
            self.room, self.robotPosition) == False:
            direction = Robot.getRobotDirection(self)
            direction = direction + 180

            if direction > 360:
                direction = direction = direction-360

            self.robotPosition = Position.getNewPosition(\
                self.robotPosition, direction, self.speed)

            direction = random.randrange(0, 360)
            self.robotDirection = direction 

            self.robotPosition = Position.getNewPosition(\
                self.robotPosition, self.robotDirection, self.speed)
예제 #8
0
파일: ps6.py 프로젝트: dtbinh/Sharkat
    def updatePositionAndClean(self):
        """
        Simulate the passage of a single time-step.

        Move the robot to a new position and mark the tile it is on as having
        been cleaned.
        """

        def checkpos(robotPosition): #checks to see if new position is in the room, if not in the room, it moves robot back to original position and re-calculates a new position until the new position is inside the room
            while RectangularRoom.isPositionInRoom(self.room, self.robotPosition) == False:
                direction = Robot.getRobotDirection(self)
                direction = direction + 180
                if direction > 360:
                    direction = direction = direction-360
                self.robotPosition = Position.getNewPosition(self.robotPosition, direction, self.speed)

                direction = random.randrange(0,360) #calculates a new random direction, once robot hits a wall and moves back to original location
                self.robotDirection = direction 
                self.robotPosition = Position.getNewPosition(self.robotPosition, self.robotDirection, self.speed)

        if self.time_step%2 == 0: # on time steps 0, 2, 4, 6...
            self.robotPosition = Position.getNewPosition(self.robotPosition, Robot.getRobotDirection(self), self.speed)
            
            checkpos(self.robotPosition)
            
            RectangularRoom.cleanTileAtPosition(self.room, self.robotPosition)

        else: #on time steps 1, 2, 3... after this one, the robot will randomly change directions (regardless of whether it hit a wall)
            self.robotPosition = Position.getNewPosition(self.robotPosition, Robot.getRobotDirection(self), self.speed)
           
            checkpos(self.robotPosition)
           

            RectangularRoom.cleanTileAtPosition(self.room, self.robotPosition)

            direction = random.randrange(0,360) #calculates a new random direction
            self.robotDirection = direction
            

        self.time_step = self.time_step+1