vefcrown.blogg.se

Cant get conways game of life working python
Cant get conways game of life working python











This happens above, below, to the right, and to the left of the cell. However, this condition fails whenever either of the offset variables, r and c, are zero.

#Cant get conways game of life working python code#

You used this code to exclude the cell itself: if r != 0 and c != 0 You made code to check the surrounding cells (the for loops shown above), and you knew that you needed exempt the cell itself from being tested. So, you need to change if board = "X" to if board = "X". Essentially, you are just checking the top few spaces of the grid. However, you never add the offsets to the original values. You start to setup code to handle the offsets here: for r in range(-1, 2):

  • You need to do a deepcopy of the board.
  • You need to include the surrounding cells when checking the neighbors, not just the cells that are diagonal from the center cell.
  • cant get conways game of life working python

    You need to include the offset when checking neighbor cells.I will explain these in more detail below: I found three mistakes, and there might be more. If board = " ": # dead cellĮlif board = "X": # live cellīoard = for row in range(0, HEIGHT)]

    cant get conways game of life working python

    Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. Any live cell with more than three live neighbours dies, as if by overcrowding. Any live cell with two or three live neighbours lives on to the next generation. Any live cell with less than two live neighbours dies, as if caused by under-population. I do not know in which area the code gremlin lives so I just posted the whole code below. What it should do is this: # (O = dead cell, X = live cell) My current code does something like this: # ("O" = dead cell, "X" = live cell) If it was working correctly, it would oscillate from 3 live cells in a row to 3 live cells in a column, but it does not do that.

    cant get conways game of life working python

    So I did, but it doesn't work as it should.įor example, I have 3 live cells in a row horizontally. I recently came across John Conway's Game of Life and decided to code it in Python.











    Cant get conways game of life working python