Skip to content

Instantly share code, notes, and snippets.

@smiley1983
Last active November 20, 2016 10:14
Show Gist options
  • Save smiley1983/0fdf1d80666071647f11501de5fe2915 to your computer and use it in GitHub Desktop.
Save smiley1983/0fdf1d80666071647f11501de5fe2915 to your computer and use it in GitHub Desktop.
def cardinal_distance_to_edge(loc, direction, limit):
if limit > 0:
next_step = gameMap.getLocation(loc, direction)
site = gameMap.getSite(next_step)
if next_step.owner == myID:
return 1 + cardinal_distance_to_edge (next_step, direction, limit - 1)
else: return 1
else:
return 1
def shortest_cardinal_to_edge(loc):
shortest_dir = 0
shortest_dist = 100000
for cardinal in CARDINALS:
distance = cardinal_distance_to_edge(loc, cardinal, max(gameMap.width, gameMap.height))
if distance < shortest_dist:
shortest_dist = distance
shortest_dir = cardinal
return shortest_dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment