public class GameOfLife {

    // size of the world
    private static final int WIDTH = 10, HEIGHT = 10;

    // which cells are alive
    private boolean[][] alive;

    // start evolution
    public static void main( String[] args ) {
        new GameOfLife().startGame();
    }

    // create a game-of-life object with given configuration
    public GameOfLife() {

        // elements are initialized with default value false
        alive = new boolean[ WIDTH ][ HEIGHT ];

        alive[ 3 ][ 3 ] = true;
        alive[ 4 ][ 3 ] = true;
        alive[ 5 ][ 3 ] = true;
        alive[ 6 ][ 4 ] = true;
        alive[ 7 ][ 4 ] = true;
        alive[ 8 ][ 4 ] = true;
    }

    // compute 10 generations and print intermediate steps
    public void startGame() {
        for ( int i = 0; i < 10; i++ ) {
            System.out.println( this );
            nextGeneration();
        }
    }

    // draw current generation
    public String toString() {
        String s = "-\n";
        for ( int j = 0; j < HEIGHT; j++ )
            for ( int i = 0; i < WIDTH; i++ )
                s += alive[ i ][ j ] ? "*" : " " + (i == 0 ? "\n" : "");

        return s;
    }

    // compute next generation
    private void nextGeneration() {
        boolean[][] next = new boolean[ WIDTH ][ HEIGHT ];

        for ( int i = 0; i < WIDTH; i++ )
            for ( int j = 0; j < HEIGHT; j ++ )
                next[ i ][ j ] = alive( i, j );

        alive = next;
    }

    // is cell alive in next generation?
    private boolean alive ( int col, int row ) {
        int living = 0;
        for ( int i = col - 1; i <= col + 1; i++ )
            for ( int j = row - 1; j <= row + 1; j++ )
                if ( 0 <= i && i < WIDTH && 0 <= j && j < HEIGHT &&
                     ( i != col || j != row) && alive[ i ][ j ] )
                    living++;

        return living == 3 || ( alive[ col ][ row ] && living == 2 );
    }
}

/*
-
 
          
          
          
  ***     
     ***  
          
          
          
          
         
-
 
          
          
   *      
   ****   
   ****   
      *   
          
          
          
         
-
 
          
          
   * *    
  *   *   
   *   *  
    * *   
          
          
          
         
-
 
          
          
          
  *** *   
   * ***  
          
          
          
          
         
-
 
          
          
   *      
  *** **  
  ** ***  
      *   
          
          
          
         
-
 
          
          
  ***     
       *  
  *       
     ***  
          
          
          
         
-
 
          
   *      
   *      
  *       
       *  
      *   
      *   
          
          
         
-
 
          
          
  **      
          
          
      **  
          
          
          
         
-
 
          
          
          
          
          
          
          
          
          
         
-
 
          
          
          
          
          
          
          
          
          
         

*/