/media/sda-magnetic/david/Dok-15-2023-11-27/Dokumente-15-appended-2023-10-11/append-temporarly/GameOfLife.java


public class GameOfLife {
  boolean[][] feld = {
      { false, false, false, false, false },
      { false, false, true, false, false },
      { false, false, true, false, false },
      { false, false, true, false, false },
      { false, false, false, false, false } };

  void print() {
    for (int i = 0; i < feld.length; i++) {
      for (int j = 0; j < feld[i].length; j++) {
        if (feld[i][j]) {
          System.out.print("o ");
        } else {
          System.out.print(". ");
        }
      }
      System.out.println();
    }
  }

  void nextGeneration() {
    int height = feld.length ;
    int width = feld[0].length;
    int i, j;
    int count;
    
    boolean [][] tempfeld = new boolean [height][width];
    
    for (j = 0;  j < width;  j++) {
        tempfeld[0][j] = false;
        tempfeld[height-1][j] = false;
    }
    for (i = 0;  i < height;  i++) {
        tempfeld[i][0] = false;
        tempfeld[i][width-1] = false;
    }
    
    for (i = 1;  i < height-1;  i++) {
        for (j = 1;  j < width-1; j++) {
            count = 0;
            if (feld [i-1][j-1] == true)
                count++;
            if (feld [i-1][j] == true)
                count++;
            if (feld [i-1][j+1] == true)
                count++;
            if (feld [i][j-1] == true)
                count++;
            if (feld [i][j+1] == true)
                count++;
            if (feld [i+1][j-1] == true)
                count++;
            if (feld [i+1][j] == true)
                count++;
            if (feld [i+1][j+1] == true)
                count++;
                
            if ((count == 2) || (count == 3))
                tempfeld [i][j] = true;
            else if ((count < 2) || (count > 3))
                tempfeld [i][j] = false;
            else if ((feld [i][j] == false) && (count == 3))
                tempfeld [i][j] = true;
        
        }
    }
    for (i = 0;  i < height; i++)
        for (j = 0;  j < width;  j++)
            feld [i][j] = tempfeld [i][j];
    
    
  }

  public static void main(String[] args) {
    GameOfLife myGame = new GameOfLife();
    for (int i = 0; i < 10; i++) {
      myGame.nextGeneration();
      myGame.print();
      System.out.println();
    }
  }
}