Game of life ERROR

0

I'm doing a somewhat simple code of Conway's famous "Game of Life",

this is the creation of the arrangement

public class FunInicio 
{
    public int [][] llenado() 
    {
        int [][] you = new int [10][10];
        for (int i=0; i<you.length; i++) 
        {
            for (int j=0; j<you.length; j++)
            {
                int celGen=(int)(Math.random()*2);
                you[i][j]=celGen;
            }
        }

        for (int i=0; i<you.length; i++)
        {
            System.out.println(" ");
            for (int j=0; j<you.length; j++)
            {
                System.out.print(you[i][j] +" | ");
            }
        }
        return you;
    }
}

Here the evaluation of various actions

public class theEndIsNigh 
{
    int genesis=0;
    int alv=0;
    int alive[][]=new int [10][10];

    public void chequeo (int life[][]) 
    {
        for (int i=0; i<10; i++)
        {
            for (int j=0; j<10; j++)
            {
                //-----------------------------------------------
                try
                {
                    if(life[i-1][j-1] == 1)
                    {
                        alv++;
                    }
                    if(life[i-1][j-1] == 0)
                    {
                        genesis++;
                    }
                }
                catch(ArrayIndexOutOfBoundsException a)
                {/*NorOeste*/ }
                try
                {
                    if(life[i-1][j]== 1)
                    {
                        alv++;
                    }
                    if(life[i--][j] == 0)
                    {
                        genesis++;
                    }
                }
                catch(ArrayIndexOutOfBoundsException b)
                {/*Norte*/ }
                try
                {
                    if(life[i-1][j+1] == 1)
                    {
                        alv++;
                    } 
                    if(life[i-1][j-1] == 0)
                    {
                        genesis++;
                    }
                 }
                catch(ArrayIndexOutOfBoundsException c)
                {/*NorEste*/ }
                try
                {
                    if(life[i]  [j-1] == 1)
                    {
                        alv++;
                    } 
                    if(life[i-1][j-1] == 0)
                    {
                        genesis++;
                    }
                }
                catch(ArrayIndexOutOfBoundsException d)
                {/*Oeste*/ }
                try
                {
                    if(life[i]  [j+1] == 1)
                    {
                        alv++;
                    } 
                    if(life[i-1][j-1] == 0)
                    {
                        genesis++;
                    }
                }
                catch(ArrayIndexOutOfBoundsException e)
                {/*Este*/ }
                try
                {
                    if(life[i+1][j-1] == 1)
                    {
                        alv++;
                    } 
                    if(life[i-1][j-1] == 0)
                    {
                        genesis++;
                    }
                }
                catch(ArrayIndexOutOfBoundsException f)
                {/*SurOeste*/ }
                try
                {
                    if(life[i+1][j] == 1)
                    {
                        alv++;
                    } 
                    if(life[i-1][j-1] == 0)
                    {
                        genesis++;
                    }
                }
                catch(ArrayIndexOutOfBoundsException g)
                {/*Sur*/ }
                try
                {
                    if(life[i+1][j+1] == 1)
                    {
                        alv++;
                    } 
                    if(life[i-1][j-1] == 0)
                    {
                        genesis++;
                    }
                }
                catch(ArrayIndexOutOfBoundsException h)
                {/*SurEste*/ }
                alive[i][j]=alv;
                alv=0;
                genesis=0;
            }
        }
    }
}

public int [][] vosQuienSos (int alie[][]) 
{  
    int matExtra [][]= new int [10][10];
    for (int j=0; j<10; j++)
    {
        for (int i=0; i<10; i++)
        {
            switch(alie[j][i])
            {
                case 0:
                    if(alive[j][i] == 3) 
                    { 
                        matExtra[j][i] = 1; 
                    }
                    break;

                case 1:
                    if(alive[j][i] == 2 || alive[j][i] ==3) 
                    { 
                        matExtra[j][i] = 1; 
                    }
                    else if(alive[j][i] >= 4) 
                    { 
                        matExtra[j][i] = 0;
                    }
                    break;
                default:
                    System.out.println(".");
            }
            System.out.print(matExtra[j][i] + " | ");
        }
        System.out.println();
    }
    return matExtra;  
}

and this is the Main

  public class AlphaEtOmega 
  {
      void Dato ()
      {
          theEndIsNigh end=new theEndIsNigh();
          FunInicio func=new FunInicio();
          int omega[][]= new int [10][10];
          omega=func.llenado();
          int repeat=0;
          do 
          { 
              end.chequeo(omega);
              omega=end.vosQuienSos(omega);
              repeat++;
          } while (repeat<10);
      } 
      public static void main(String[] args) 
      {
          AlphaEtOmega inicioFin=new AlphaEtOmega();
          inicioFin.Dato();
      }
  }

My mistake in this case is that I only print an Arrangement and the program tries to continue but something prevents it What could I do?

    
asked by MirDepressed12 23.05.2018 в 10:31
source

0 answers