shithub: moonfish

Download patch

ref: 42d06e8de474fe7b0eccb34700dea696faef9eca
parent: 81ff406eac32db854403b45149d46127a94ebe32
author: zamfofex <zamfofex@twdb.moe>
date: Wed Oct 9 00:53:32 EDT 2024

remove minified build

--- a/.build.yml
+++ b/.build.yml
@@ -21,7 +21,6 @@
       make LDFLAGS=-static
       make LDFLAGS=-static CC=x86_64-w64-mingw32-gcc moonfish.exe
       make LDFLAGS=-static CC='clang --target=wasm32-wasi' CPPFLAGS='-Dmoonfish_no_threads' moonfish.wasm
-      shell=bash ./minify.sh
   - strip: |
       cd moonfish
       strip --strip-all moonfish play lichess analyse chat
@@ -45,7 +44,6 @@
         -F "$root"/lichess=@lichess \
         -F "$root"/analyse=@analyse \
         -F "$root"/chat=@chat \
-        -F "$root"/moonfish.sh=@moonfish.sh \
         -F "$root"/moonfish.exe=@moonfish.exe \
         -F "$root"/moonfish.wasm=@moonfish.wasm \
         https://neocities.org/api/upload
--- a/.gitignore
+++ b/.gitignore
@@ -9,13 +9,10 @@
 !/.build.yml
 !/check.sh
 !/moonfish.vcxproj
-!/minify.sh
-!/rename.sh
 !/moonfish.h
 !/chess.c
 !/search.c
 !/main.c
-!/mini.c
 !/tools
 !/tools/tools.h
 !/tools/utils.c
--- a/chess.c
+++ b/chess.c
@@ -1,6 +1,8 @@
 /* moonfish is licensed under the AGPL (v3 or later) */
 /* copyright 2023, 2024 zamfofex */
 
+#include <string.h>
+
 #include "moonfish.h"
 
 static void moonfish_force_promotion(struct moonfish_chess *chess, struct moonfish_move **moves, unsigned char from, unsigned char to, unsigned char promotion)
@@ -276,12 +278,10 @@
 	int i, count;
 	struct moonfish_move moves[32];
 	
-#ifndef moonfish_mini
 	if (name[0] < 'a' || name[0] > 'h') return 1;
 	if (name[1] < '1' || name[1] > '8') return 1;
 	if (name[2] < 'a' || name[2] > 'h') return 1;
 	if (name[3] < '1' || name[3] > '8') return 1;
-#endif
 	
 	x0 = name[0] - 'a';
 	y0 = name[1] - '1';
@@ -349,10 +349,6 @@
 	}
 }
 
-#ifndef moonfish_mini
-
-#include <string.h>
-
 int moonfish_move(struct moonfish_chess *chess, struct moonfish_move *found, unsigned char from, unsigned char to)
 {
 	struct moonfish_move moves[32];
@@ -835,5 +831,3 @@
 	
 	*name = 0;
 }
-
-#endif
--- a/mini.c
+++ /dev/null
@@ -1,65 +1,0 @@
-/* moonfish is licensed under the AGPL (v3 or later) */
-/* copyright 2023, 2024 zamfofex */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "moonfish.h"
-
-int main(void)
-{
-	static char line[2048];
-	
-	struct moonfish_move move;
-	char name[6];
-	int our_time, their_time, time;
-	struct moonfish_chess chess;
-	char *arg;
-	
-	for (;;)
-	{
-		fgets(line, sizeof line, stdin);
-		arg = strchr(line, '\n');
-		if (arg) *arg = 0;
-		
-		if (!strncmp(line, "go ", 3))
-		{
-			sscanf(line, "go wtime %d btime %d", &our_time, &their_time);
-			
-			if (!chess.white)
-			{
-				time = our_time;
-				our_time = their_time;
-				their_time = time;
-			}
-			
-			moonfish_best_move_clock(&chess, &move, our_time, their_time);
-			moonfish_to_uci(&chess, &move, name);
-			printf("bestmove %s\n", name);
-		}
-		else if (!strncmp(line, "position ", 9))
-		{
-			moonfish_chess(&chess);
-			
-			arg = strstr(line, " moves ");
-			if (!arg) continue;
-			
-			arg = strtok(arg, " ");
-			
-			while (arg = strtok(NULL, "\n "))
-			{
-				moonfish_from_uci(&chess, &move, arg);
-				chess = move.chess;
-			}
-		}
-		else if (!strcmp(line, "uci"))
-			printf("uciok\n");
-		else if (!strcmp(line, "isready"))
-			printf("readyok\n");
-		else if (!strcmp(line, "quit"))
-			break;
-		
-		fflush(stdout);
-	}
-}
--- a/minify.sh
+++ /dev/null
@@ -1,98 +1,0 @@
-#!/usr/bin/env bash
-
-# moonfish is licensed under the AGPL (v3 or later)
-# copyright 2023, 2024 zamfofex
-
-set -e
-
-sh="${shell:-"${SHELL:-bash}"}"
-cc="${HOST_CC:-gcc}"
-
-# for each C source file
-cat moonfish.h chess.c search.c mini.c |
-
-# replace 'unsigned char' with 'int'
-sed 's/\bunsigned char\b/int/g' |
-
-# remove 'signed' and 'unsigned'
-sed 's/\tsigned /\t/g' |
-sed 's/\tunsigned /\t/g' |
-
-# remove 'long'
-sed 's/\blong\b \?//g' |
-
-# remove top-level 'static', 'int' and 'void'
-sed 's/^static\b//g' |
-sed 's/^int\b//g' |
-sed 's/^void\b//g' |
-
-# remove redundant 'int'
-sed 's/\bstatic int\b/static/g' |
-
-# remove the '#' from system '#include'
-sed 's/^#\(include <\)/\1/g' |
-
-# preprocess the file, add '#' back to 'include'
-# note: this materialises the whole file
-"$cc" -E -Dinclude='#include' -Dmoonfish_mini - |
-
-# remove lines starting with '# '
-sed '/^# /d' |
-
-# remove leading white space from '#include' lines
-sed 's/^[\t ]\+#/#/g' |
-
-# place all '#include' lines on top
-# note: this materialises the whole file
-( txt="$(tee)" && { grep '^#' <<< "$txt" || : ; grep -v '^#' <<< "$txt" ; } ) |
-
-# put line breaks around string literals
-sed 's/\("\(\\.\|[^"]\)*"\)/\n\1\n/g' |
-
-# put line breaks around character literals
-sed 's/\('"'"'\(\\.\|.\)*'"'"'\)/\n\1\n/g' |
-
-# in every line that isn't a string literal or '#include' line,
-# put line breaks around identifiers
-sed '/^[^"'"'"'#]/s/[a-z0-9_]\+/\n\0\n/gi' |
-
-# rename identifiers to be shorter
-"$sh" rename.sh |
-
-# replace all white space with tabs (except inside string literals)
-# note: this makes the next 'sed' materialise the whole file
-sed '/^[^"'"'"']/s/[\t ]\+/\t/g' |
-tr '\n' '\t' |
-
-# replace tabs between alphanumeric characters with a single space
-# note: there are no tabs inside string literals
-sed 's/\([a-z0-9_]\)\t\+\([a-z0-9_]\)/\1 \2/gi' |
-
-# remove all tab characters
-tr -d '\t' |
-
-# put line breaks back around '#include' lines again
-# (also remove whitespace betwen '#include' and '<')
-# note: there is no white space within include file names
-sed 's/#include<[^>]*>/\n\0\n/g' |
-
-# remove all empty lines
-sed '/^$/d' |
-
-# remove duplicate lines (for '#include')
-awk '!x[$0]++' |
-
-# store the result into a file
-tee moonfish.c |
-
-# and also compress it
-xz -e9qFraw > moonfish.c.xz
-
-# finally, make it into an executable program
-cat - moonfish.c.xz > moonfish.sh << END
-#!/bin/sh
-t=\`mktemp\`
-tail -n+5 "\$0"|unxz -Fraw|${CC:-cc} -O3 -o \$t -xc - -pthread
-(sleep 3;rm \$t)&exec \$t
-END
-chmod +x moonfish.sh
--- a/moonfish.h
+++ b/moonfish.h
@@ -116,8 +116,6 @@
 	unsigned char from, to;
 };
 
-#ifndef moonfish_mini
-
 /* the PST */
 extern moonfish_t moonfish_values[];
 
@@ -201,7 +199,5 @@
 /* note: 0 means false */
 int moonfish_checkmate(struct moonfish_chess *chess);
 int moonfish_stalemate(struct moonfish_chess *chess);
-
-#endif
 
 #endif
--- a/rename.sh
+++ /dev/null
@@ -1,51 +1,0 @@
-#!/usr/bin/env bash
-
-# moonfish is licensed under the AGPL (v3 or later)
-# copyright 2023, 2024 zamfofex
-
-set -e
-
-alphabet=({a..z} {a..z}{a..z} {a..z}{a..z}{a..z})
-alphabet2=("${alphabet[@]}")
-declare -A names
-
-functions="main fopen fread printf fprintf sscanf fgets fflush stdin stdout stderr strcmp strncmp strcpy strtok strstr strchr malloc realloc free exit errno clock_gettime timespec tv_sec tv_nsec pthread_create pthread_join pthread_t typedef moonfish_type_t"
-keywords="do while for if else switch case break continue return extern static struct enum unsigned signed long short int char void sizeof $functions"
-
-while read -r name
-do
-	if ! [[ "$name" =~ ^[a-z] ]]
-	then
-		echo "$name"
-		continue
-	fi
-	
-	if [[ " $keywords " =~ " $name " ]]
-	then
-		echo "$name"
-		continue
-	fi
-	
-	short="${names["$name"]}"
-	if [[ "$short" = "" ]]
-	then
-		if [[ "$name" =~ ^moonfish ]]
-		then
-			short="F${alphabet[0]}"
-			alphabet=("${alphabet[@]:1}")
-		else
-			while :
-			do
-				short="${alphabet2[0]}"
-				alphabet2=("${alphabet2[@]:1}")
-				if ! [[ " $keywords " =~ " $short " ]]
-				then break
-				fi
-			done
-		fi
-		
-		names["$name"]="$short"
-	fi
-	
-	echo "$short"
-done
--- a/search.c
+++ b/search.c
@@ -81,15 +81,11 @@
 {
 	struct timespec ts;
 	
-#ifdef moonfish_mini
-	clock_gettime(CLOCK_MONOTONIC, &ts);
-#else
 	if (clock_gettime(CLOCK_MONOTONIC, &ts))
 	{
 		perror(NULL);
 		exit(1);
 	}
-#endif
 	
 	return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
 }
@@ -187,7 +183,6 @@
 
 static void moonfish_iteration(struct moonfish_analysis *analysis, struct moonfish_move *best_move)
 {
-	int result;
 	int x, y;
 	struct moonfish_move moves[32];
 	int i, j, count;
@@ -227,14 +222,11 @@
 			analysis->threads[j].analysis = analysis;
 			analysis->threads[j].move = moves[i];
 			
-			result = thrd_create(&analysis->threads[j].thread, &moonfish_start_search, analysis->threads + j);
-#ifndef moonfish_mini
-			if (result != thrd_success)
+			if (thrd_create(&analysis->threads[j].thread, &moonfish_start_search, analysis->threads + j) != thrd_success)
 			{
 				fprintf(stderr, "error creating thread\n");
 				exit(1);
 			}
-#endif
 			
 			j++;
 		}
@@ -244,14 +236,11 @@
 	
 	for (i = 0 ; i < j ; i++)
 	{
-		result = thrd_join(analysis->threads[i].thread, NULL);
-#ifndef moonfish_mini
-		if (result != thrd_success)
+		if (thrd_join(analysis->threads[i].thread, NULL) != thrd_success)
 		{
 			fprintf(stderr, "error joining thread\n");
 			exit(1);
 		}
-#endif
 		
 		if (analysis->threads[i].score > analysis->score)
 		{
@@ -261,8 +250,6 @@
 	}
 }
 
-#ifndef moonfish_mini
-
 int moonfish_best_move_depth(struct moonfish_chess *chess, struct moonfish_move *best_move, int depth)
 {
 	static struct moonfish_analysis analysis;
@@ -273,8 +260,6 @@
 	moonfish_iteration(&analysis, best_move);
 	return analysis.score;
 }
-
-#endif
 
 int moonfish_best_move_time(struct moonfish_chess *chess, struct moonfish_move *best_move, long int time)
 {
--