This might be asking entirely too much, and if it is I'll go back to trying to fix it on my own, but I was wondering if someone would be able to help me figure out why what I've written doesn't work.
I'm trying to make Conway's Game of Life [
http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life] right now and it's not working. I'm quite frankly stumped, I've been over it a hundred times and everything looks fine to me.
When I run the program and test it, the simulation generates patterns, but not the proper/intended ones.
I went about it by drawing a grid and creating an array of bools called IsCellOccupied, each element representing one square on the grid, 1's representing that cell being occupied, 0's representing empty. It's a two dimensional array, though, with the first dimension a size of two so that it can hold the current game board in one instance and the next iteration of the board in the other instance. This is so it can evaluate every rule at once without making changes to the current board when transitioning to the next turn.
I think the problem probably lies in simulation_rules. A function called simulateturn is called, and from there, four functions are called, each representing one of the rules from the wikipedia page. Each one of those four functions cycles through every element of the current instance of the iscelloccupied array, calling another function that returns how many alive neighbors that square has. It then switches to the other element in the first dimension of the array and sets that square to be alive or dead depending on how many alive neighbors it has, then switches back to the original value and continues to cycle through the remaining squares. Once the four turns end, the iscelloccupied is then switched over to the new board that we just made, and the current iteration is wiped clean.
At least, that's how it should work, I think, but it either doesn't work like that or I'm misunderstanding the logic. I've tried running each rule separately and it's just nonsensical.
The rule 1 function for example causes everything to die, even if it's surrounded completely with live cells.
The rule 2 function shouldn't even do anything, but it causes adjacent squares to come alive if two or more sqaures are alive next to each other, which I'm baffled by.
Rule 3 function just causes everything to die
and rule 4 does something similar to 2
I've spent most of my day trying to figure out what's wrong and I've kind of given up at this point. I'm going to keep trying to fix it, but if anyone wants to help me out, I'd appreciate it. This is all of the code
Main
http://pastebin.com/HGqwHSDz
Board.h
http://pastebin.com/meD5Qm2z
constants.h
http://pastebin.com/kTqpLX9u
input.h
http://pastebin.com/vr0YyPcg
SDL_Graphics.h
http://pastebin.com/33XSApsS
timer.h
http://pastebin.com/mdydwNuW
board.cpp
http://pastebin.com/8b2sad0x
input.cpp
http://pastebin.com/BhHSafhM
sdl_graphics.cpp
http://pastebin.com/R39ZGdt0
simulation_rules.cpp
http://pastebin.com/5SZDcZe1
timer.cpp
http://pastebin.com/fdmnyv0u