shithub: moonfish

Download patch

ref: d21a86fe75905c8e2cd2f154bb55f9539e1f6a6f
parent: b1b324741eb77f1cde80e2f872721617b3a3cd12
author: zamfofex <zamfofex@twdb.moe>
date: Sun Nov 19 04:14:26 EST 2023

make pthreads non‐optional

--- a/makefile
+++ b/makefile
@@ -7,16 +7,12 @@
 
 src := chess.c search.c main.c
 
-moonfish_cc := $(cc)
+moonfish_cc := $(cc) -pthread -D_POSIX_C_SOURCE=199309L
 tools_cc := $(cc) -pthread -D_POSIX_C_SOURCE=200809L
 
 .PHONY: all clean
 
 all: moonfish play lichess analyse
-
-ifneq ($(has_pthread),no)
-moonfish_cc += -D_POSIX_C_SOURCE=199309L -DMOONFISH_HAS_PTHREAD -pthread
-endif
 
 moonfish moonfish.exe: moonfish.h $(src)
 	$(moonfish_cc) -o $@ $(src)
--- a/minify.sh
+++ b/minify.sh
@@ -12,7 +12,7 @@
 sed 's/^#\(include <\)/\1/g' |
 
 # preprocess the file, add '#' back to 'include'
-gcc -E -DMOONFISH_HAS_PTHREAD -Dinclude='#include' - |
+gcc -E -Dinclude='#include' - |
 
 # remove lines starting with '# '
 sed '/^# /d' |
--- a/search.c
+++ b/search.c
@@ -4,7 +4,15 @@
 #include <time.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <pthread.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
 
+#ifdef __MINGW32__
+#include <sysinfoapi.h>
+#endif
+
 #include "moonfish.h"
 
 static int moonfish_search(struct moonfish_chess *chess, int alpha, int beta, int depth)
@@ -44,17 +52,6 @@
 	return alpha;
 }
 
-#ifdef MOONFISH_HAS_PTHREAD
-
-#include <pthread.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-
-#ifdef __MINGW32__
-#include <sysinfoapi.h>
-#endif
-
 struct moonfish_search_info
 {
 	pthread_t thread;
@@ -166,48 +163,6 @@
 	
 	return best_score;
 }
-
-#else
-
-static int moonfish_best_move_depth(struct moonfish *ctx, struct moonfish_move *best_move, int depth)
-{
-	int x, y;
-	struct moonfish_move moves[32];
-	struct moonfish_move *move;
-	int score, best_score;
-	
-	best_score = -200 * moonfish_omega;
-	
-	for (y = 0 ; y < 8 ; y++)
-	for (x = 0 ; x < 8 ; x++)
-	{
-		moonfish_moves(&ctx->chess, moves, (x + 1) + (y + 2) * 10);
-		
-		for (move = moves ; move->piece != moonfish_outside ; move++)
-		{
-			moonfish_play(&ctx->chess, move);
-			
-			if (!moonfish_validate(&ctx->chess))
-			{
-				moonfish_unplay(&ctx->chess, move);
-				continue;
-			}
-			
-			score = -moonfish_search(&ctx->chess, -100 * moonfish_omega, 100 * moonfish_omega, depth);
-			moonfish_unplay(&ctx->chess, move);
-			
-			if (score > best_score)
-			{
-				*best_move = *move;
-				best_score = score;
-			}
-		}
-	}
-	
-	return best_score;
-}
-
-#endif
 
 static void moonfish_clock(struct moonfish *ctx, struct timespec *ts)
 {
--