def direction(self, other): offset = (other.x - self.x, other.y - self.y) for d in direction_by_abr.values(): if d.offset == offset: return d raise ValueError(other)
def adjacent_tiles(self, tile): '''Return all adjacent tiles to this tile.''' adj = [ d.offset for d in direction_by_abr.values()] return [t for t in [self.get((tile.x + idx[0],tile.y + idx[1])) for idx in adj] if t]