• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Trouble with symbols not being found.

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't listen to Steve. Just read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic