1
0
mirror of https://codeberg.org/emilwilliams/life synced 2024-11-22 03:54:20 -05:00

README.md and well defined defaults

This commit is contained in:
Chad C. Starz 2024-07-24 20:31:21 +00:00
parent 55c146c927
commit f1d4d8bcf9
No known key found for this signature in database
GPG Key ID: CEEBC9208C287297
2 changed files with 34 additions and 12 deletions

10
README.md Normal file
View File

@ -0,0 +1,10 @@
# Conway's Game Of Life
An implementation in C.
Usage: ./life [GRID SIZE=20] [WAIT BETWEEN EACH STEP=4] [MAX STEP=-1]
WAIT is written as 1e6 / WAIT, which we wait as a fraction of a second.
I will one day write a good frontend for the CLI, along with proper
logging, and readin and readout of RLE, and maybe more.

36
life.c
View File

@ -9,6 +9,25 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
/* defaults */
#define DEFAULT_GRID_SIZE "20"
#define DEFAULT_WAIT 4
#define DEFAULT_MAX_STEP -1
/* symbols used */
char symbol [] = " O.";
/* ... */
/* maps to symbol */
enum {
LIFE_NONE,
LIFE_ALIVE,
LIFE_DEAD
};
#define DELC static inline #define DELC static inline
/* nearness mask, life mask */ /* nearness mask, life mask */
@ -17,14 +36,6 @@
/* life nearness function */ /* life nearness function */
#define life_near life_near_lim #define life_near life_near_lim
enum {
LIFE_NONE,
LIFE_ALIVE,
LIFE_DEAD
};
char symbol [] = " O.";
/* tty */ /* tty */
#define CSI "\033[" #define CSI "\033["
@ -229,18 +240,19 @@ int main (int argc, char ** argv) {
if ( argc >= 2 if ( argc >= 2
&& (strcmp (argv [1], "-h") == 0 && (strcmp (argv [1], "-h") == 0
|| strcmp (argv [1], "--help") == 0)) { || strcmp (argv [1], "--help") == 0)) {
printf ("%s [GRID SIZE] [WAIT BETWEEN EACH STEP=4] [MAX STEP=-1]\n", argv [0]); printf ("%s [GRID SIZE=%s] [WAIT BETWEEN EACH STEP=%d] [MAX STEP=-%d]\n",
argv [0], DEFAULT_GRID_SIZE, DEFAULT_WAIT, DEFAULT_MAX_STEP);
return 1; return 1;
} }
char * rect = argc >= 2 ? argv [1] : "20"; char * rect = argc >= 2 ? argv [1] : DEFAULT_GRID_SIZE;
board_t * b = board_alloc_text (rect); board_t * b = board_alloc_text (rect);
board_randomize (b, 5); board_randomize (b, 5);
board_eq_filter (b, 1); board_eq_filter (b, 1);
int wait = argc >= 3 ? atoi (argv [2]) : 4; int wait = argc >= 3 ? atoi (argv [2]) : DEFAULT_WAIT;
int step = argc >= 4 ? atoi (argv [3]) : -1; int step = argc >= 4 ? atoi (argv [3]) : DEFAULT_MAX_STEP;
#ifndef NDEBUG #ifndef NDEBUG
life_debug_near (b, 0, 0); life_debug_near (b, 0, 0);