I'm doing the Game of Life by John Conway and I have been trying for such a long time to do this but it keeps giving me this error:
if matrix[i+1][j] == 1:
IndexError: list index out of range
I don't know what's wrong with it, normally m[i+1][j]
works for finding the specific position I'm asking for.
Unlike the other answers, I will assume that your question is about why you get this error in your GoL implementation and is not a question about what the error means.
You do not provide a lot of information about when the error occurs, but a common issue in implementing GoL is how to handle the boundaries. This is discussed in Wikipedia's GoL article. Most likely you get your error when you are trying to compute a neighborhood at the boundary. Here is one common solution. Extend your grid by one on each side (including top and bottom). Call the new cells "boundary cells"; use them to store the state of the "neighors" that would be there with a toroidal topology. Compute the next state only for the non-boundary cells; when you update their state, also update each boundary cell to the toroidally "wrapped" cell it represents.