Reputation: 191
I'm trying to make 'The Game of Life' in Java. I made a 2d matrix and filled it with boolean values.
Now I'm trying to count the boolean values of adjacent cells that are true, but when I use =
, I get all of the cells surrounding it (eg: a cell in the middle gives 8, a cell on a corner gives 3) and when I use ==
, I just get all 0's.
Example if statement (first one works, second doesn't work):
if(!celloc.equals("URC") && !celloc.equals("RightB") && !celloc.equals("LRC")) {
if(current[i][j+1] = true) {
life++; // right
}}
Upvotes: 0
Views: 197
Reputation: 661
A single "=" is for assignment, use "==" when testing for equivalency. Also, if "current[i][j+1]" is a boolean you can simply type:
if(current[i][j+1]) {
to test if that value is true. You may be getting 0 because you may not be getting to that if statement. Try adding some output to see if your first if statement is ever actually true.
Upvotes: 1