shithub: moonfish

Download patch

ref: 34d627b5ec5914b22b0e4a2596f5daf8632a199b
parent: c26929cb40221d6efc9f3a8fc83024513cba8540
author: zamfofex <zamfofex@twdb.moe>
date: Sun Jun 1 09:25:51 EDT 2025

make small fixes and improvements

--- a/chess.c
+++ b/chess.c
@@ -220,11 +220,7 @@
 	chess->ooo[1] = 1;
 	chess->passing = 0;
 	
-	for (y = 0 ; y < 12 ; y++) {
-		for (x = 0 ; x < 10 ; x++) {
-			chess->board[x + y * 10] = moonfish_outside;
-		}
-	}
+	for (x = 0 ; x < 120 ; x++) chess->board[x] = moonfish_outside;
 	
 	for (x = 0 ; x < 8 ; x++) {
 		chess->board[x + 21] = pieces[x] | 0x10;
@@ -440,6 +436,7 @@
 		if (ch == 'k') type = moonfish_king;
 		if (type == 0) return 1;
 		
+		if (x >= 8 || y >= 8) return 1;
 		chess->board[(x + 1) + (9 - y) * 10] = type | color;
 		
 		x++;
@@ -534,8 +531,8 @@
 				other = *chess;
 				moonfish_play(&other, moves + i);
 				if (!moonfish_validate(&other)) continue;
-				if (check && !moonfish_check(chess)) continue;
-				if (check == 2 && !moonfish_checkmate(chess)) continue;
+				if (check && !moonfish_check(&other)) continue;
+				if (check == 2 && !moonfish_checkmate(&other)) continue;
 				if (found) return 1;
 				found = 1;
 				*move = moves[i];
--