shithub: moonfish

Download patch

ref: ed32fab5682c03b8d30df18a1f47eb1ed0c62fed
parent: 9571174370478fb8beb2b3319142b60986ab2252
author: zamfofex <zamfofex@twdb.moe>
date: Sun Dec 17 03:48:48 EST 2023

fix Lichess integration move bugs

--- a/chess.c
+++ b/chess.c
@@ -409,6 +409,11 @@
 	moonfish_fen(chess, "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq");
 }
 
+static void moonfish_from_xy(struct moonfish_chess *chess, struct moonfish_move *move, int x0, int y0, int x1, int y1)
+{
+	moonfish_create_move(chess, &move, (x0 + 1) + (y0 + 2) * 10, (x1 + 1) + (y1 + 2) * 10);
+}
+
 void moonfish_from_uci(struct moonfish_chess *chess, struct moonfish_move *move, char *name)
 {
 	int x0, y0;
@@ -420,12 +425,12 @@
 	x1 = name[2] - 'a';
 	y1 = name[3] - '1';
 	
-	moonfish_create_move(chess, &move, (x0 + 1) + (y0 + 2) * 10, (x1 + 1) + (y1 + 2) * 10);
+	moonfish_from_xy(chess, move, x0, y0, x1, y1);
 	if (move->piece % 16 == moonfish_king && x0 == 4)
 	{
 		if (x1 == 0) x1 = 2;
 		if (x1 == 7) x1 = 6;
-		moonfish_create_move(chess, &move, (x0 + 1) + (y0 + 2) * 10, (x1 + 1) + (y1 + 2) * 10);
+		moonfish_from_xy(chess, move, x0, y0, x1, y1);
 	}
 	
 	color = chess->white ? 0x10 : 0x20;
@@ -453,7 +458,10 @@
 	
 	if (move->promotion != move->piece)
 	{
-		name[4] = 'q';
+		if (move->promotion % 16 == moonfish_queen) name[4] = 'q';
+		if (move->promotion % 16 == moonfish_rook) name[4] = 'r';
+		if (move->promotion % 16 == moonfish_bishop) name[4] = 'b';
+		if (move->promotion % 16 == moonfish_knight) name[4] = 'n';
 		name[5] = 0;
 	}
 	else
--