Skip to content
Snippets Groups Projects
user avatar
Ole authored
- remove the unused include of unistd.h in cli.c and removed an out-commented codeline
3f295b4e
History

Game of life

simple c implementation of Conway's game of life.

usage

  • download /clone the src folder.
  • use the folling template:
#include "gol.h"
#include <stdio.h>
const unsigned int ROUNDS = 2;

//for each colmn print the value
void print_colmn(unsigned int value)
{
	printf("%d", value);
}

//print each row
void print_row(unsigned int line)
{
	printf("\n");
}

int main(int argc, char **argv)
{
	//setup a game of life struct with (24*5 cells)
	gol_t *game = gol_setup(24, 5);
	//set dead/alive cells
	game->current[7] = 28; // set ---  (blinker)
	unsigned int round = 0;
	while (1)
	{
		printf("round: %d \n", round++);
		//print current fields
		gol_each(game, &print_colmn, &print_row);
		if (round > ROUNDS)
		{
			break;
		}
		//evolve one time step
		gol_tick(game);
	}
	//free everything
	gol_free(game);
}

test

make test
echo $? #should be 0