Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
7-liner: based on tom-tom's solution in Creative category for Find Enemy by przemyslaw.daniel
def find_enemy(you, adir, enemy):
to_hex = lambda p: (int(p[1])-(ord(p[0])-65)//2-1, ord(p[0])-65)
x, y = [b-a for a, b in zip(to_hex(you), to_hex(enemy))]
p, q = {'N': (-x,-y), 'NE': (y, -x-y), 'SE': (x+y,-x),
'S': (x,y), 'SW': (-y, x+y), 'NW': (-x-y,x)}[adir]
rdir = 'L'*(q>0)*(-q<=p<=0)+'R'*(q<0)*(0<=p<=-q)+'F'*(p>0)+'B'
return rdir[0], max(abs(x), abs(y), abs(x+y))
Oct. 4, 2017
Comments: