Last active
November 20, 2016 10:14
-
-
Save smiley1983/0fdf1d80666071647f11501de5fe2915 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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