Re: game of life



"CPSCmajor" <bmerritt1987@xxxxxxxxx> writes:
> anyone have any ideas?? thanks.

My first idea is to ask you to please stop top posting. ;-)

> I got rid of the out of bounds exception, and now the rest of the
> program doesn't work :( ! All that it will do is display the initial
> configuration and then make it disappear. I don't know what else to
> try to fix it. Any ideas?
[ . . . ]
> public static void main(String[] args)
> {
> GameOfLife g = new GameOfLife(); // Creates a new Game of Life
> Scanner s = new Scanner(System.in);
>
> System.out.print("Enter a configuration: ");
> int config = s.nextInt();
> int i = 12;
> int j = 12;
> String board[][] = new String[ROWS][COLUMNS];
> System.out.print(g.toString());
>
> if (config == 1) // Sets up configuration a
> {
> for (board[i][j] = " "; j <= 15; j++)
> {
> g.set(i, j);
> System.out.print(g.toString());
> }
> g.countNeighbors(board, i, j);
> System.out.print(g.nextGen(board));
> System.out.print(g.toString());
[ . . . ]
> }
[ . . . ]

The good news is that your code is behaving exactly as it
should. The bad news is that the behavior is not what you _want_. If
you look carefully at the snippet I've quoted, you are:

1. setting up a board configuration
2. printing it
3. counting the number of neighbors forsome reason
4. printing the next generation
5. printing the board again
6. stopping

Presumably you want to do something like:

1. set board configuration
2. loop some number of times while
2a. printing the board
2b. updating the board
3. stop

Does that help?

One other note: Your for loops will be more understandable if
you initialize the increment counter within the loop, e.g.:

for (j = 12;j <= 15;j++)

Regards,

Patrick

------------------------------------------------------------------------
S P Engineering, Inc. | The experts in large scale distributed OO
| systems design and implementation.
pjm@xxxxxxx | (C++, Java, Common Lisp, Jini, CORBA, UML)
.



Relevant Pages

  • Strange behaviour of while loop !!
    ... I have a query on the behaviour while loop ... based on code snippet given below - ... int main ... as whileand keep printing the value of x continuously? ...
    (comp.lang.c)
  • Re: [C] problem displaying string
    ... character and printing it with the %d format. ... >typedef struct bigint { ... >int main ... > bigint nines, subtrahend, diff; ...
    (alt.comp.lang.learn.c-cpp)
  • Re: offscreen rendering in Linux
    ... I'm trying to get printing my OpenGL scenes of aUCBLogo to work ... Instead of a Pixmap use a PBuffer. ... int scrnum = DefaultScreen; ...
    (comp.graphics.api.opengl)
  • Re: Better report handling
    ... I need help on printing a report. ... I do a sequential search on the child file which has ... Do you have any ideas on why I can't retrieve all the associated child ...
    (comp.lang.clarion)
  • Re: Speeding up the ocnPrint() function
    ... warning if the printing exceeds 10000 points. ... of the points each time through the loop. ... How much physical memory does your workstation have? ... Who knows what the limiting mechanism is; no source code, ...
    (comp.cad.cadence)