ref: c7714a96d1f1ea392716b5aa219c839a590408d8
parent: 6ce47f5b11173b9e0392d461333c4173564be2fe
author: zamfofex <zamfofex@twdb.moe>
date: Tue Apr 30 23:12:43 EDT 2024
replace PST (use texel-tuner instead!) with data from Expositor: https://expositor.dev (thank you!)
--- a/.gitignore
+++ b/.gitignore
@@ -33,3 +33,8 @@
!/tools/https.c
!/tools/perft.c
!/tools/book.c
+!/extras
+!/extras/texel-tuner
+!/extras/moonfish.cc
+!/extras/moonfish.hh
+!/extras/config.h
--- /dev/null
+++ b/.gitmodules
@@ -1,0 +1,3 @@
+[submodule "extras/texel-tuner"]
+ path = extras/texel-tuner
+ url = https://github.com/GediminasMasaitis/texel-tuner
--- a/chess.c
+++ b/chess.c
@@ -3,63 +3,61 @@
#include "moonfish.h"
-static int moonfish_piece_scores[] = {82, 337, 365, 477, 1025, 0};-
-static signed char moonfish_piece_square_scores[] =
+static int moonfish_piece_square_scores[] =
{0, 0, 0, 0,
- 81, 93, 84, 43,
- 48, 41, 16, -13,
- 22, 9, 15, -18,
- 14, 0, 4, -26,
- -3, 0, 14, -19,
- -19, 2, 18, -28,
+ 232, 240, 242, 229,
+ 172, 171, 176, 148,
+ 128, 121, 129, 114,
+ 119, 111, 116, 98,
+ 102, 108, 116, 95,
+ 95, 109, 121, 90,
0, 0, 0, 0,
- 6, -65, -52, -128,
- 29, 67, -17, -45,
- 74, 83, 66, -1,
- 45, 44, 17, 6,
- 20, 17, 12, -10,
- 14, 14, 8, -19,
- -2, 3, -33, -24,
- -25, -43, -20, -64,
+ 330, 318, 308, 224,
+ 360, 360, 324, 314,
+ 386, 372, 366, 334,
+ 371, 367, 352, 338,
+ 347, 351, 339, 322,
+ 337, 338, 322, 297,
+ 319, 311, 301, 287,
+ 299, 296, 289, 255,
- -31, -62, 5, -18,
- 8, 20, 17, -36,
- 37, 46, 37, -9,
- 43, 28, 6, -3,
- 30, 12, 11, -1,
- 14, 21, 16, 5,
- 3, 18, 24, 2,
- -17, -13, -21, -27,
+ 358, 357, 353, 339,
+ 368, 366, 363, 343,
+ 386, 381, 378, 372,
+ 388, 378, 376, 362,
+ 377, 373, 366, 358,
+ 370, 369, 363, 355,
+ 352, 356, 364, 350,
+ 331, 327, 326, 337,
- 57, 20, 36, 37,
- 71, 62, 29, 35,
- 26, 35, 40, 5,
- 25, 21, -9, -22,
- 4, -9, -10, -29,
- -7, -8, -15, -39,
- -5, -4, -11, -57,
- 16, 4, -25, -22,
+ 583, 577, 576, 578,
+ 593, 593, 585, 587,
+ 588, 582, 579, 577,
+ 574, 571, 569, 562,
+ 554, 553, 552, 542,
+ 540, 536, 535, 522,
+ 537, 532, 524, 505,
+ 553, 545, 529, 513,
- 35, 36, 21, 8,
- -7, 26, -5, 15,
- 18, 31, 15, 22,
- -8, 0, -14, -13,
- -6, -6, -11, -6,
- -3, -4, 8, -4,
- 5, 13, -5, -17,
- -2, -17, -24, -25,
+ 1117, 1111, 1099, 1077,
+ 1124, 1121, 1095, 1097,
+ 1136, 1124, 1118, 1103,
+ 1114, 1113, 1098, 1107,
+ 1080, 1088, 1091, 1099,
+ 1076, 1080, 1077, 1069,
+ 1076, 1075, 1069, 1062,
+ 1065, 1050, 1050, 1071,
- -35, -9, 12, -26,
- -7, -12, -19, 0,
- -18, 4, 23, -15,
- -28, -18, -17, -26,
- -42, -35, -17, -50,
- -45, -26, -14, -20,
- -53, -12, 8, 4,
- -23, -8, 30, 0,
+ 30, 37, 43, -17,
+ 33, 36, 52, 15,
+ 24, 36, 42, 19,
+ 7, 17, 20, 0,
+ -5, 1, -1, -17,
+ -15, -10, -9, -22,
+ -37, -14, -1, -1,
+ -14, -21, 16, -2,
};
void moonfish_force_move(struct moonfish_chess *chess, struct moonfish_move *move, unsigned char from, unsigned char to)
@@ -296,7 +294,7 @@
if (x < 4) x = 3 - x;
else x %= 4;
- score = moonfish_piece_scores[type] + moonfish_piece_square_scores[x + y * 4 + type * 32];
+ score = moonfish_piece_square_scores[x + y * 4 + type * 32];
if (color != 0) score *= -1;
return score;
--- /dev/null
+++ b/extras/config.h
@@ -1,0 +1,15 @@
+/* moonfish is licensed under the AGPL (v3 or later) */
+/* copyright 2024 zamfofex */
+
+#ifndef MOONFISH_TEXEL_TUNER_CONFIG
+#define MOONFISH_TEXEL_TUNER_CONFIG
+
+#include "moonfish.hh"
+
+using TuneEval = moonfish::MoonfishEval;
+constexpr int data_load_thread_count = 4;
+constexpr int thread_count = 4;
+constexpr static bool print_data_entries = false;
+constexpr static int data_load_print_interval = 10000;
+
+#endif
--- /dev/null
+++ b/extras/moonfish.cc
@@ -1,0 +1,98 @@
+/* moonfish is licensed under the AGPL (v3 or later) */
+/* copyright 2024 zamfofex */
+
+#include <math.h>
+#include <stdio.h>
+
+#include "moonfish.hh"
+
+extern "C"
+{+#include "../moonfish.h"
+}
+
+struct moonfish_trace
+{+ int values[32 * 6][2];
+};
+
+parameters_t moonfish::MoonfishEval::get_initial_parameters(void)
+{+ static int scores[6 * 32] = {0};+ parameters_t parameters;
+ get_initial_parameter_array(parameters, scores, 6 * 32);
+ return parameters;
+}
+
+void moonfish::MoonfishEval::print_parameters(parameters_t parameters)
+{+ int x, y, type;
+ long int l;
+
+ printf("static int moonfish_piece_square_scores[] =\n{\n");+
+ for (type = 0 ; type < 6 ; type++)
+ {+ for (y = 0 ; y < 8 ; y++)
+ {+ printf("\t");+ for (x = 0 ; x < 4 ; x++)
+ {+ l = lround(parameters[x + y * 4 + type * 32]);
+ printf("%ld,", l);+ if (x != 7) printf(" ");+ }
+ printf("\n");+ }
+ if (type != 5) printf("\n");+ }
+
+ printf("};\n");+}
+
+
+EvalResult moonfish::MoonfishEval::get_fen_eval_result(std::string fen)
+{+ struct moonfish_chess chess;
+ int x0, y0;
+ int x, y;
+ struct moonfish_trace trace = {0};+ unsigned char type, color;
+ unsigned char piece;
+ EvalResult result;
+
+ moonfish_chess(&chess);
+ moonfish_fen(&chess, (char *) fen.c_str());
+
+ for (y0 = 0 ; y0 < 8 ; y0++)
+ for (x0 = 0 ; x0 < 8 ; x0++)
+ {+ x = x0;
+ y = y0;
+
+ piece = chess.board[(x + 1) + (y + 2) * 10];
+ if (piece == moonfish_empty) continue;
+
+ type = (piece % 16) - 1;
+ color = (piece / 16) - 1;
+
+ if (color == 0) y = 7 - y;
+
+ if (x < 4) x = 3 - x;
+ else x %= 4;
+
+ trace.values[x + y * 4 + type * 32][color]++;
+ }
+
+ get_coefficient_array(result.coefficients, trace.values, 6 * 32);
+ result.score = 0;
+ result.endgame_scale = 0;
+ return result;
+}
+
+EvalResult moonfish::MoonfishEval::get_external_eval_result(chess::Board board)
+{+ (void) board;
+ EvalResult result;
+ return result;
+}
--- /dev/null
+++ b/extras/moonfish.hh
@@ -1,0 +1,39 @@
+/* moonfish is licensed under the AGPL (v3 or later) */
+/* copyright 2024 zamfofex */
+
+#ifndef MOONFISH_TEXEL_TUNER
+#define MOONFISH_TEXEL_TUNER
+
+#define TAPERED 0
+
+#include <string>
+
+#include "texel-tuner/src/base.h"
+#include "texel-tuner/src/external/chess.hpp"
+
+namespace moonfish
+{+ class MoonfishEval
+ {+ public:
+ constexpr static bool includes_additional_score = true;
+ constexpr static bool supports_external_chess_eval = false;
+ constexpr static bool retune_from_zero = true;
+ constexpr static tune_t preferred_k = 2.1;
+ constexpr static int32_t max_epoch = 5001;
+ constexpr static bool enable_qsearch = false;
+ constexpr static bool filter_in_check = false;
+ constexpr static tune_t initial_learning_rate = 1;
+ constexpr static int32_t learning_rate_drop_interval = 10000;
+ constexpr static tune_t learning_rate_drop_ratio = 1;
+ constexpr static bool print_data_entries = false;
+ constexpr static int32_t data_load_print_interval = 10000;
+
+ static parameters_t get_initial_parameters(void);
+ static EvalResult get_fen_eval_result(std::string fen);
+ static EvalResult get_external_eval_result(chess::Board board);
+ static void print_parameters(parameters_t parameters);
+ };
+}
+
+#endif
--- a/makefile
+++ b/makefile
@@ -2,10 +2,12 @@
# copyright 2023, 2024 zamfofex
CFLAGS ?= -ansi -O3 -Wall -Wextra -Wpedantic
+CXXFLAGS ?= -std=c++20 -O3 -Wall -Wextra -Wpedantic
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
cc := $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
+cxx := $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)
moonfish_cc := $(cc) -pthread -D_POSIX_C_SOURCE=199309L
tools_cc := $(cc) -pthread -D_POSIX_C_SOURCE=200809L
@@ -34,6 +36,21 @@
uci-ugi: $(ugi_src)
$(tools_cc) -o $@ $(filter %.c,$^)
+
+tuner: \
+ extras/texel-tuner/src/main.cpp \
+ extras/texel-tuner/src/tuner.cpp \
+ extras/texel-tuner/src/threadpool.cpp \
+ extras/texel-tuner/src/base.h \
+ extras/texel-tuner/src/threadpool.h \
+ extras/texel-tuner/src/tuner.h \
+ extras/moonfish.cc \
+ extras/moonfish.hh \
+ extras/config.h \
+ chess.c moonfish.h
+ $(RM) extras/texel-tuner/src/config.h
+ $(cc) -c chess.c
+ $(cxx) -pthread -iquote extras -o $@ $(filter %.cc %.cpp,$^) chess.o
clean:
git clean -fdx
--
⑨