shithub: moonfish

Download patch

ref: c80f7beebc91dfce3d37874c79f698705d751dd9
parent: c173769001b5bd4ba69ea1fe6bcb8f984165cdf6
author: zamfofex <zamfofex@twdb.moe>
date: Sun Jan 21 12:29:12 EST 2024

improve minification

--- a/chess.c
+++ b/chess.c
@@ -432,13 +432,31 @@
 
 void moonfish_chess(struct moonfish_chess *chess)
 {
+	char pieces[] = {moonfish_rook, moonfish_knight, moonfish_bishop, moonfish_queen, moonfish_king, moonfish_bishop, moonfish_knight, moonfish_rook};
 	int x, y;
 	
+	chess->white = 1;
+	chess->castle.white_oo = 0;
+	chess->castle.white_ooo = 0;
+	chess->castle.black_oo = 0;
+	chess->castle.black_ooo = 0;
+	chess->score = 0;
+	chess->passing = 0;
+	
 	for (y = 0 ; y < 12 ; y++)
 	for (x = 0 ; x < 10 ; x++)
 		chess->board[x + y * 10] = moonfish_outside;
 	
-	moonfish_fen(chess, "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq");
+	for (x = 0 ; x < 8 ; x++)
+	{
+		chess->board[(x + 1) + 20] = pieces[x] | 0x10;
+		chess->board[(x + 1) + 90] = pieces[x] | 0x20;
+		chess->board[(x + 1) + 30] = moonfish_white_pawn;
+		chess->board[(x + 1) + 80] = moonfish_black_pawn;
+		
+		for (y = 4 ; y < 8 ; y++)
+			chess->board[(x + 1) + y * 10] = moonfish_empty;
+	}
 }
 
 static void moonfish_from_xy(struct moonfish_chess *chess, struct moonfish_move *move, int x0, int y0, int x1, int y1)
@@ -502,6 +520,8 @@
 	}
 }
 
+#ifndef moonfish_mini
+
 int moonfish_fen(struct moonfish_chess *chess, char *fen)
 {
 	int x, y;
@@ -592,6 +612,8 @@
 	
 	return 0;
 }
+
+#endif
 
 int moonfish_validate(struct moonfish_chess *chess)
 {
--- a/main.c
+++ b/main.c
@@ -77,6 +77,7 @@
 						return 1;
 					}
 				}
+#ifndef moonfish_mini
 				else if (!strcmp(arg, "depth"))
 				{
 					arg = strtok(NULL, "\r\n\t ");
@@ -88,6 +89,7 @@
 						return 1;
 					}
 				}
+#endif
 			}
 			
 			if (wtime < 0) wtime = 0;
@@ -94,7 +96,11 @@
 			if (btime < 0) btime = 0;
 			
 			if (depth >= 0)
+#ifdef moonfish_mini
+				exit(1);
+#else
 				score = moonfish_best_move_depth(ctx, &move, depth);
+#endif
 			else if (ctx->chess.white)
 				score = moonfish_best_move_time(ctx, &move, &depth, wtime, btime);
 			else
@@ -122,8 +128,13 @@
 				return 1;
 			}
 			
-			if (!strcmp(arg, "fen"))
+			if (!strcmp(arg, "startpos"))
 			{
+				moonfish_chess(&ctx->chess);
+			}
+#ifndef moonfish_mini
+			else if (!strcmp(arg, "fen"))
+			{
 				arg = strtok(NULL, "\r\n");
 				moonfish_fen(&ctx->chess, arg);
 				
@@ -140,10 +151,7 @@
 					strtok("", "\r\n\t ");
 				}
 			}
-			else if (!strcmp(arg, "startpos"))
-			{
-				moonfish_chess(&ctx->chess);
-			}
+#endif
 			else
 			{
 				fprintf(stderr, "malformed 'position' command\n");
--- a/moonfish.h
+++ b/moonfish.h
@@ -67,7 +67,6 @@
 };
 
 void moonfish_chess(struct moonfish_chess *chess);
-int moonfish_fen(struct moonfish_chess *chess, char *fen);
 
 void moonfish_moves(struct moonfish_chess *chess, struct moonfish_move *moves, unsigned char from);
 
@@ -74,7 +73,6 @@
 void moonfish_play(struct moonfish_chess *chess, struct moonfish_move *move);
 void moonfish_unplay(struct moonfish_chess *chess, struct moonfish_move *move);
 
-int moonfish_best_move_depth(struct moonfish *ctx, struct moonfish_move *move, int depth);
 int moonfish_best_move_time(struct moonfish *ctx, struct moonfish_move *move, int *depth, long int our_time, long int their_time);
 int moonfish_countdown(int score);
 
@@ -84,5 +82,12 @@
 
 int moonfish_validate(struct moonfish_chess *chess);
 int moonfish_check(struct moonfish_chess *chess);
+
+#ifndef moonfish_mini
+
+int moonfish_fen(struct moonfish_chess *chess, char *fen);
+int moonfish_best_move_depth(struct moonfish *ctx, struct moonfish_move *move, int depth);
+
+#endif
 
 #endif
--- a/search.c
+++ b/search.c
@@ -305,6 +305,8 @@
 	return best_score;
 }
 
+#ifndef moonfish_mini
+
 int moonfish_best_move_depth(struct moonfish *ctx, struct moonfish_move *best_move, int depth)
 {
 	int i;
@@ -320,6 +322,8 @@
 	
 	return score;
 }
+
+#endif
 
 #ifdef _WIN32
 
--