Beispiel #1
0
 def haveClearShotOfTarget(self,
                           target):
     owner = self.owner
     fleet = owner.fleet
     turretPosition = self.getPosition()
     targetPosition = target.getPosition()
     turretToTarget = calculate.subtractPoints(targetPosition,
                                               turretPosition)
     distanceSquaredToTarget = vector.getMagnitudeSquared(turretToTarget)
     headingToTarget = vector.normalize(turretToTarget)
     for friendlyShip in fleet.getAllShips():
         friendPosition = friendlyShip.getPosition()
         turretToFriend = calculate.subtractPoints(friendPosition,
                                                   turretPosition)
         distanceSquaredToFriend = vector.getMagnitudeSquared(turretToFriend)
         if distanceSquaredToFriend > distanceSquaredToTarget:
             continue
         
         headingToFriend = vector.normalize(turretToFriend)
         dotProductOfFriendAndTarget = calculate.dotProduct(headingToTarget,
                                                            headingToFriend)
         if calculate.withinTolerance(dotProductOfFriendAndTarget,
                                      1,
                                      self.clearShotTolerance):
             return False
     
     return True
Beispiel #2
0
 def test_toleranceIsZero_aboveTolerance(self):
     tolerance = 0
     value = 1
     threshold = .9
     withinTolerance = calculate.withinTolerance(value,
                                                 threshold,
                                                 tolerance)
     self.assertFalse(withinTolerance)
Beispiel #3
0
 def test_toleranceIsZero_belowTolerance(self):
     tolerance = 0
     value = .9
     threshold = 1
     withinTolerance = calculate.withinTolerance(value,
                                                 threshold,
                                                 tolerance)
     self.assertFalse(withinTolerance)
Beispiel #4
0
 def test_toleranceIsZero_withinTolerance(self):
     tolerance = 0
     value = 1
     threshold = 1
     withinTolerance = calculate.withinTolerance(value,
                                                 threshold,
                                                 tolerance)
     self.assertTrue(withinTolerance)