Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sides = ['N', 'NW', 'SW', 'S', 'SE', 'NE']
- class HexaDot:
- def __init__(self, coord_string):
- x = ord(coord_string[0]) - 65
- z = (int(coord_string[1:])) - (x - (x % 2)) // 2
- y = -x - z
- self.x, self.y, self.z = x, y, z
- def distance_to(self, dot2):
- return max(abs(self.x - dot2.x), abs(self.y - dot2.y), abs(self.z - dot2.z))
- def rotate_by_60(self, axes_dot, nums):
- x, y, z = self.x-axes_dot.x, self.y-axes_dot.y, self.z-axes_dot.z
- for i in range(nums):
- x, y, z = -z, -x, -y
- self.x, self.y, self.z = x+axes_dot.x, y+axes_dot.y, z+axes_dot.z
- def get_side_of_dot(self, dot):
- x, y, z = dot.x - self.x, dot.y - self.y, dot.z - self.z
- if y > 0 and z < 0: return 'F'
- if y < 0 and z > 0: return 'B'
- if y >= 0 and z >= 0: return 'L'
- if y <= 0 and z <= 0: return 'R'
- def find_enemy(you, dir, enemy):
- dot1, dot2 = HexaDot(you), HexaDot(enemy)
- dot2.rotate_by_60(dot1, sides.index(dir))
- side = dot1.get_side_of_dot(dot2)
- dist = dot1.distance_to(dot2)
- return [side, dist]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement