shithub: moonfish

Download patch

ref: b33c86b6de728a4b7aa41e131ffbf41618d91412
parent: 689c117d9d500f5ff967d717cfe2600e658bc51c
author: zamfofex <zamfofex@twdb.moe>
date: Mon Dec 9 18:04:19 EST 2024

add tapered evaluation

--- a/mini.c
+++ b/mini.c
@@ -76,4 +76,3 @@
 		if (!strcmp(line, "quit")) return 0;
 	}
 }
-
--- a/search.c
+++ b/search.c
@@ -62,32 +62,49 @@
 	long int node_count;
 };
 
-static short int moonfish_values[] = {0,0,0,0,103,124,116,101,104,120,104,108,106,118,107,112,122,131,118,123,170,183,170,167,243,249,232,223,0,0,0,0,293,328,339,338,338,342,357,365,338,368,378,391,362,386,397,401,377,389,418,419,367,395,416,424,347,367,394,400,249,342,356,371,373,383,375,379,390,403,404,398,395,405,409,415,395,408,414,426,400,416,423,432,409,419,422,423,383,403,409,407,378,390,384,394,592,607,611,616,586,602,606,606,594,608,604,608,610,619,619,623,631,636,642,645,643,651,655,655,652,655,661,663,649,652,653,654,1181,1168,1172,1190,1178,1189,1199,1195,1187,1197,1203,1200,1191,1208,1209,1214,1211,1213,1226,1231,1217,1224,1240,1240,1197,1189,1233,1238,1214,1227,1239,1243,-21,2,-24,-31,-6,-2,-6,-8,-17,-1,4,8,-12,10,18,23,6,32,34,33,20,44,40,29,5,34,27,16,-50,-1,-5,-10};
+static short int moonfish_values0[] = {0, 0, 0, 0, 56, 96, 84, 65, 61, 92, 74, 79, 58, 88, 83, 95, 69, 102, 96, 115, 82, 132, 156, 159, 258, 226, 262, 274, 0, 0, 0, 0, 262, 317, 317, 310, 323, 314, 337, 344, 321, 350, 356, 367, 341, 370, 371, 371, 366, 368, 406, 398, 361, 399, 433, 442, 338, 329, 420, 402, 194, 295, 237, 363, 356, 375, 360, 346, 382, 394, 396, 378, 386, 393, 387, 395, 382, 390, 392, 414, 380, 397, 421, 430, 406, 429, 426, 440, 374, 391, 413, 395, 343, 339, 291, 298, 456, 467, 469, 477, 427, 460, 462, 465, 440, 462, 447, 458, 447, 457, 454, 469, 474, 484, 496, 513, 491, 529, 533, 548, 523, 521, 552, 552, 564, 550, 535, 552, 1046, 1032, 1038, 1058, 1046, 1062, 1070, 1058, 1049, 1063, 1056, 1052, 1047, 1056, 1051, 1046, 1073, 1053, 1058, 1057, 1078, 1083, 1077, 1071, 1049, 1001, 1063, 1041, 1057, 1071, 1089, 1107, 20, 37, -21, -15, 18, 4, -61, -82, -63, -50, -84, -97, -93, -68, -82, -97, -77, -40, -24, -40, -31, 28, 52, 36, 44, 13, 53, 63, 163, 141, 61, 70};
+static short int moonfish_values1[] = {0, 0, 0, 0, 137, 142, 141, 145, 132, 137, 127, 134, 139, 138, 123, 119, 156, 152, 134, 125, 223, 214, 184, 178, 255, 269, 236, 215, 0, 0, 0, 0, 320, 318, 360, 369, 345, 378, 378, 387, 360, 388, 396, 416, 384, 403, 428, 436, 388, 413, 430, 439, 376, 396, 414, 416, 362, 399, 385, 408, 317, 372, 415, 387, 389, 391, 391, 410, 393, 402, 404, 420, 402, 416, 431, 431, 410, 429, 436, 437, 420, 437, 431, 440, 412, 421, 431, 425, 399, 420, 418, 423, 409, 418, 423, 430, 699, 708, 715, 717, 706, 704, 709, 708, 705, 712, 718, 716, 724, 732, 737, 734, 737, 740, 743, 738, 744, 738, 742, 734, 742, 749, 743, 746, 727, 736, 744, 738, 1255, 1256, 1247, 1234, 1248, 1249, 1246, 1271, 1276, 1274, 1307, 1305, 1308, 1332, 1342, 1359, 1309, 1358, 1374, 1384, 1318, 1333, 1375, 1386, 1327, 1388, 1381, 1410, 1338, 1346, 1357, 1352, -71, -42, -29, -42, -27, -11, 12, 17, -3, 12, 30, 39, 8, 30, 45, 55, 21, 48, 49, 52, 29, 49, 42, 30, -7, 42, 27, 10, -95, -30, -17, -26};
 
 static short int moonfish_score(struct moonfish_chess *chess)
 {
+	static int phases[] = {0, 1, 1, 2, 4, 0};
+	
 	int x, y;
 	int x1, y1;
 	int type, color, piece;
-	short int score;
+	int score0, score1;
+	int i;
+	int phase;
 	
-	score = 0;
+	score0 = 0;
+	score1 = 0;
+	phase = 0;
 	
 	for (y = 0 ; y < 8 ; y++) {
+		
 		for (x = 0 ; x < 8 ; x++) {
+			
 			piece = chess->board[(x + 1) + (y + 2) * 10];
 			if (piece == moonfish_empty) continue;
 			type = piece % 16 - 1;
 			color = piece / 16 - 1;
+			
 			x1 = x;
 			y1 = y;
+			
 			if (x1 > 3) x1 = 7 - x1;
 			if (color == 1) y1 = 7 - y1;
-			score -= moonfish_values[x1 + y1 * 4 + type * 32] * (color * 2 - 1);
+			
+			i = x1 + y1 * 4 + type * 32;
+			
+			score0 -= moonfish_values0[i] * (color * 2 - 1);
+			score1 -= moonfish_values1[i] * (color * 2 - 1);
+			
+			phase += phases[type];
 		}
 	}
 	
-	return score;
+	return (score0 * phase + score1 * (24 - phase)) / 24;
 }
 
 static void moonfish_discard(struct moonfish_node *node)
--