Advertisement
Archius11

Untitled

Apr 8th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. sides = ['N', 'NW', 'SW', 'S', 'SE', 'NE']
  2.  
  3.  
  4. class HexaDot:
  5.     def __init__(self, coord_string):
  6.         x = ord(coord_string[0]) - 65
  7.         z = (int(coord_string[1:])) - (x - (x % 2)) // 2
  8.         y = -x - z
  9.         self.x, self.y, self.z = x, y, z
  10.  
  11.     def distance_to(self, dot2):
  12.         return max(abs(self.x - dot2.x), abs(self.y - dot2.y), abs(self.z - dot2.z))
  13.  
  14.     def rotate_by_60(self, axes_dot, nums):
  15.         x, y, z = self.x-axes_dot.x, self.y-axes_dot.y, self.z-axes_dot.z
  16.         for i in range(nums):
  17.             x, y, z = -z, -x, -y
  18.         self.x, self.y, self.z = x+axes_dot.x, y+axes_dot.y, z+axes_dot.z
  19.  
  20.     def get_side_of_dot(self, dot):
  21.         x, y, z = dot.x - self.x, dot.y - self.y, dot.z - self.z
  22.         if y > 0 and z < 0: return 'F'
  23.         if y < 0 and z > 0: return 'B'
  24.         if y >= 0 and z >= 0: return 'L'
  25.         if y <= 0 and z <= 0: return 'R'
  26.  
  27.  
  28. def find_enemy(you, dir, enemy):
  29.     dot1, dot2 = HexaDot(you), HexaDot(enemy)
  30.     dot2.rotate_by_60(dot1, sides.index(dir))
  31.     side = dot1.get_side_of_dot(dot2)
  32.     dist = dot1.distance_to(dot2)
  33.     return [side, dist]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement