Re: help help, ... :) "game of life",
Quote:
I need this assignment please because I have to solve it.
Yes you're quite right you have to solve it.
Quote:
But instead of False True I need it 0 1
Ok but that's easy for you to change.
Quote:
exactly same this assignment which disccussed here.
Lucky you, that'll make things a lot easier for you.
Quote:
please help cause I have tough courses
Oh poor you :rolleyes:
Re: help help, ... :) "game of life",
oh please I wanna help
because really I don't understand JAVA
and there are many seperated codes here I don't know what I have to pick
please help :(
don't worry about zeros one .
just make it done for me.
Re: help help, ... :) "game of life",
I put this cod:
Code:
public class Life {
public static void main(String[] args) {
boolean[][] cell = new boolean[5][5];
for (int i=0;i<cell.length;i++)
for (int j=0;j<cell[0].length;j++)
cell[i][j] = false;
cell[1][2] = true;
cell[1][1] = true;
cell[1][0] = true;
for (int i=cell.length-1;i>=0;i--)
{
for (int j=0;j<cell[0].length;j++)
{
System.out.print(cell[i][j]+" ");
}
System.out.println();
}
System.out.println(numberOfNeighbors(cell,1,1)+" "+ checkCell(cell,1,1));
cell = nextGeneration(cell);
for (int i=cell.length-1;i>=0;i--)
{
for (int j=0;j<cell[0].length;j++)
{
System.out.print(cell[i][j]+" ");
}
System.out.println();
}
}
public static boolean isInside(boolean[][] cells, int x, int y) {
if ((cells.length <= x) || (x < 0) || (cells[0].length <= y) || (y < 0))
return false;
return true;
}
public static boolean checkCell(boolean[][] cells, int x, int y) {
return isInside(cells, x, y) && cells[x][y];
}
public static int numberOfNeighbors(boolean[][] cells,int x,int y) {
int count=0,j=0,i=1,marker=0;
while (marker < 3)
{
if ((checkCell(cells,x+j,y)) && (cells[x+j][y] != cells[x][y]))
count++;
if (checkCell(cells,x+j,y+i))
count++;
if (checkCell(cells,x+j,y-i))
count++;
j=1;
marker++;
if (marker == 2)
j=-1;
}
return count;
}
public static boolean[][] nextGeneration(boolean[][] cells) {
boolean[][] cell = new boolean[cells.length][cells[0].length];
for (int i=0;i<cells.length;i++)
for (int j=0;j<cells[0].length;j++)
cell[i][j] = false;
for (int i=0;i<cells.length;i++)
for (int j=0;j<cells[0].length;j++)
{
if ((checkCell(cells,i,j)) && (numberOfNeighbors(cells,i,j) > 2))
{
cell[i][j] = true;
}
if (numberOfNeighbors(cells,i,j) == 3)
{
cell[i][j] = true;
}
else
{
cell[i][j] = false;
}
}
return cell;
}
}
It gives me :
false false false false false
false false false false false
false false false false false
true true true false false
false false false false false
2 true
false false false false false
false false false false false
false true false false false
false false false false false
false true false false false
<<< but the correct way is
input:
false false false false false
false false false false false
false false false false false
true true true false false
false false false false false
output:
false false false false false
false false false false false
false true false false false
false true false false false
false true false false false
Re: help help, ... :) "game of life",
There's only one cell that is wrong and that is the case where a cell stays alive if it has 2 or 3 neighbours. So you need to look at the code that handles this case - of course it would be eaiser for you to do this if you had documented which bit of code handled which case.
Re: help help, ... :) "game of life",
Quote:
Originally Posted by
sanfor
i did it ;P
Code:
int numberOfNeighbors;
if (checkCell(cells,x,y))
numberOfNeighbors=-1;
else
numberOfNeighbors=0;
before:
Code:
false false false false false
false false false false false
false false false false false
true true true false false
false false false false false
after:
Code:
false false false false false
false false false false false
false true false false false
false true false false false
false true false false false
I don't know where I have to add this code to fix the problem.
again, please I need help.
Re: help help, ... :) "game of life",
Quote:
Originally Posted by
NOT-BAD
I don't know where I have to add this code to fix the problem.
You claim you already wrote the code that does other checks of the neighbours, so you ought to know where it goes. If not, find code that looks similar, and insert it there (hint: the nextGeneration(..) method). Some things you need to figure out for yourself.
Why do we never have time to do it right, but always have time to do it over?
Anon.
Re: help help, ... :) "game of life",
Quote:
Originally Posted by
NOT-BAD
oh please I wanna help
because really I don't understand JAVA
and there are many seperated codes here I don't know what I have to pick
please help :(
In case you're wondering why you're getting the responses you see here, this is an assistance forum, not a homework cheating forum.
You say you don't really understand Java, but isn't that the point of the class you are taking? If you don't understand, how is having someone else do your work going to help you understand better? I suggest you do some more reading and/or work with your instructor, because you do need more help if this is the case.
Quote:
don't worry about zeros one .
just make it done for me.
:eek:
Not going to happen. Most of us here are helping out in our spare time in addition to what ever full time jobs we have. We don't have the time or inclination to write your homework for you. We've already put in the time to learn and know the subject. This is where you do the same. If you read this entire thread, you'll see the difference between the amount of effort Sanfor put in and what you're giving. That level of effort is directly reflected in the answers you're getting.