Created
February 10, 2017 15:04
-
-
Save DexGroves/4e04e922be5078ba326f213d75f7cc74 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import numpy as np | |
from collections import deque | |
def dist_to(game_map, sources): | |
dist = np.empty_like(game_map.owners) | |
dist.fill(-1) | |
for sx, sy in sources: | |
dist[sx, sy] = 0 | |
ds = deque(sources) | |
while len(ds) > 0: | |
cx, cy = ds.popleft() | |
c_dist = dist[cx, cy] | |
for nx, ny in game_map.nbrs[cx, cy]: | |
if dist[nx, ny] == -1 or dist[nx, ny] > (c_dist + 1): | |
dist[nx, ny] = c_dist + 1 | |
ds.append((nx, ny)) | |
return dist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment