From 3a8549cfcc867f5216a0dcfbcf5efb454bede17c Mon Sep 17 00:00:00 2001 From: Charles Peyrat Date: Fri, 11 Dec 2020 17:09:27 +0100 Subject: [PATCH] Added a method to interfaces.Map to get the neighbours of a given tile --- squirrelbattle/interfaces.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/squirrelbattle/interfaces.py b/squirrelbattle/interfaces.py index 3567ea0..50ebb2e 100644 --- a/squirrelbattle/interfaces.py +++ b/squirrelbattle/interfaces.py @@ -5,6 +5,7 @@ from enum import Enum, auto from math import sqrt from random import choice, randint from typing import List, Optional +from itertools import product from .display.texturepack import TexturePack from .translations import gettext as _ @@ -180,6 +181,13 @@ class Map: for entisave in d["entities"]: self.add_entity(dictclasses[entisave["type"]](**entisave)) + def large_neighbourhood(self, y, x): + neighbours = [] + for dy, dx in product([-1, 0, 1], [-1, 0, 1]): + if 0 < y+dy < self.height and 0 < x+dx < self.width: + neighbours.append([y+dy, x+dx]) + return neighbours + class Tile(Enum): """