Skip to main content
edited title
Link

my attempt at Conway's game of life attemptalgorithm does not work

deleted 50 characters in body
Source Link
Kromster
  • 10.7k
  • 4
  • 54
  • 67

the getNeighborsgetNeighbors and isOutOfBoundsisOutOfBounds function works fine as far as my tests go but for some reason the game never works as intended and i did the rules according to this:

Any live cell with two or three live neighbours survives.
Any dead cell with three live neighbours becomes a live cell.
All other live cells die in the next generation. Similarly, all other dead cells stay dead.
  • Any live cell with two or three live neighbours survives.
  • Any dead cell with three live neighbours becomes a live cell.
  • All other live cells die in the next generation. Similarly, all other dead cells stay dead.

this is the advance()advance() function of my game of life attempt:

the game is initially at this state:   

enter image description here

advancement 1:   

enter image description here

another example:   

enter image description here

advancement 1:   

enter image description here

advancement 2: enter image description here

apologies for such long post, any help would be appreciatedenter image description here

the getNeighbors and isOutOfBounds function works fine as far as my tests go but for some reason the game never works as intended and i did the rules according to this:

Any live cell with two or three live neighbours survives.
Any dead cell with three live neighbours becomes a live cell.
All other live cells die in the next generation. Similarly, all other dead cells stay dead.

this is the advance() function of my game of life attempt:

the game is initially at this state:  enter image description here

advancement 1:  enter image description here

another example:  enter image description here

advancement 1:  enter image description here

advancement 2: enter image description here

apologies for such long post, any help would be appreciated

the getNeighbors and isOutOfBounds function works fine as far as my tests go but for some reason the game never works as intended and i did the rules according to this:

  • Any live cell with two or three live neighbours survives.
  • Any dead cell with three live neighbours becomes a live cell.
  • All other live cells die in the next generation. Similarly, all other dead cells stay dead.

this is the advance() function of my game of life attempt:

the game is initially at this state: 

enter image description here

advancement 1: 

enter image description here

another example: 

enter image description here

advancement 1: 

enter image description here

advancement 2:

enter image description here

Source Link

my attempt at Conway's game of life attempt does not work

the getNeighbors and isOutOfBounds function works fine as far as my tests go but for some reason the game never works as intended and i did the rules according to this:

Any live cell with two or three live neighbours survives.
Any dead cell with three live neighbours becomes a live cell.
All other live cells die in the next generation. Similarly, all other dead cells stay dead.

this is the advance() function of my game of life attempt:

var grid : MutableList<MutableList<Boolean>> // initialised in the constructor
    fun advance()
    {
        var iter = grid.iterator()
        var toSet = MutableList(grid.size)  { i-> iter.next()}
        var dieAmount = 0
        var reviveAmount = 0
        for( col in 0 until grid.size)
        {
            for( row in 0 until grid[0].size )
            {
                var neighbors = getNeighborCount(grid, col, row)



                if(!(neighbors == 2 || neighbors == 3))
                {
                    toSet[col][row] = false
                    dieAmount++
                }
                 if(neighbors == 3 && !grid[col][row])
                {
                    toSet[col][row] = true
                    reviveAmount++
                }
                else
                    toSet[col][row] = false

            }

        }
        //println("dieAmount: $dieAmount surviveAmount: $reviveAmount")
        grid = toSet
    }

and my functions:

    fun getNeighborCount(grid: MutableList<MutableList<Boolean>>, column:Int, row:Int) : Int
    {
        var toReturn = 0
        for(minorColumn in -1..1)
            for(minorRow in -1..1)
                if(!isOverBounds(grid,column + minorColumn, row +minorRow) &&  !(minorColumn == 0 && minorRow == 0))
                {
                    if(grid[column+minorColumn][row + minorRow])
                    {
                        toReturn++
                    }
                }
        return toReturn
    }


    fun <T> isOverBounds(args: MutableList<MutableList<T>>, colCheck: Int, rowCheck: Int) : Boolean
    {
        if(args.size < colCheck+1 ||colCheck < 0) return true
        if(args[0].size<rowCheck+1||rowCheck < 0) return true
        return false
    }

the game is initially at this state: enter image description here

advancement 1: enter image description here

and the sole cell disappears in the second

another example: enter image description here

advancement 1: enter image description here

advancement 2: enter image description here

apologies for such long post, any help would be appreciated