From: Huck Boles Date: Mon, 23 Jan 2023 04:17:48 +0000 (-0600) Subject: v0.2.1 X-Git-Url: https://git.huck.website/?a=commitdiff_plain;h=ba1ec2f12ff5a308265b28032f8f924190ff3cdf;p=gol.git v0.2.1 --- diff --git a/Makefile b/Makefile index ba53210..4ef4aaa 100644 --- a/Makefile +++ b/Makefile @@ -15,27 +15,20 @@ DOCDIR ?= $(USRDIR)/share/doc/$(NAME) SRCDIR ?= ./src OBJDIR ?= ./obj BUILD ?= ./build -TESTDIR ?= ./tests -TESTBIN ?= $(TESTDIR)/bin BIN ?= $(BUILD)/$(NAME) SRC ?= $(wildcard $(SRCDIR)/*.c) HDR ?= $(wildcard $(SRCDIR)/*.h) OBJ ?= $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(SRC)) -TEST ?= $(wildcard $(TESTDIR)/*.c) -TESTS ?= $(patsubst $(TESTDIR)/%.c, $(TESTBIN)/%, $(TEST)) -TAR ?= $(BUILD)/$(NAME)-$(VERSION).tar.gz -TARSUM ?= $(BUILD)/$(NAME)-$(VERSION)-tar.hash -BINSUM ?= $(BUILD)/$(NAME)-$(VERSION).hash +TAR ?= $(BUILD)/$(NAME)-$(VER).tar.gz MAN ?= $(SRCDIR)/$(NAME).1 -MANPAGE ?= $(BUILD)/$(MAN).gz +MANPAGE ?= $(patsubst $(SRCDIR)/%.1,$(BUILD)/%.1.gz,$(MAN)) DOC ?= README LICENSE CC ?= gcc -AR ?= tar -HASH ?= sha256sum +ZIP ?= gzip CFLAGS += -O2 -pipe WARNINGS ?= -Wall -Wextra -Wpedantic CPPFLAGS += -I $(SRCDIR) @@ -46,16 +39,15 @@ FLAGS ?= $(CPPFLAGS) $(CFLAGS) $(WARNINGS) $(LDFLAGS) $(LDLIBS) all: $(BIN) release: CFLAGS = -O3 -pipe -DNDEBUG -DDONT_USE_VOL -release: clean -release: tar release: $(BIN) - $(HASH) $(BIN) > $(BINSUM) -install: $(BIN) $(MAN) $(DOC) +install: $(BIN) $(MANPAGE) $(DOC) -mkdir -p $(BINDIR) - install -CDm 755 -t $(BINDIR) $(BIN) + cp $(BIN) $(BINDIR) + chmod 755 $(BINDIR)/$(patsubst $(BUILD)/%,%,$(BIN)) -mkdir -p $(MANDIR) - install -CDm 644 -t $(MANDIR) $(MANPAGE) + cp $(MANPAGE) $(MANDIR) + chmod 644 $(MANDIR)/$(patsubst $(BUILD)/%,%,$(MANPAGE)) -mkdir -p $(DOCDIR) install -CDm 644 -t $(DOCDIR) $(DOC) @@ -63,9 +55,7 @@ uninstall: -rm -rf $(BINDIR)/$(BIN) $(MANDIR)/$(MANPAGE) $(DOCDIR) tar: $(SRC) $(HDR) $(MAN) $(DOC) - -rm $(TAR) $(HASHSUM) - $(AR) -c -f - $(SRC) $(HDR) $(MAN) $(DOC) | gzip > $(TAR) - $(HASH) $(TAR) > $(TARSUM) + tar -I $(ZIP) -cvf $(TAR) $(SRC) $(HDR) $(MAN) $(DOC) $(BIN): $(OBJ) $(CC) $(OBJ) $(FLAGS) -o $(BIN) @@ -79,13 +69,10 @@ clean: debug: CFLAGS += -ggdb3 -Og debug: $(BIN) -$(TESTBIN)/%: $(TESTDIR)/%.c - $(CC) $(FLAGS) $< $(filter-out $(OBJDIR)/$(NAME).o,$(OBJ)) -o $@ +$(MANPAGE): $(MAN) + $(ZIP) -c $(MAN) > $(MANPAGE) -test: $(BIN) $(TESTBIN) $(TESTS) - for test in $(TESTS); do ./$$test; done - -$(SRCDIR) $(OBJDIR) $(BUILDIR) $(TESTDIR) $(TESTBIN): +$(SRCDIR) $(OBJDIR) $(BUILDIR): mkdir $@ .PHONY: all release clean install tar uninstall debug test diff --git a/README b/README index e69de29..8665e8e 100644 --- a/README +++ b/README @@ -0,0 +1,34 @@ +gol - Conway's Game Of Life + +Version: 0.2.2 + +gol is an implementation of Conway's Game of life that runs in a terminal emulator. +There are two states: alive and dead, and each generation uses the number of neighbors +to determine the state of each cell. A dead cell surrounded by exactly 3 live cells will +spawn. A live cell will stay alive if it is surrounded by 2 or 3 other cells, otherwise it +dies. Each generation uses the last generations map to create the next map. + + +Installation: + +Download and extract source: + $ curl "https://download.huck.website/gol-[VERSION].tar.gz > gol.tar.gz + $ tar -xzvf gol.tar.gz + $ cd gol.tar.gz + +Build and install: + $ make && sudo make install + + +Usage: + + Run gol with base parameters: + $ gol + Change size of map: + $ gol -x [COLUMNS] -y [ROWS] + Use ascii only mode: + $ gol -a + Change initial distribution weight: + $ gol -w [INT] +E + diff --git a/src/function.c b/src/function.c index 8b867dd..14b6580 100644 --- a/src/function.c +++ b/src/function.c @@ -61,10 +61,11 @@ void help(){ printf("Usage:\n"); printf("\tgol [OPTIONS]"); printf("Option flags:\n"); - printf("\t-x [INT]\tnumber of columns, default: 90\n"); - printf("\t-y [INT]\tnumber of rows, default: 30\n"); - printf("\t-a \tascii only mode\n"); + printf("\t-x [INT] number of columns, default: 90\n"); + printf("\t-y [INT] number of rows, default: 30\n"); + printf("\t-a\tascii only mode\n"); printf("\t-t [ms]\tamount of time to wait in ms between generations, default: 75000\n"); + printf("\t-w [INT] initial distribution weight\n"); printf("\t-V\tversion information\n"); printf("\t-h\tshow this help\n"); diff --git a/src/map.c b/src/map.c index 0e81cef..ae5ca41 100644 --- a/src/map.c +++ b/src/map.c @@ -21,8 +21,8 @@ int updatemap(struct map map){ int n = 0; struct map tmp = newmap(); - for (int r = 1; r < row-1; r++){ - for(int c = 1; c < col-1; c++){ + for (int r = 0; r < row-1; r++){ + for(int c = 0; c < col-1; c++){ int state = checkstate(map,r,c); tmp.line[r].cell[c].state = state; tmp.line[r].cell[c].cellchar = statechar(state); @@ -31,6 +31,22 @@ int updatemap(struct map map){ } } + for (int r = 0; r < row -1; r++){ + int state = checkstate(map,r,0); + tmp.line[r].cell[col-1].state = state; + tmp.line[r].cell[col-1].cellchar = statechar(state); + strncpy(tmp.line[r].cell[col-1].pixel,statecell(state),4); + if (state > DEAD){ n++; } + } + + for (int c = 0; c < col -1; c++){ + int state = checkstate(map,0,c); + tmp.line[row-1].cell[c].state = state; + tmp.line[row-1].cell[c].cellchar = statechar(state); + strncpy(tmp.line[row-1].cell[c].pixel,statecell(state),4); + if (state > DEAD){ n++; } + } + for(int r = 0; r < row; r++){ for (int c = 0; c < col; c++){ map.line[r].cell[c] = tmp.line[r].cell[c];