I have this program trying to add up the number of grid spaces around it of a certain value, and it keep giving the error "IndexError: list out of range". I've tried setting it to start on column and row late and end one column and row early to the same effect. The error points at [x+1][y+1] specifically.
for l in range(loops):
for x in range(self.width):
for y in range(self.height):
neighbors = 0
if tiles_copy[x-1][y-1] == 1:
neighbors += 1
if tiles_copy[x][y-1] == 1:
neighbors += 1
if tiles_copy[x+1][y-1] == 1:
neighbors += 1
if tiles_copy[x+1][y] == 1:
neighbors += 1
if tiles_copy[x+1][y+1] == 1:
neighbors += 1
if tiles_copy[x][y+1] == 1:
neighbors += 1
if tiles_copy[x-1][y+1] == 1:
neighbors += 1
if tiles_copy[x-1][y] == 1:
neighbors += 1
Not an answer
Can you change the start of your loop to
len(tiles_copy) should be equal to self.width and the 3 values in the loop should be equal to self.height. At a guess, some of the values are less.