Commit 4186a22

mo khan <mo@mokhan.ca>
2014-12-30 02:07:15
use pointers to cells instead.
1 parent 2ce0728
Changed files (3)
src/cell.c
@@ -13,6 +13,6 @@ Cell* cell_create(int number_of_cells) {
   return cells;
 }
 
-int cell_alive(Cell cell) { 
-  return cell.alive == true ? 1 : 0; 
+int cell_alive(Cell *cell) {
+  return cell->alive ? 1 : 0;
 };
src/cell.h
@@ -5,4 +5,4 @@ typedef struct {
 } Cell;
 
 Cell* cell_create(int number_of_cells);
-int cell_alive(Cell cell);
+int cell_alive(Cell *cell);
src/world.c
@@ -39,19 +39,19 @@ int south_east_of(World *world, int index) {
   return east_of(world, south_of(world, index));
 }
 
-Cell world_cell_at(World *world, int index) {
-  return world->cells[sizeof(Cell) * index];
+Cell* world_cell_at(World *world, int index) {
+  return &world->cells[sizeof(Cell) * index];
 }
 
 int world_neighbours(World *world, int index) {
-  Cell west_cell = world_cell_at(world, west_of(world, index));
-  Cell east_cell = world_cell_at(world, east_of(world, index));
-  Cell north_cell = world_cell_at(world, north_of(world, index));
-  Cell south_cell = world_cell_at(world, south_of(world, index));
-  Cell north_west_cell = world_cell_at(world, north_west_of(world, index));
-  Cell north_east_cell = world_cell_at(world, north_east_of(world, index));
-  Cell south_west_cell = world_cell_at(world, south_west_of(world, index));
-  Cell south_east_cell = world_cell_at(world, south_east_of(world, index));
+  Cell *west_cell = world_cell_at(world, west_of(world, index));
+  Cell *east_cell = world_cell_at(world, east_of(world, index));
+  Cell *north_cell = world_cell_at(world, north_of(world, index));
+  Cell *south_cell = world_cell_at(world, south_of(world, index));
+  Cell *north_west_cell = world_cell_at(world, north_west_of(world, index));
+  Cell *north_east_cell = world_cell_at(world, north_east_of(world, index));
+  Cell *south_west_cell = world_cell_at(world, south_west_of(world, index));
+  Cell *south_east_cell = world_cell_at(world, south_east_of(world, index));
 
   return cell_alive(west_cell)
     + cell_alive(east_cell)