This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Grokking Bitcoin and have Kalle Rosenbaum on-line!
See this thread for details.
Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Trouble with symbols not being found.  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm having some trouble implementing Conway's game of life. I can get to grips with the rules, but variable names are causing me headaches.

Here's how I have the code:



My problem is in the next method at the bottom. I am getting a bunch of errors at compile time relating to variables and missing symbols.

Can anyone help me fix this? I know it's probably something simple but i'm new to this so I can't figure it out.

Thanks in advance!
 
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you declare size? And colspace++ is not the same as col++ (also applies to others).

And please post the compile errors. It's easier to look at the compile error and refer back to the code.

good luck,
Gary
 
Saloon Keeper
Posts: 10135
214
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do away with the declaration of readgrid, and the assignment of generation to it. First of all, generation is not declared in the scope of next(), and secondly I doubt you would need readgrid because you already have access to cells.
 
Ian E Jones
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Those are the errors. I declared size on line 7, is there something else I should be doing at the end with that variable?
 
Stephan van Hulst
Saloon Keeper
Posts: 10135
214
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neither size nor generation are declared within the scope of the next method. They are local to the main method, and the Life constructor.

I already told you what to do about the generation symbol. Replace size in your next method with cells.length, and cells[row].length.
 
Stephan van Hulst
Saloon Keeper
Posts: 10135
214
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, I notice you assign new columns to the cells array in your next method. Don't do this. First construct the array newGrid with the same dimensions as cells, then read all the data you want from cells, and apply the results to newGrid. Finally when you are done, assign newGrid to cells. This will assure that you don't change the old situation before you are done reading from it.
 
Ian E Jones
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's actually what I was trying to do, I was just coming up with errors trying to write it any different way, what should I be doing here?
 
Stephan van Hulst
Saloon Keeper
Posts: 10135
214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I may make a suggestion, start like this, it should make the next method easier to implement, and the Life class easier to use by another class in general:
Make sure the next() method does not change the state of the current object.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!