Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First - Cubic coordinates solution in Clear category for Find Enemy by carel.anthonissen
def find_enemy(you, dir, enemy):
# Convert to axial coordinates
start = [ord(you[0]),int(you[1])-(ord(you[0])+ord(you[0])%2)/2]
end = [ord(enemy[0]),int(enemy[1])-(ord(enemy[0])+ord(enemy[0])%2)/2]
# Calculate the displacement vector
dv = [end[i]-start[i] for i in range(2)]
# Convert to cube coordinates
dv.append(-dv[0]-dv[1])
# Calculate the length of the displacement vector (the distance)
t_dist = max(abs(dv[0]),abs(dv[1]),abs(dv[2]))
# Rotate the displacement vector to reflect the bearing
rot = {'N':0, 'NW':1, 'SW':2, 'S':3, 'SE':4, 'NE':5}
rdv = [(-(rot[dir]%2)*2+1)*dv[(i+rot[dir])%3] for i in range(3)]
# Determine the relative direction
rdir = 'F'
left_right = rdv[0]-rdv[1]-rdv[2]
up_down = (rdv[2]-rdv[1])*2
if abs(left_right) >= abs(up_down):
if left_right > 0:
rdir = 'R'
else:
rdir = 'L'
else:
if up_down < 0:
rdir = 'B'
return [rdir, t_dist]
April 24, 2018