Esempio n. 1
0
    def canAshootB(self, tank1Id, tank2Id):
        tank1 = self.tanks[tank1Id]
        tank2 = self.tanks[tank2Id]

        ## Check if in range
        distance = mathHelper.distanceBetween(tank1["position"], tank2["position"])
        if distance > PROJECTILE_RANGE + tank2["hitRadius"]:
            return False

        ## Check that we are pointing at it
        angle = mathHelper.angleFromAToB(tank1["position"], tank2["position"])
        offset = math.asin(tank2["hitRadius"] / distance)
        if not mathHelper.angleInRange(tank1["turret"], angle + offset, angle - offset):
            return False

        ## get the end point for tank1's range
        endPoint = mathHelper.getLineEndpoint(tank1["position"], distance, tank1["turret"])

        # Don't want to check if other tanks are blocking because they could move
        ##        ## Check that no other tanks are in the way
        ##        for tank in self.tanks:
        ##            ## Don't consider the original 2 tanks
        ##            if (tank['id'] == tank1Id or tank['id'] == tank2Id):
        ##                continue
        ##            if (mathHelper.circleOnLine(tank1['position'], endPoint, tank['position'], tank['hitRadius'])):
        ##                return False

        ## Ensure path is clear of solids
        if self.isShotClear(tank1["position"], endPoint):
            return True

        return False
Esempio n. 2
0
    def canAshootB(self, tank1Id, tank2Id):
        tank1 = self.tanks[tank1Id]
        tank2 = self.tanks[tank2Id]

        ## Check if in range
        distance = mathHelper.distanceBetween(tank1['position'], tank2['position'])
        if (distance > PROJECTILE_RANGE + tank2['hitRadius']):
            return False

        ## Check that we are pointing at it
        angle = mathHelper.angleFromAToB(tank1['position'], tank2['position'])
        offset = math.asin(tank2['hitRadius']/distance)
        if (not mathHelper.angleInRange(tank1['turret'], angle + offset, angle - offset)):
            return False

        ## get the end point for tank1's range
        endPoint = mathHelper.getLineEndpoint(tank1['position'], distance, tank1['turret'])

# Don't want to check if other tanks are blocking because they could move
##        ## Check that no other tanks are in the way
##        for tank in self.tanks:
##            ## Don't consider the original 2 tanks
##            if (tank['id'] == tank1Id or tank['id'] == tank2Id):
##                continue
##            if (mathHelper.circleOnLine(tank1['position'], endPoint, tank['position'], tank['hitRadius'])):
##                return False

        ## Ensure path is clear of solids
        if self.isShotClear(tank1['position'], endPoint):
            return True

        return False
Esempio n. 3
0
def angleInRange():
    ## Should return true
    if (not mathHelper.angleInRange(2, 3, 1) == True):
        raise Exception('Failed angleInRange')
    if (not mathHelper.angleInRange(1, 2, -1) == True):
        raise Exception('Failed angleInRange')
    if (not mathHelper.angleInRange(6, 1, -1) == True):
        raise Exception('Failed angleInRange')
    if (not mathHelper.angleInRange(1, 8, 6) == True):
        raise Exception('Failed angleInRange')
    if (not mathHelper.angleInRange(6, 8, 5) == True):
        raise Exception('Failed angleInRange')

    ## Should return false
    if (not mathHelper.angleInRange(4, 3, 1) == False):
        raise Exception('Failed angleInRange')
    if (not mathHelper.angleInRange(4, 2, -1) == False):
        raise Exception('Failed angleInRange')
    if (not mathHelper.angleInRange(4, 8, 5) == False):
        raise Exception('Failed angleInRange')
Esempio n. 4
0
def angleInRange():
    ## Should return true
    if (not mathHelper.angleInRange(2, 3, 1) == True):
        raise Exception('Failed angleInRange')
    if (not mathHelper.angleInRange(1, 2, -1) == True):
        raise Exception('Failed angleInRange')
    if (not mathHelper.angleInRange(6, 1, -1) == True):
        raise Exception('Failed angleInRange')
    if (not mathHelper.angleInRange(1, 8, 6) == True):
        raise Exception('Failed angleInRange')
    if (not mathHelper.angleInRange(6, 8, 5) == True):
        raise Exception('Failed angleInRange')

    ## Should return false
    if (not mathHelper.angleInRange(4, 3, 1) == False):
        raise Exception('Failed angleInRange')
    if (not mathHelper.angleInRange(4, 2, -1) == False):
        raise Exception('Failed angleInRange')
    if (not mathHelper.angleInRange(4, 8, 5) == False):
        raise Exception('Failed angleInRange')