ref: ba40d957a856ab2c1ebdde90492f6e9e0485c2a4
parent: 7006b40c1f110656932c18acd39ab18174899145
author: zamfofex <zamfofex@twdb.moe>
date: Sat Oct 7 11:04:49 EDT 2023
add option to inbuild network into the executable
--- a/main.c
+++ b/main.c
@@ -21,12 +21,20 @@
char name[6];
int score;
- if (argc != 2)
+ if (argc < 1) return 1;
+
+ if (argc != 2 && moonfish_network == NULL)
{- if (argc > 0) fprintf(stderr, "usage: %s <file-name>\n", argv[0]);
+ fprintf(stderr, "usage: %s <file-name>\n", argv[0]);
return 1;
}
+ if (argc > 2)
+ {+ fprintf(stderr, "usage: %s [<file-name>]\n", argv[0]);
+ return 1;
+ }
+
ctx = malloc(sizeof *ctx);
if (ctx == NULL)
{@@ -34,7 +42,9 @@
return 1;
}
- file = fopen(argv[1], "rb");
+ if (argc >= 2) file = fopen(argv[1], "rb");
+ else file = fmemopen(moonfish_network, 1139, "rb");
+
if (file == NULL)
{perror(argv[0]);
--- a/makefile
+++ b/makefile
@@ -1,7 +1,31 @@
-CFLAGS = -ansi -O3 -Wall -Wextra -Wpedantic
+CFLAGS ?= -ansi -O3 -Wall -Wextra -Wpedantic
-moonfish: *.c moonfish.h
- $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o moonfish *.c
+cc = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
-play: tools/play.c chess.c moonfish.h
- $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -pthread -D_POSIX_C_SOURCE=200809L -o play chess.c tools/play.c
+ifeq ($(inbuilt_network),yes)
+
+moonfish: moonfish.h *.c net/tanh.c tanh.o
+ $(cc) -D_POSIX_C_SOURCE=200809L -o moonfish net/tanh.c tanh.o *.c
+
+tanh.o: tanh.moon
+ $(LD) -r -b binary -o tanh.o tanh.moon
+
+tanh.moon: tanh.pickle
+ python3 convert.py tanh.pickle
+
+else
+
+moonfish: moonfish.h *.c net/none.c
+ $(cc) -o moonfish net/none.c *.c
+
+endif
+
+play: moonfish.h tools/play.c chess.c
+ $(cc) -pthread -D_POSIX_C_SOURCE=200809L -o play tools/play.c chess.c
+
+.PHONY: all clean
+
+all: moonfish play
+
+clean:
+ $(RM) moonfish play tanh.moon tanh.o
--- a/moonfish.h
+++ b/moonfish.h
@@ -79,4 +79,6 @@
int moonfish_validate(struct moonfish *ctx);
int moonfish_check(struct moonfish *ctx);
+extern char *moonfish_network;
+
#endif
--- /dev/null
+++ b/net/none.c
@@ -1,0 +1,5 @@
+#include <stdlib.h>
+
+#include "../moonfish.h"
+
+char *moonfish_network = NULL;
--- /dev/null
+++ b/net/tanh.c
@@ -1,0 +1,6 @@
+#include <stdlib.h>
+
+#include "../moonfish.h"
+
+extern char _binary_tanh_moon_start[];
+char *moonfish_network = _binary_tanh_moon_start;
--
⑨