Appears I fixed the logic bug on the cells. The game seems to play out correctly now.
This commit is contained in:
+10
-8
@@ -86,8 +86,8 @@ int main(int argc, char** argv) {
|
||||
GlobalList->cells = calloc(GetIndex(MAX_X, MAX_Y, MAX_X) + 1, sizeof(Cell*));
|
||||
GlobalList->capcity = GetIndex(MAX_X, MAX_Y, MAX_X);
|
||||
|
||||
for(int x = 0; x < MAX_X; x++) {
|
||||
for(int y = 0; y < MAX_Y; y++) {
|
||||
for(int x = 0; x <= MAX_X; x++) {
|
||||
for(int y = 0; y <= MAX_Y; y++) {
|
||||
GlobalList->cells[GetIndex(x, y, MAX_X)] = CreateCell(x, y);
|
||||
}
|
||||
}
|
||||
@@ -104,6 +104,7 @@ int main(int argc, char** argv) {
|
||||
Restart:
|
||||
|
||||
RestartSim = 0;
|
||||
Start = 0;
|
||||
|
||||
Seed();
|
||||
|
||||
@@ -153,8 +154,6 @@ int main(int argc, char** argv) {
|
||||
|
||||
Cell* cell = GlobalList->cells[i];
|
||||
|
||||
if (!cell) continue;
|
||||
|
||||
int count = 0;
|
||||
|
||||
Cell* topLeft = GlobalList->cells[GetIndex(cell->x - 1, cell->y - 1, MAX_X)];
|
||||
@@ -172,13 +171,13 @@ int main(int argc, char** argv) {
|
||||
Cell* right = GlobalList->cells[GetIndex(cell->x + 1, cell->y, MAX_X)];
|
||||
if (right && right->Status == Alive) count++;
|
||||
// Point BottomLeft;
|
||||
Cell* bottomLeft = GlobalList->cells[GetIndex(cell->x + 1, cell->y - 1, MAX_X)];
|
||||
Cell* bottomLeft = GlobalList->cells[GetIndex(cell->x - 1, cell->y + 1, MAX_X)];
|
||||
if (bottomLeft && bottomLeft->Status == Alive) count++;
|
||||
// Point Botttom;
|
||||
Cell* bottom = GlobalList->cells[GetIndex(cell->x, cell->y + 1, MAX_X)];
|
||||
if (bottom && bottom->Status == Alive) count++;
|
||||
// Point BottomRight;
|
||||
Cell* bottomRight = GlobalList->cells[GetIndex(cell->x - 1, cell->y - 1, MAX_X)];
|
||||
Cell* bottomRight = GlobalList->cells[GetIndex(cell->x + 1, cell->y + 1, MAX_X)];
|
||||
if (bottomRight && bottomRight->Status == Alive) count++;
|
||||
|
||||
rect->x = cell->x * CELL_SIZE;
|
||||
@@ -207,8 +206,11 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
|
||||
void Seed(){
|
||||
//for (int f = 0; f < GlobalList->capcity; f++) GlobalList->cells[f]->Status = Dead;
|
||||
|
||||
for(int i = 0; i < GlobalList->capcity; i++) {
|
||||
if (GlobalList->cells[i] == NULL) continue;
|
||||
//if (GlobalList->cells[i] == NULL) continue;
|
||||
if (i > 200) return;
|
||||
|
||||
if (GetNotSoRandomNumber(100) % 3 != 0) continue;
|
||||
|
||||
@@ -250,7 +252,7 @@ void HandleInput(void) {
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if (event.button.button == SDL_BUTTON_RIGHT) exit(0);
|
||||
else Thing(event.button.x, event.button.y);
|
||||
//else Thing(event.button.x, event.button.y);
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_s) Start = 1;
|
||||
if (event.key.keysym.sym == SDLK_r) RestartSim = 1;
|
||||
|
||||
Reference in New Issue
Block a user