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