Game of Life - Style gone bad
Howdie,
First of all id like to say that I have been loving the vidieos and am ashamed that it took me until I had a problem to sign up!
I have been following through the C course and have come a little stuck on a issue which is baffling me somewhat.
When I compiled and run towards the end of the tutorials, the "little men" (\f) were not disapearing during each generation and athough the min went down till it stabalized I ended up with a ("Zombie filled world") with the dead members refusing to leave.
I tried tracking it down and found some other errors that would of caused some problems including one that made the entire grid full but still couldnt find out the issue.
I then signed up and downloaded your source code to compare, after about 30 mins, I was well and truly stumped so I sectioned up the wibit code and systematically replaced mine with it until I found what was causing the problem.
From one of the earlier videos I remember hearing that you can always include a functions{} or leave it out if it is a single statement (I also liked notepad++ position highlight so have been adding them where I can, which infact caused this problem).
On line 108 of the Wibit Code lives this if statment:
if(tempGrid[i][j] == 1) population++;
g[i][j] = tempGrid[i][j];
Now when following through I put:
if(tempGrid[i][j] == 1)
{
population++;
g[i][j] = tempGrid[i][j];
}
Which is causing my zombie apocolipse, removing the {} fixes this problem but I am unsure of why?
I am thinking along the lines of once included in the block statement it scopes it so it is not available where needed.
Another small confusion is why this effects the persistance of the "zombie" characters, unless it in itself is breaking something that returns the array to 0.
Please forgive me if this is a stupid question, completely new to programming but you never know unless you ask, and I prefer to be the fool that asks instead of the one sitting in silence.
Cheers,
Les
Forum Rules/Features
Welcome to the WiBit.net forums! Check out our terms and features:
Hot Topic(s)
Annoy your friends
Is this something you think someone else would enjoy? Is it not for you, but do you know someone who is down with this type of content? Well share away:
Tweet
The Blog
Don't Let XML Make You a Cheater
This blog is a reminder that cheating in software development can get you into big trouble. Sometimes developers get really really lazy, OR are pressured to write something using overly simplified data structures. Almost every time this happens you are bitten in the butt! Sometimes the problems show up immediately and other times it may take months or years (especially in integrated systems).
- 1 of 78
- ››








Les, I'm not sure on this in C but it is so in Java, if you do not supply curly braces after an if statement it reads the very next statement and only the very next statement. So for an example of the code you provided.
if(tempGrid[i][j] == 1) population++;
g[i][j] = tempGrid[i][j];
Is the same as writing:
if(tempGrid[i][j] == 1){
population++;
}
g[i][j] = tempGrid[i][j];