shithub: moonfish

Download patch

ref: b414f614dd3739bfad3a940921bb26e897301e49
parent: 294dd4480614df64edf438b966061584a5826ada
author: zamfofex <zamfofex@twdb.moe>
date: Wed Oct 23 06:40:44 EDT 2024

make small improvements to analysis TUI

--- a/chess.c
+++ b/chess.c
@@ -730,7 +730,7 @@
 	*fen = 0;
 }
 
-void moonfish_to_san(struct moonfish_chess *chess, struct moonfish_move *move, char *name)
+void moonfish_to_san(struct moonfish_chess *chess, struct moonfish_move *move, char *name, int check)
 {
 	static char names[] = "NBRQK";
 	
@@ -816,6 +816,15 @@
 	
 	*name++ = to_x + 'a';
 	*name++ = to_y + '1';
+	
+	if (moonfish_checkmate(&move->chess)) {
+		if (~check & 1) *name++ = '#';
+	}
+	else {
+		if (moonfish_check(&move->chess)) {
+			if (~check & 2) *name++ = '+';
+		}
+	}
 	
 	*name = 0;
 }
--- a/moonfish.h
+++ b/moonfish.h
@@ -183,8 +183,13 @@
 /* SAN parsing is very loose, so it will accept many forms, including UCI */
 /* on success, the parser will return 0, on failure, it will return 1 (and the move is unusable) */
 /* parsing is somewhat robust, so you can trust it won't succeed with an invalid move */
+/* the "check" parameter determines which check/checkmate annotations will be added: */
+/* '0' means both */
+/* '1' means check only */
+/* '2' means checkmate only */
+/* '3' means neither */
 int moonfish_from_san(struct moonfish_chess *chess, struct moonfish_move *move, char *name);
-void moonfish_to_san(struct moonfish_chess *chess, struct moonfish_move *move, char *name);
+void moonfish_to_san(struct moonfish_chess *chess, struct moonfish_move *move, char *name, int check);
 
 /* checks whether there is a valid move with the given from/to square indices */
 /* then, if so, generates the move and stores it in the given move pointer */
--- a/tools/analyse.c
+++ b/tools/analyse.c
@@ -165,7 +165,7 @@
 
 static void moonfish_scoresheet_move(struct moonfish_fancy *fancy, int i)
 {
-	struct moonfish_ply *ply;
+	struct moonfish_ply *ply, *prev;
 	int score;
 	int length;
 	
@@ -214,10 +214,11 @@
 		return;
 	}
 	
-	if (ply[-1].ephemeral) score = ply->score + ply[-1].score;
-	else score = ply->score + ply[-1].main->score;
+	prev = ply - 1;
+	if (!ply->ephemeral && prev->ephemeral) prev = prev->main;
+	score = ply->score + prev->score;
 	
-	if (ply[-1].main->checkmate != 0 || score > 200) {
+	if (prev->checkmate != 0 || score > 200) {
 		printf("\x1B[38;5;124m?? ");
 	}
 	else {
@@ -411,7 +412,7 @@
 						i = 1;
 						continue;
 					}
-					moonfish_to_san(&ply.chess, &move, san);
+					moonfish_to_san(&ply.chess, &move, san, 0);
 					length = strlen(san);
 					if (i + length > sizeof fancy->pv - 2) break;
 					ply.chess = move.chess;
@@ -686,7 +687,7 @@
 	
 	strcpy(fancy->plies[fancy->i].name, name);
 	if (move == NULL) return;
-	moonfish_to_san(&fancy->plies[fancy->i].chess, move, fancy->plies[fancy->i].san);
+	moonfish_to_san(&fancy->plies[fancy->i].chess, move, fancy->plies[fancy->i].san, 1);
 	
 	ply->chess = move->chess;
 	
--- a/tools/chat.c
+++ b/tools/chat.c
@@ -290,7 +290,7 @@
 			exit(1);
 		}
 		
-		moonfish_to_san(&chess, &move, name);
+		moonfish_to_san(&chess, &move, name, 0);
 		chess = move.chess;
 		moonfish_to_fen(&chess, fen);
 		
--