Esempio n. 1
0
    def defender_between(self, normal, defenders):
        '''
        if there is a defender between self and normal, return 1; else return
        0. Between here is described above, but to reiterate: 
        1) take the vector of my position minus the normal position, 
        2) mangitudize this vector to be the radius, 
        3) scalar multiply the vector between self and normal by 1/n, n int
        4) go by intervals of 1/n along the vector, and check if a defender 
           lies in a circle about that point of radius defined above
        '''
        x_start = self.get_xpos()
        x_end = normal.get_xpos()
        y_start = self.get_ypos()
        y_end = normal.get_ypos()


        vector_reg = Vector(x_start - x_end, y_start - y_end)
        vector_norm = vector_reg.normalize()
        radius = vector_reg.magnitude() # radius
        n = 9 # division
        radius = radius / n
        # 3)
        while (vector_reg.magnitude() > radius):
            this_step = vector_norm * (radius/n)
            x_start = x_start - this_step.x()
            y_start = y_start - this_step.y()

            if self.defender_in_circle((x_start, y_start), radius, defenders):
                return 1
            vector_reg = Vector(x_start - x_end, y_start - y_end)

        return 0
Esempio n. 2
0
def defender_between(normal, zombie, defenders, fineness = 9):
    '''
    if there is a defender between self and normal, return 1; else return
    0. Between here is described above, but to reiterate: 
    1) take the vector of my position minus the normal position, 
    2) mangitudize this vector to be the radius, 
    3) scalar multiply the vector between self and normal by 1/n, n int
    4) go by intervals of 1/n along the vector, and check if a defender 
    lies in a circle about that point of radius defined above
    '''
    x_start = zombie.get_xpos()
    x_end = normal.get_xpos()
    y_start = zombie.get_ypos()
    y_end = normal.get_ypos()   
    
    vector_reg = Vector(x_start - x_end, y_start - y_end)
    
    vector_norm = vector_reg.normalize()
    radius = vector_reg.magnitude() 

    ##
    n = fineness
    # fineness; determines fineness of the line check; higher n for a higher
    # frequency of checks but a smaller circle about each point whereas lower
    # n means for faster but much-less-precise checks. If n is too low, for 
    # instance 2, this check determines whether there is a defender in a circle
    # of radius half the distance between the normal and zombie at the midpoint
    # of the line
    ##
    radius = radius / n
    while (vector_reg.magnitude() > radius):
        this_step = vector_norm * (radius/n)
        x_start = x_start - this_step.x()
        y_start = y_start - this_step.y()
        
        if circle_contains((x_start, y_start), radius, defenders):
            return 1
        vector_reg = Vector(x_start - x_end, y_start - y_end)
    return 0    
Esempio n. 3
0
 def can_get_between(self, normal, zombie):
     '''
     to determine if I can get between, drop a perpendicular line to the line
     formed by the normal and the zombie, and check whether the point of 
     intersection of these two lines is contained in the line segment 
     starting at the normal and ending at the zombie. Here's a picture!!
     ______________________________   _____________________________
     |                     N      |  |                            |
     |                     |      |  |         N--------Z--       |
     |                     |      |  |                    |       |
     |               D-----|      |  |                    |       |
     |                     |      |  |                    |       |
     |                     Z      |  |                    D       |
     |                            |  |                            |
     |                            |  |                            |
     ______________________________   _____________________________
            CAN intervene                    CAN'T intervene 
     '''
     line = Line((normal.get_xpos(), normal.get_ypos()), 
                 (zombie.get_xpos(), zombie.get_ypos()))
     my_position = (self.get_xpos(), self.get_ypos())
     
     return line.contains_perpendicular_from(my_position)