shithub: moonfish

Download patch

ref: 0f81d1a403ba557b722ada5d460134412b858a72
parent: e6fc4ccbf8a7519627fdaf412ca0829d2cecb30b
author: zamfofex <zamfofex@twdb.moe>
date: Sun Dec 24 07:18:19 EST 2023

also inform score

--- a/main.c
+++ b/main.c
@@ -16,6 +16,7 @@
 	struct moonfish_move move;
 	char name[6];
 	long int wtime, btime, *xtime;
+	int score;
 	
 	if (argc > 1)
 	{
@@ -80,10 +81,14 @@
 			if (btime < 0) btime = 0;
 			
 			if (ctx->chess.white)
-				moonfish_best_move(ctx, &move, wtime, btime);
+				score = moonfish_best_move(ctx, &move, wtime, btime);
 			else
-				moonfish_best_move(ctx, &move, btime, wtime);
+				score = moonfish_best_move(ctx, &move, btime, wtime);
 			
+			if (score >= moonfish_omega || score <= -moonfish_omega)
+				printf("info score mate %d\n", moonfish_countdown(score));
+			else
+				printf("info score cp %d\n", score);
 			moonfish_to_uci(name, &move);
 			printf("bestmove %s\n", name);
 		}
--- a/moonfish.h
+++ b/moonfish.h
@@ -30,6 +30,7 @@
 	moonfish_outside = 0,
 	moonfish_empty = 0xFF,
 	
+	moonfish_depth = 50,
 	moonfish_omega = 5000000
 };
 
@@ -72,6 +73,7 @@
 void moonfish_unplay(struct moonfish_chess *chess, struct moonfish_move *move);
 
 int moonfish_best_move(struct moonfish *ctx, struct moonfish_move *move, long int our_time, long int their_time);
+int moonfish_countdown(int score);
 
 void moonfish_from_uci(struct moonfish_chess *chess, struct moonfish_move *move, char *name);
 void moonfish_to_uci(char *name, struct moonfish_move *move);
--- a/search.c
+++ b/search.c
@@ -40,7 +40,7 @@
 
 #include "moonfish.h"
 
-static int moonfish_search(struct moonfish_chess *chess, int alpha, int beta, int depth)
+static int moonfish_search(struct moonfish_chess *chess, int alpha, int beta, int depth, int qdepth, int i)
 {
 	int x, y;
 	struct moonfish_move moves[32];
@@ -47,12 +47,12 @@
 	struct moonfish_move *move;
 	int score;
 	
-	if (depth <= 0)
+	if (i >= depth)
 	{
 		score = chess->score;
 		if (!chess->white) score *= -1;
 		
-		if (depth <= -4) return score;
+		if (i >= depth + qdepth) return score;
 		if (score >= beta) return beta;
 		if (score > alpha) alpha = score;
 	}
@@ -64,16 +64,16 @@
 		
 		for (move = moves ; move->piece != moonfish_outside ; move++)
 		{
-			if (depth <= 0)
+			if (i >= depth)
 			if (move->captured == moonfish_empty)
 			if (move->promotion == move->piece)
 				continue;
 			
 			if (move->captured % 16 == moonfish_king)
-				return moonfish_omega * (depth + 10);
+				return moonfish_omega * (moonfish_depth - i);
 			
 			moonfish_play(chess, move);
-			score = -moonfish_search(chess, -beta, -alpha, depth - 1);
+			score = -moonfish_search(chess, -beta, -alpha, depth, qdepth, i + 1);
 			moonfish_unplay(chess, move);
 			
 			if (score >= beta) return beta;
@@ -84,6 +84,14 @@
 	return alpha;
 }
 
+int moonfish_countdown(int score)
+{
+	score /= -moonfish_omega;
+	if (score < 0) score += moonfish_depth;
+	else score -= moonfish_depth;
+	return score;
+}
+
 struct moonfish_search_info
 {
 	pthread_t thread;
@@ -97,7 +105,7 @@
 {
 	struct moonfish_search_info *info;
 	info = data;
-	info->score = -moonfish_search(&info->chess, -100 * moonfish_omega, 100 * moonfish_omega, info->depth);
+	info->score = -moonfish_search(&info->chess, -100 * moonfish_omega, 100 * moonfish_omega, info->depth, 4, 0);
 	return moonfish_value;
 }
 
--