ref: 6112f03e9d0200943250e775a97210c46f5b5f6f
parent: 088335597c2f6b3acc13935811c4fbddb9814c13
author: zamfofex <zamfofex@twdb.moe>
date: Thu Jun 12 00:04:25 EDT 2025
use visit count for move selection instead
--- a/scripts/check.txt
+++ b/scripts/check.txt
@@ -3,103 +3,103 @@
bestmove b1c3
perft 0: 1
info depth 2 nodes 1024 score cp 101
-bestmove g2h3
+bestmove e2a6
perft 0: 1
info depth 2 nodes 1024 score cp 23
bestmove b4c4
perft 0: 1
info depth 2 nodes 1024 score cp -458
-bestmove c4c5
+bestmove f1f2
perft 0: 1
info depth 2 nodes 1024 score cp -458
-bestmove c5c4
+bestmove f8f7
perft 0: 1
info depth 2 nodes 1024 score cp 638
bestmove d7c8q
perft 0: 1
info depth 2 nodes 1024 score cp 16
-bestmove e2d1
+bestmove a1d1
perft 1: 20
info depth 2 nodes 1024 score cp 13
bestmove b1c3
perft 1: 48
info depth 2 nodes 1024 score cp 101
-bestmove g2h3
+bestmove e2a6
perft 1: 14
info depth 2 nodes 1024 score cp 23
bestmove b4c4
perft 1: 6
info depth 2 nodes 1024 score cp -458
-bestmove c4c5
+bestmove f1f2
perft 1: 6
info depth 2 nodes 1024 score cp -458
-bestmove c5c4
+bestmove f8f7
perft 1: 44
info depth 2 nodes 1024 score cp 638
bestmove d7c8q
perft 1: 46
info depth 2 nodes 1024 score cp 16
-bestmove e2d1
+bestmove a1d1
perft 2: 400
info depth 2 nodes 1024 score cp 13
bestmove b1c3
perft 2: 2039
info depth 2 nodes 1024 score cp 101
-bestmove g2h3
+bestmove e2a6
perft 2: 191
info depth 2 nodes 1024 score cp 23
bestmove b4c4
perft 2: 264
info depth 2 nodes 1024 score cp -458
-bestmove c4c5
+bestmove f1f2
perft 2: 264
info depth 2 nodes 1024 score cp -458
-bestmove c5c4
+bestmove f8f7
perft 2: 1486
info depth 2 nodes 1024 score cp 638
bestmove d7c8q
perft 2: 2079
info depth 2 nodes 1024 score cp 16
-bestmove e2d1
+bestmove a1d1
perft 3: 8902
info depth 3 nodes 4096 score cp 26
-bestmove b1c3
+bestmove g1f3
perft 3: 97862
-info depth 3 nodes 4096 score cp 198
+info depth 3 nodes 4096 score cp -12
bestmove e2a6
perft 3: 2812
-info depth 3 nodes 4096 score cp 52
+info depth 3 nodes 4096 score cp 119
bestmove b4f4
perft 3: 9467
-info depth 3 nodes 4096 score cp -443
-bestmove c4c5
+info depth 3 nodes 4096 score cp -481
+bestmove d2d4
perft 3: 9467
-info depth 3 nodes 4096 score cp -443
-bestmove c5c4
+info depth 3 nodes 4096 score cp -481
+bestmove d7d5
perft 3: 62379
info depth 3 nodes 4096 score cp 615
bestmove d7c8q
perft 3: 89890
-info depth 3 nodes 4096 score cp 11
-bestmove f1c1
+info depth 3 nodes 4096 score cp 15
+bestmove h2h3
perft 4: 197281
-info depth 4 nodes 65536 score cp -15
+info depth 4 nodes 65536 score cp -26
bestmove g1f3
perft 4: 4085603
-info depth 4 nodes 65536 score cp 228
+info depth 4 nodes 65536 score cp 80
bestmove e2a6
perft 4: 43238
-info depth 4 nodes 65536 score cp 55
+info depth 4 nodes 65536 score cp 21
bestmove b4f4
perft 4: 422333
-info depth 4 nodes 65536 score cp -194
+info depth 4 nodes 65536 score cp -343
bestmove c4c5
perft 4: 422333
-info depth 4 nodes 65536 score cp -194
+info depth 4 nodes 65536 score cp -343
bestmove c5c4
perft 4: 2103487
-info depth 4 nodes 65536 score cp 554
+info depth 4 nodes 65536 score cp 640
bestmove d7c8q
perft 4: 3894594
-info depth 4 nodes 65536 score cp 20
+info depth 4 nodes 65536 score cp -86
bestmove c3d5
--- a/scripts/compare.sh
+++ b/scripts/compare.sh
@@ -60,6 +60,6 @@
-each $protocol tc=inf/10+0.1 option.MultiPV=0 \
-openings $format file=openings.fen order=random \
-games 2 -rounds 1024 \
- -sprt elo0=0 elo1=12 alpha=0.05 beta=0.05 \
+ -sprt elo0=0 elo1=5 alpha=0.05 beta=0.05 \
-concurrency "$(getconf _NPROCESSORS_ONLN)" \
$cli_args
--- a/search.c
+++ b/search.c
@@ -136,7 +136,6 @@
static int moonfish_compare(const void *ax, const void *bx)
{const struct moonfish_node *a, *b;
-
a = ax;
b = bx;
if (!a->ignored && b->ignored) return -1;
@@ -335,7 +334,7 @@
{int i;
for (i = 0 ; i < node->count ; i++) {- if (node->children[i].visits < node->visits / node->count / 2) {+ if (node->children[i].visits < node->visits / node->count / 8) {moonfish_discard(node->children + i);
}
moonfish_clean(node->children + i);
@@ -342,6 +341,20 @@
}
}
+#ifndef moonfish_mini
+
+static int moonfish_compare_visits(const void *ax, const void *bx)
+{+ const struct moonfish_node *a, *b;
+ a = ax;
+ b = bx;
+ if (!a->ignored && b->ignored) return -1;
+ if (a->ignored && !b->ignored) return 1;
+ return b->visits - a->visits;
+}
+
+#endif
+
void moonfish_best_move(struct moonfish_root *root, struct moonfish_result *result, struct moonfish_options *options)
{struct moonfish_node *node;
@@ -367,16 +380,23 @@
moonfish_start(root, options->thread_count);
#endif
moonfish_clean(&root->node);
- if (root->node.count > 0) qsort(root->node.children, root->node.count, sizeof root->node, &moonfish_compare);
+ count = -1;
for (i = 0 ; i < root->node.count ; i++) {- node = root->node.children + i;
- for (j = 0 ; j < node->count ; j++) node->children[j].parent = node;
+ if (root->node.children[i].ignored) continue;
+ if (root->node.children[i].visits > count) {+ result->move = root->node.children[i].move;
+ count = root->node.children[i].visits;
+ }
}
- result->move = root->node.children[0].move;
result->score = root->node.score;
result->node_count = root->node.visits;
result->time = moonfish_clock() - time0;
#ifndef moonfish_mini
+ if (root->node.count > 0) qsort(root->node.children, root->node.count, sizeof root->node, &moonfish_compare_visits);
+ for (i = 0 ; i < root->node.count ; i++) {+ node = root->node.children + i;
+ for (j = 0 ; j < node->count ; j++) node->children[j].parent = node;
+ }
if (root->log != NULL) (*root->log)(result, root->data);
if (root->stop) break;
if (root->node.visits >= node_count) break;
@@ -475,7 +495,7 @@
struct moonfish_node *node;
struct moonfish_chess chess;
int j;
- int best_score;
+ int visits;
struct moonfish_node *best_node;
if (i >= root->node.count) *count = 0;
@@ -498,13 +518,13 @@
moves[j] = node->move;
moonfish_play(&chess, &node->move);
- best_score = INT_MAX;
+ visits = -1;
best_node = NULL;
for (i = 0 ; i < node->count ; i++) {if (node->children[i].ignored) continue;
- if (node->children[i].score < best_score) {+ if (node->children[i].visits > visits) {best_node = node->children + i;
- best_score = best_node->score;
+ visits = best_node->visits;
}
}
--
⑨