Large neighbourhood shouldn't return the central cell

This commit is contained in:
Charles Peyrat 2021-01-08 05:41:16 +01:00
parent 20cbf546f9
commit 8475e5228e

View File

@ -202,9 +202,13 @@ class Map:
"""
height, width = len(grid), len(grid[0])
neighbours = []
dyxs = product([-1, 0, 1], [-1, 0, 1]) if large else [[0, -1], [0, 1], [-1, 0], [1, 0]]
if large:
dyxs = product([-1, 0, 1], [-1, 0, 1])
dyxs = dyxs[:5] + dyxs[6:]
else:
dyxs = [[0, -1], [0, 1], [-1, 0], [1, 0]]
for dy, dx in dyxs:
if 0 < y+dy < height and 0 < x+dx < width:
if 0 <= y+dy < height and 0 <= x+dx < width:
neighbours.append([y+dy, x+dx])
return neighbours