From 8475e5228e603e23f7682460d0ac60247a24198b Mon Sep 17 00:00:00 2001 From: Charles Peyrat Date: Fri, 8 Jan 2021 05:41:16 +0100 Subject: [PATCH] Large neighbourhood shouldn't return the central cell --- squirrelbattle/interfaces.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/squirrelbattle/interfaces.py b/squirrelbattle/interfaces.py index 2a08abc..4e5f9ff 100644 --- a/squirrelbattle/interfaces.py +++ b/squirrelbattle/interfaces.py @@ -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