shithub: moonfish

Download patch

ref: 51f346310de5794bb7044fd7c64c8c8297420e23
parent: 690093ab209826a7428d6efbdbbf5675598dcca7
author: zamfofex <zamfofex@twdb.moe>
date: Sun Dec 8 21:01:37 EST 2024

make small style changes

--- a/chess.c
+++ b/chess.c
@@ -1,6 +1,8 @@
 /* moonfish is licensed under the AGPL (v3 or later) */
 /* copyright 2023, 2024 zamfofex */
 
+#include <string.h>
+
 #include "moonfish.h"
 
 static void moonfish_force_promotion(struct moonfish_chess *chess, struct moonfish_move **moves, int from, int to, int promotion)
@@ -136,12 +138,12 @@
 {
 	int color;
 	
-	color = chess->board[from] & 0xF0;
-	if ((color == 0x10 && from < 80) || (color == 0x20 && from > 40)) {
+	if (to > 30 && to < 90) {
 		moonfish_force_move(chess, moves, from, to);
 		return;
 	}
 	
+	color = chess->board[from] & 0xF0;
 	moonfish_force_promotion(chess, moves, from, to, color | moonfish_queen);
 	moonfish_force_promotion(chess, moves, from, to, color | moonfish_rook);
 	moonfish_force_promotion(chess, moves, from, to, color | moonfish_bishop);
@@ -153,9 +155,7 @@
 	int dy;
 	
 	if (to == chess->passing) {
-		
 		dy = chess->white ? 10 : -10;
-		
 		moonfish_force_move(chess, moves, from, to);
 		(*moves)[-1].chess.board[to - dy] = moonfish_empty;
 		return;
@@ -173,9 +173,7 @@
 	dy = chess->white ? 10 : -10;
 	
 	if (chess->board[from + dy] == moonfish_empty) {
-		
 		moonfish_pawn_moves(chess, moves, from, from + dy);
-		
 		if ((chess->white ? from < 40 : from > 80) && chess->board[from + dy * 2] == moonfish_empty) {
 			moonfish_force_move(chess, moves, from, from + dy * 2);
 			(*moves)[-1].chess.passing = from + dy;
@@ -331,23 +329,6 @@
 	}
 }
 
-int moonfish_move(struct moonfish_chess *chess, struct moonfish_move *found, int from, int to)
-{
-	struct moonfish_move moves[32];
-	int i, count;
-	
-	count = moonfish_moves(chess, moves, from);
-	
-	for (i = 0 ; i < count ; i++) {
-		if (moves[i].to == to && moonfish_validate(&moves[i].chess)) {
-			*found = moves[i];
-			return 0;
-		}
-	}
-	
-	return 1;
-}
-
 int moonfish_finished(struct moonfish_chess *chess)
 {
 	struct moonfish_move moves[32];
@@ -391,7 +372,22 @@
 
 #ifndef moonfish_mini
 
-#include <string.h>
+int moonfish_move(struct moonfish_chess *chess, struct moonfish_move *found, int from, int to)
+{
+	struct moonfish_move moves[32];
+	int i, count;
+	
+	count = moonfish_moves(chess, moves, from);
+	
+	for (i = 0 ; i < count ; i++) {
+		if (moves[i].to == to && moonfish_validate(&moves[i].chess)) {
+			*found = moves[i];
+			return 0;
+		}
+	}
+	
+	return 1;
+}
 
 int moonfish_from_fen(struct moonfish_chess *chess, char *fen)
 {
--- a/moonfish.h
+++ b/moonfish.h
@@ -67,7 +67,7 @@
 	/* 10 x 12 array board representation */
 	unsigned char board[120];
 	
-	/* booleans representing castling rights */
+	/* flags representing castling rights */
 	unsigned char oo[2], ooo[2];
 	
 	/* square index of a pawn that may be captured via e.p. */
@@ -190,7 +190,7 @@
 /* sets the state's position */
 void moonfish_reroot(struct moonfish_root *root, struct moonfish_chess *chess);
 
-/* get the state's position (it is stored in the given position pointer) */
+/* gets the state's position (it is stored in the given position pointer) */
 void moonfish_root(struct moonfish_root *root, struct moonfish_chess *chess);
 
 /* creates a new state (with the initial position) */
--- a/search.c
+++ b/search.c
@@ -225,29 +225,9 @@
 	return node;
 }
 
-#ifdef moonfish_no_threads
-
 static void moonfish_propagate(struct moonfish_node *node)
 {
 	int i;
-	
-	while (node != NULL) {
-		node->visits++;
-		node->score = SHRT_MIN;
-		for (i = 0 ; i < node->count ; i++) {
-			if (node->score < -node->children[i].score) {
-				node->score = -node->children[i].score;
-			}
-		}
-		node = node->parent;
-	}
-}
-
-#else
-
-static void moonfish_propagate(struct moonfish_node *node)
-{
-	int i;
 	short int score, child_score;
 	
 	while (node != NULL) {
@@ -257,12 +237,14 @@
 			if (score < child_score) score = child_score;
 		}
 		node->score = score;
+#ifdef moonfish_no_threads
+		node->visits++;
+#else
 		atomic_fetch_add(&node->visits, 1);
+#endif
 		node = node->parent;
 	}
 }
-
-#endif
 
 static void moonfish_propagate_bounds(struct moonfish_node *node, int i)
 {
--