Re: game of life
- From: Patrick May <pjm@xxxxxxx>
- Date: 24 Nov 2005 11:41:57 +0000
"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)
.
- References:
- game of life
- From: CPSCmajor
- Re: game of life
- From: Niels Dybdahl
- Re: game of life
- From: CPSCmajor
- Re: game of life
- From: CPSCmajor
- Re: game of life
- From: Roedy Green
- Re: game of life
- From: CPSCmajor
- Re: game of life
- From: wolfgang zeidler
- Re: game of life
- From: Roedy Green
- Re: game of life
- From: CPSCmajor
- Re: game of life
- From: CPSCmajor
- game of life
- Prev by Date: Re: Restructoring a java program
- Next by Date: Re: finding out weather an object extends a certain class
- Previous by thread: Re: game of life
- Next by thread: Finding the IP address of client proxy from Server side component
- Index(es):
Relevant Pages
|