aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmil Williams2024-07-24 20:31:21 +0000
committerEmil Williams2024-07-24 20:31:21 +0000
commitf1d4d8bcf9bf5ac28413c43508a71757d7804d64 (patch)
treefe26c61f9fcfbe45b0f9e9e35c6642a2662ec052
parent55c146c9276b4727adcc55e75a4304bf94f08f96 (diff)
downloademil-life-master.tar.xz
emil-life-master.tar.zst
README.md and well defined defaultsHEADmaster
-rw-r--r--README.md10
-rw-r--r--life.c34
2 files changed, 33 insertions, 11 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..893187c
--- /dev/null
+++ b/README.md
@@ -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.
diff --git a/life.c b/life.c
index eb84346..35ed216 100644
--- a/life.c
+++ b/life.c
@@ -9,21 +9,32 @@
#include <time.h>
#include <unistd.h>
-#define DELC static inline
+/* defaults */
-/* nearness mask, life mask */
-#define LIFE_NEAR_MASK ((1 << 4) - 1)
-#define LIFE_MASK (32)
-/* life nearness function */
-#define life_near life_near_lim
+#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
};
-char symbol [] = " O.";
+#define DELC static inline
+
+/* nearness mask, life mask */
+#define LIFE_NEAR_MASK ((1 << 4) - 1)
+#define LIFE_MASK (32)
+/* life nearness function */
+#define life_near life_near_lim
/* tty */
@@ -229,18 +240,19 @@ int main (int argc, char ** argv) {
if ( argc >= 2
&& (strcmp (argv [1], "-h") == 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;
}
- char * rect = argc >= 2 ? argv [1] : "20";
+ char * rect = argc >= 2 ? argv [1] : DEFAULT_GRID_SIZE;
board_t * b = board_alloc_text (rect);
board_randomize (b, 5);
board_eq_filter (b, 1);
- int wait = argc >= 3 ? atoi (argv [2]) : 4;
- int step = argc >= 4 ? atoi (argv [3]) : -1;
+ int wait = argc >= 3 ? atoi (argv [2]) : DEFAULT_WAIT;
+ int step = argc >= 4 ? atoi (argv [3]) : DEFAULT_MAX_STEP;
#ifndef NDEBUG
life_debug_near (b, 0, 0);