#### Archived

This topic is now archived and is closed to further replies.

# I'm doing the game of life!

This topic is 6029 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I ran into a small problem though. I wrote a function to count the neighbors, and it worked, but it ended up being 3/4 of a page long. Does anyone know any incredibly short ways of doing this?

##### Share on other sites
Not terribly efficient, but short enough:

  int indexwrap( int x, int xdim ){ x %= xdim; return (x<0)?x+xdim:x;}int count( int x, int y, int xdim, int ydim ){ int i,j; count = 0; for( i = x-1; i < x+2; ++i ) for( j = y-1; j < y+2; ++j ) count += !((i==x) && (j==y)) && cell[indexwrap(i,xdim)][indexwrap(j,ydim)]; return count;}

##### Share on other sites
It''s been a while since I played, but I don''t remember any neighbors. I remember getting babies in the back of the stationwagon, and the occasional car crash would dump them all out onto the playing board (oh the humanity!).

##### Share on other sites
quote:
Original post by Stoffel
It''s been a while since I played, but I don''t remember any neighbors. I remember getting babies in the back of the stationwagon, and the occasional car crash would dump them all out onto the playing board (oh the humanity!).

ROFL

1. 1
Rutin
25
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 14
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631757
• Total Posts
3002141
×