Please join us at the new JavaWorld Q&A Forums. Your existing login will work there. The discussions here are now read-only.


JavaWorld >> Java Beginner

Pages: 1
joker
journeyman


Reged: 07/19/06
Posts: 58
Game of life
      #185105 - 09/23/08 12:07 AM

I was wondering if anyone is familiar with game of life algorithm. I am trying to implement if but have trouble checking neighboring cells. I am working with 2d array of size [10][10]. Every cell has 8 neighbours and I am suppose to check each of those 8 cells that surround cell that I am currently on. Anyone has any suggestion?

Thanks


Post Extras: Print Post   Remind Me!   Notify Moderator  
hiwa
Carpal Tunnel


Reged: 06/21/03
Posts: 7704
Loc: Japan
Re: Game of life [Re: joker]
      #185141 - 09/23/08 05:40 PM

Neighbors for the cell[x][y] would be
(clock-wise from left-top)
cell[x-1][y-1]
cell[x][y-1]
cell[x+1][y-1]
cell[x+1][y]
cell[x+1][y+1]
cell[x][y+1]
cell[x-1][y+1]
cell[x-1][y]

Use double for-loops for iterating on them.

If the edge cells are wrapped around to the cells on the other side of edge, the neighbor computation should be sligtly different for them.

--------------------
*stop cruelty* Annual number of euthanized cats&dogs: US 5M, JP 500K.*for our better karma*


Post Extras: Print Post   Remind Me!   Notify Moderator  
joker
journeyman


Reged: 07/19/06
Posts: 58
Re: Game of life [Re: hiwa]
      #185413 - 09/25/08 12:40 PM

Yeah thanks so much for reply. The cells wrap around but I implemented somehow before I got your post. It took me a while to figure out how it works but I did it. I really appreciate the reply. Thank you

Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 3 anonymous users are browsing this forum.

Moderator:   

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 4536

Rate this topic

Jump to

Contact us JavaWorld

Powered by UBB.threads™ 6.5.5