Jump to content

conway's game of life

- - - - -

  • Please log in to reply
1 reply to this topic

#1
compgeek97

compgeek97

    Newbie

  • Members
  • Pip
  • 6 posts
i found this program as an exercise in my school textbook and decided i wanted to try it. I am far ahead of the rest of my class(they just started for...next loops today) so my teacher is busy with other things. I have been able to create the board as well as buttons to clear the board, generate 20 random living cells, and move to the next generation. My problem lies in the algorithm i use to check how many neighbors each cell has. when i try to check the cells on the edges, with x=0 and y=0, obviously cell(x-1,y-1) is out of bounds. i get the correct error. how do i change the algorithm so that this is a toroidal array of cells? I would like the board to wrap in both the x and y axes.
my project code is attached.

[ATTACH]4487[/ATTACH]

Attached Files



#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
I haven't looked at your code, but I generally do something like
if x=0 then testx=20 else testx=x-1
if y=0 then testy=20 else testy=y-1

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users