public static void give_life(boolean[][]grid_of_life, int x, int y)
{
System.out.println("width = " +x);
System.out.println("height = "+y);
int counter = 0;
for(int i = 0;i<x;i++)
{
for(int j = 0;j<y;j++)
{
if(grid_of_life[i][j] == true)
{
if(grid_of_life[i][j+1] == true) counter++;
if(grid_of_life[i+1][j+1] == true) counter++;
if(grid_of_life[i+1][j] == true) counter++;
if(grid_of_life[i+1][j-1] == true) counter++;
if(grid_of_life[i][j-1] == true) counter++;
if(grid_of_life[i-1][j-1] == true) counter++;
if(grid_of_life[i-1][j] == true) counter++;
if(grid_of_life[i-1][j+1] == true) counter++;
if(counter<=1) grid_of_life[i][j].equals(false); //ERROR: says 'boolean cannot be dereferanced
if(counter>=4) grid_of_life[i][j].equsls(false);//ERROR: says 'boolean cannot be dereferanced
counter = 0;
}
else
{
if(grid_of_life[i][j+1] == true) counter++;
if(grid_of_life[i+1][j+1] == true) counter++;
if(grid_of_life[i+1][j] == true) counter++;
if(grid_of_life[i+1][j-1] == true) counter++;
if(grid_of_life[i][j-1] == true) counter++;
if(grid_of_life[i-1][j-1] == true) counter++;
if(grid_of_life[i-1][j] == true) counter++;
if(grid_of_life[i-1][j+1] == true) counter++;
if(counter == 3) grid_of_life[i][j].equals(true);//ERROR: says 'boolean cannot be dereferanced
counter = 0;
}
}
}
// check the result
for(int i = 0;i<x;i++)
{
for(int j = 0;j<y;j++)
{
System.out.println("Final State at: " +(i+1)+ " " +(j+1)+ " = " + grid_of_life[i][j]);
}
}
return;
}
if(counter<=1) grid_of_life[i][j].equals(false); //ERROR: says 'boolean cannot be dereferanced
if(counter>=4) grid_of_life[i][j].equsls(false);//ERROR: says 'boolean cannot be dereferanced
// Are you comparing boolean values or are you setting
// grid_of_life[i][j] to false?
if (counter <= 1) grid_of_life[i][j] = false;
if (counter >= 4) grid_of_life[i][j] = false;
Edited by: lethalwire on Nov 11, 2007 3:45 PMboolean t = true;
boolean f = false;
if (t)
System.out.println ("t is true");
if (!f)
System.out.println ("f is not true");
db thenextbesthang wrote:
i'm setting whatever is at grid_of_life[i][j] to false, if there is 1 or less 'trues' around it, or 4 or more 'trues' around it.
So imagine at [j] there are 4 trues around it, it should become false. Same thing if there are 1 or less. If there are two or three, nothing should happen.
In any case of you changing a value, use =.
int a = 3;
boolean a1 = false;
Same thing with your array
boolean[][] a2 = new boolean[2][2];
a2[0][0] = false;
Don't use
a2[0][0].equals(false)
Read the reply someone posted for the reason.