[python] distance func

Viewer

copydownloadembedprintName: distance func
  1. def find_opponent_unit_distance(unit):
  2.     attack_range = unit.data.get('attack_range')
  3.  
  4.     for opponent in unit.battalion.target.units:
  5.         position_delta = (unit.position[0] - opponent.position[0], unit.position[1] - opponent.position[1])
  6.         distance = numpy.linalg.norm(position_delta)
  7.  
  8.         if distance < 92:
  9.             if opponent.opponents is None:
  10.                 return opponent
  11.     else:
  12.         return None

Editor

You can edit this paste and save as new:


File Description
  • distance func
  • Paste Code
  • 23 May-2022
  • 441 Bytes
You can Share it: