Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Bertha Ferguson   on Jan 19 In Java Category.

  
Question Answered By: Ada Bailey   on Jan 19

Firstly, c[][] is an array of objects of cell  type. .getAlive()
method is a method of Cell.

Maybe I was a little vague in sending this code, I just figured I
might have got something fundamental wrong and it wouldn't matter if
anyone who looked at my code  knew what it was supposed to do.

So here's a brief outline:

it is basically a Conway's Life Generation program, and the method I
have posted checks each cell that is passed into the method for any
neighbouring alive cells.

The reason I used the for loop

> > for(int y = -1; y < 2; y++)
> > {
> > for(int x = -1; x < 2; x++)

is so each neighbouring cell is checked, like so:
xxx
xox
xxx

x being the neighbours and o being the coordinates passed in to the
method.

if I exchange < 2 for < 3 it would chack in this fashion
xxxx
xoxx
xxxx
xxxx

Which isn't what I want.

I am still having difficulty but I have narrowed the problem down to
this line (which is needed for the chack to be done correctly)

if (x != 0 && y != 0)

Basically this line makes sure that it isn't checking ITSELF for a
neighbour then lets the variable increment. Without this line, I
would get 1 too many neighbours each time  I checked an alive cel for
neighbours (both alive and dead cells need to be checked for the
program to run correctly). But for some strange reason, this very
line is stopping the incrementation from going past 1!

If you can help I would REALLY appreciate it, as I am totally screwed!

Share: