Conway game of life, Next generation not printing well

ThisIsMi

I am working on Conway game of college problem. I have been able to print the first generation and the second but when it comes to the following ones they all copy the second generation. I was wondering if y'all can help me out.

public void computeNextGeneration(int generation)
{
    char[][] newBoard = new char[board.length][board[0].length];

    for(int i = 0; i < board.length; i++)
    {
        for(int j = 0; j < board[0].length; j++)
        {
            if(board[i][j] == '0' && numOfNeighbors(i,j) == 3)
            {
                newBoard[i][j] = 'X';
            }
            else if(board[i][j] == 'X' && numOfNeighbors(i,j) < 2)
            {
                newBoard[i][j] = '0';
            }
             else if(board[i][j] == 'X' && numOfNeighbors(i,j) >3)
            {
                newBoard[i][j] = '0';
            }
             else if(board[i][j] == 'X' && numOfNeighbors(i,j) == 2 || numOfNeighbors(i,j) == 3)
            {
                newBoard[i][j] = 'X'; //change x to 0
            }
             else{
                 newBoard[i][j] +=board[i][j];
             }
        }  
    }


        for (int i = 0; i < newBoard.length; i++)
        {
            for(int j = 0; j < newBoard[0].length; j++)
            {
                System.out.print(newBoard[i][j]);
            }
            System.out.println();
        }
}
RobP

After you calculate the new board you have to assign it back to the class field board. Add as the last line of computeNextGeneration board = newboard.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

C# Conway's Game Of Life

From Dev

Conway's Game of Life - beyond the grid

From Dev

Why in Conway's game of life the Gilder becomes the following? I just don't understand

From Dev

A very specific Conway's Game of Life (Ruby beginner)

From Dev

Why is my Conway's Game of Life acting strangely?

From Dev

John Conway's Game of Life - Basic implementation in C

From Dev

Python Conway's Game of Life

From Dev

Counting live neighbors in conway's game of life not working

From Dev

Conway's Game of Life Applying Rules of Life Issues Android

From Dev

Optimizing neighbor count function for conway's game of life in C

From Dev

Modelling Conway's game of life in integer linear programming?

From Dev

Counting neighboring cells for Conway's Game of Life in C++

From Dev

Conway's Game of Life New Values

From Dev

Copying List Error Python (part of Conway's Game of Life)

From Dev

Conway's Game Of Life In C

From Dev

ATBS Conway's Game of Life code doesnt seem right

From Dev

Drawing smooth lines to a grid [2D array] in Conway's Game of Life

From Dev

JAVA - Conway's Game of Life deletes all alive cells?

From Dev

building conway's game of life for iPad

From Dev

Why is my Conway's Game of Life acting strangely?

From Dev

Conway Game of Life - cells won't appear on canvas

From Dev

Counting live neighbors in conway's game of life not working

From Dev

Debugging Conway's Game of Life Graphics?

From Dev

Conway's Game of Life New Values

From Dev

Conway's game of life error

From Dev

Conway's game of life list index error

From Dev

What's wrong with my (Conway's Game Of) life?

From Dev

Python Conway's Game of Life not behaving properly for glider gun design

From Dev

Conway's Game of Life C++ Code check

Related Related

  1. 1

    C# Conway's Game Of Life

  2. 2

    Conway's Game of Life - beyond the grid

  3. 3

    Why in Conway's game of life the Gilder becomes the following? I just don't understand

  4. 4

    A very specific Conway's Game of Life (Ruby beginner)

  5. 5

    Why is my Conway's Game of Life acting strangely?

  6. 6

    John Conway's Game of Life - Basic implementation in C

  7. 7

    Python Conway's Game of Life

  8. 8

    Counting live neighbors in conway's game of life not working

  9. 9

    Conway's Game of Life Applying Rules of Life Issues Android

  10. 10

    Optimizing neighbor count function for conway's game of life in C

  11. 11

    Modelling Conway's game of life in integer linear programming?

  12. 12

    Counting neighboring cells for Conway's Game of Life in C++

  13. 13

    Conway's Game of Life New Values

  14. 14

    Copying List Error Python (part of Conway's Game of Life)

  15. 15

    Conway's Game Of Life In C

  16. 16

    ATBS Conway's Game of Life code doesnt seem right

  17. 17

    Drawing smooth lines to a grid [2D array] in Conway's Game of Life

  18. 18

    JAVA - Conway's Game of Life deletes all alive cells?

  19. 19

    building conway's game of life for iPad

  20. 20

    Why is my Conway's Game of Life acting strangely?

  21. 21

    Conway Game of Life - cells won't appear on canvas

  22. 22

    Counting live neighbors in conway's game of life not working

  23. 23

    Debugging Conway's Game of Life Graphics?

  24. 24

    Conway's Game of Life New Values

  25. 25

    Conway's game of life error

  26. 26

    Conway's game of life list index error

  27. 27

    What's wrong with my (Conway's Game Of) life?

  28. 28

    Python Conway's Game of Life not behaving properly for glider gun design

  29. 29

    Conway's Game of Life C++ Code check

HotTag

Archive