Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
hexed coordinates solution in Clear category for Find Enemy by Stensen
DIR = lambda x, y: {
'N' : ( -x, -y),
'NE': ( y, -x-y),
'SE': ( x+y, -x),
'S' : ( x, y),
'SW': ( -y, x+y),
'NW': (-x-y, x)}
def find_enemy(you, dir, enemy):
_hex = lambda p: (int(p[1]) - (ord(p[0]) - 65) // 2 - 1, ord(p[0]) - 65)
(i1, j1), (i2, j2) = _hex(you), _hex(enemy)
x, y, = i2 - i1, j2 - j1
dist = max(abs(x), abs(y), abs(x + y))
x, y = DIR(x, y)[dir]
if y > 0 and -y <= x <= 0: rdir = 'L'
elif y < 0 and 0 <= x <= - y: rdir = 'R'
elif x > 0: rdir = 'F'
else: rdir = 'B'
return [rdir, dist]
Oct. 10, 2020
Comments: