From 68e3af24bfe424163ee1cd7e23e2eaff2e1f3c9a Mon Sep 17 00:00:00 2001 From: TheRealGioviok <425gioviok@gmail.com> Date: Sun, 1 Feb 2026 21:15:13 +0100 Subject: [PATCH 1/9] Bench: 17344937 --- src/eval_constants.hpp | 209 +++++++++++++++++++------------------- src/eval_types.hpp | 16 +++ src/evaltune_main.cpp | 8 +- src/evaluation.cpp | 12 +++ src/tuning/graph.cpp | 22 ++++ src/tuning/operations.hpp | 1 + src/tuning/value.cpp | 10 ++ src/tuning/value.hpp | 3 + 8 files changed, 178 insertions(+), 103 deletions(-) diff --git a/src/eval_constants.hpp b/src/eval_constants.hpp index 44b5cf2a..1e5a9317 100644 --- a/src/eval_constants.hpp +++ b/src/eval_constants.hpp @@ -5,171 +5,176 @@ namespace Clockwork { // clang-format off -inline const PParam PAWN_MAT = S(169, 148); -inline const PParam KNIGHT_MAT = S(693, 425); -inline const PParam BISHOP_MAT = S(735, 433); -inline const PParam ROOK_MAT = S(600, 463); -inline const PParam QUEEN_MAT = S(1410, 694); -inline const PParam TEMPO_VAL = S(63, 13); +inline const PParam PAWN_MAT = S(266, 126); +inline const PParam KNIGHT_MAT = S(925, 328); +inline const PParam BISHOP_MAT = S(971, 350); +inline const PParam ROOK_MAT = S(883, 305); +inline const PParam QUEEN_MAT = S(1889, 361); +inline const PParam TEMPO_VAL = S(77, 2); -inline const PParam BISHOP_PAIR_VAL = S(76, 157); -inline const PParam ROOK_OPEN_VAL = S(109, -22); -inline const PParam ROOK_SEMIOPEN_VAL = S(45, 17); +inline const PParam BISHOP_PAIR_VAL = S(154, 111); +inline const PParam ROOK_OPEN_VAL = S(110, -16); +inline const PParam ROOK_SEMIOPEN_VAL = S(58, 13); -inline const PParam DOUBLED_PAWN_VAL = S(-13, -57); -inline const PParam ISOLATED_PAWN_VAL = S(-22, -18); +inline const PParam DOUBLED_PAWN_VAL = S(-39, -46); +inline const PParam ISOLATED_PAWN_VAL = S(-28, -12); -inline const PParam POTENTIAL_CHECKER_VAL = S(-60, -7); -inline const PParam OUTPOST_KNIGHT_VAL = S(44, 49); -inline const PParam OUTPOST_BISHOP_VAL = S(57, 26); +inline const PParam POTENTIAL_CHECKER_VAL = S(-77, -1); +inline const PParam OUTPOST_KNIGHT_VAL = S(69, 30); +inline const PParam OUTPOST_BISHOP_VAL = S(83, 12); -inline const PParam PAWN_PUSH_THREAT_KNIGHT = S(44, 6); -inline const PParam PAWN_PUSH_THREAT_BISHOP = S(56, -20); -inline const PParam PAWN_PUSH_THREAT_ROOK = S(34, 43); -inline const PParam PAWN_PUSH_THREAT_QUEEN = S(69, -47); +inline const PParam PAWN_PUSH_THREAT_KNIGHT = S(48, 6); +inline const PParam PAWN_PUSH_THREAT_BISHOP = S(54, -18); +inline const PParam PAWN_PUSH_THREAT_ROOK = S(55, 27); +inline const PParam PAWN_PUSH_THREAT_QUEEN = S(72, -71); inline const std::array PAWN_PHALANX = { - S(19, -4), S(45, 17), S(64, 46), S(155, 124), S(438, 152), S(603, 501), + S(17, 3), S(58, 17), S(87, 33), S(227, 81), S(666, 156), S(701, 438), }; inline const std::array DEFENDED_PAWN = { - S(62, 19), S(50, 17), S(62, 43), S(149, 98), S(511, -24), + S(78, 18), S(64, 14), S(91, 30), S(216, 77), S(561, 59), }; inline const std::array PASSED_PAWN = { - S(-89, -93), S(-82, -77), S(-45, 6), S(22, 90), S(120, 205), S(317, 276), + S(-176, -86), S(-165, -77), S(-81, -18), S(34, 50), S(220, 147), S(524, 191), }; inline const std::array DEFENDED_PASSED_PUSH = { - S(34, -37), S(37, -10), S(28, 17), S(18, 68), S(82, 137), S(180, 224), + S(4, -21), S(29, -1), S(64, 11), S(123, 42), S(308, 61), S(495, 141), }; inline const std::array BLOCKED_PASSED_PAWN = { - S(20, -33), S(5, 8), S(-3, -14), S(-10, -37), S(-30, -78), S(-279, -102), + S(-5, -24), S(0, -1), S(-23, -18), S(-42, -36), S(-104, -71), S(-471, -97), }; inline const std::array FRIENDLY_KING_PASSED_PAWN_DISTANCE = { - S(0, 0), S(15, 113), S(-8, 92), S(-10, 39), S(-6, 9), S(4, 5), S(43, 3), S(14, -7), + S(0, 0), S(138, 86), S(103, 65), S(38, 37), S(10, 19), S(18, 15), S(58, 16), S(38, 16), }; inline const std::array ENEMY_KING_PASSED_PAWN_DISTANCE = { - S(0, 0), S(-358, -6), S(-33, 17), S(-12, 45), S(25, 75), S(43, 89), S(58, 92), S(36, 83), + S(0, 0), S(-280, -12), S(31, 28), S(37, 38), S(93, 56), S(111, 63), S(110, 69), S(112, 51), }; inline const std::array KNIGHT_MOBILITY = { - S(82, -62), S(163, 104), S(205, 190), S(237, 223), S(281, 236), S(309, 269), S(342, 265), S(378, 272), S(424, 211), + S(151, -15), S(276, 122), S(343, 182), S(389, 204), S(441, 211), S(481, 235), S(517, 232), S(558, 238), S(577, 194), }; inline const std::array BISHOP_MOBILITY = { - S(111, -62), S(160, 119), S(222, 173), S(252, 216), S(280, 245), S(299, 265), S(309, 281), S(325, 288), S(335, 300), S(357, 289), S(373, 284), S(420, 249), S(429, 250), S(479, 210), + S(171, 5), S(254, 141), S(343, 162), S(390, 186), S(430, 204), S(458, 213), S(473, 226), S(495, 230), S(512, 236), S(532, 228), S(546, 230), S(572, 202), S(571, 212), S(565, 200), }; inline const std::array ROOK_MOBILITY = { - S(358, 146), S(285, 320), S(313, 340), S(332, 346), S(344, 358), S(351, 368), S(359, 376), S(369, 375), S(377, 381), S(390, 379), S(404, 377), S(415, 376), S(423, 373), S(435, 360), S(540, 269), + S(490, 166), S(467, 305), S(505, 312), S(532, 308), S(550, 312), S(562, 318), S(575, 320), S(589, 317), S(601, 322), S(615, 321), S(631, 320), S(642, 323), S(644, 326), S(643, 313), S(698, 240), }; inline const std::array QUEEN_MOBILITY = { - S(593, 310), S(754, 270), S(782, 385), S(802, 504), S(820, 552), S(830, 599), S(837, 629), S(845, 640), S(850, 663), S(855, 674), S(861, 680), S(867, 683), S(875, 680), S(877, 683), S(883, 676), S(881, 677), S(882, 674), S(890, 664), S(897, 653), S(914, 636), S(936, 605), S(961, 577), S(1011, 526), S(1105, 431), S(1159, 376), S(1234, 334), S(1317, 280), S(1096, 367), + S(849, 311), S(1079, 77), S(1121, 255), S(1155, 370), S(1176, 456), S(1188, 547), S(1199, 585), S(1212, 577), S(1218, 616), S(1227, 616), S(1238, 609), S(1250, 593), S(1259, 583), S(1261, 594), S(1268, 578), S(1266, 585), S(1269, 577), S(1275, 569), S(1284, 553), S(1295, 544), S(1297, 528), S(1303, 507), S(1298, 512), S(1279, 461), S(1246, 472), S(1239, 446), S(1180, 504), S(1173, 417), }; inline const std::array KING_MOBILITY = { - S(490, -194), S(112, -130), S(36, -47), S(22, -8), S(-1, 1), S(-22, 7), S(-26, 18), S(-44, 32), S(-43, 2), + S(482, 10), S(93, -89), S(20, -6), S(13, 20), S(-9, 21), S(-20, 10), S(-14, 7), S(-13, -0), S(7, -42), }; inline const std::array PT_INNER_RING_ATTACKS = { - S(12, -13), S(17, -17), S(14, -13), S(7, -9), S(3, 232), + S(10, -5), S(11, -13), S(10, -10), S(4, -5), S(1, 97), }; inline const std::array PT_OUTER_RING_ATTACKS = { - S(4, -2), S(7, -10), S(6, -8), S(6, -5), S(7, 454), + S(6, -3), S(4, -8), S(4, -7), S(4, -4), S(6, 300), }; -inline const PParam PAWN_THREAT_KNIGHT = S(233, 67); -inline const PParam PAWN_THREAT_BISHOP = S(213, 111); -inline const PParam PAWN_THREAT_ROOK = S(216, 91); -inline const PParam PAWN_THREAT_QUEEN = S(182, -53); +inline const PParam PAWN_THREAT_KNIGHT = S(282, 33); +inline const PParam PAWN_THREAT_BISHOP = S(281, 46); +inline const PParam PAWN_THREAT_ROOK = S(287, 22); +inline const PParam PAWN_THREAT_QUEEN = S(216, -134); -inline const PParam KNIGHT_THREAT_BISHOP = S(124, 75); -inline const PParam KNIGHT_THREAT_ROOK = S(256, 19); -inline const PParam KNIGHT_THREAT_QUEEN = S(168, -36); +inline const PParam KNIGHT_THREAT_BISHOP = S(169, 52); +inline const PParam KNIGHT_THREAT_ROOK = S(311, -12); +inline const PParam KNIGHT_THREAT_QUEEN = S(211, -99); -inline const PParam BISHOP_THREAT_KNIGHT = S(115, 43); -inline const PParam BISHOP_THREAT_ROOK = S(241, 76); -inline const PParam BISHOP_THREAT_QUEEN = S(204, 40); +inline const PParam BISHOP_THREAT_KNIGHT = S(143, 23); +inline const PParam BISHOP_THREAT_ROOK = S(314, 23); +inline const PParam BISHOP_THREAT_QUEEN = S(256, -0); inline const std::array BISHOP_PAWNS = { - S(5, -26), S(-3, -11), S(-6, -21), S(-11, -28), S(-17, -33), S(-24, -34), S(-28, -44), S(-35, -39), S(-46, -38), + S(-3, -20), S(-4, -9), S(-11, -14), S(-21, -19), S(-32, -22), S(-41, -25), S(-49, -32), S(-55, -32), S(-66, -32), }; -inline const PParam ROOK_LINEUP = S(14, 71); +inline const PParam ROOK_LINEUP = S(20, 87); inline const std::array PAWN_PSQT = { - S(326, 280), S(177, 363), S(318, 340), S(329, 214), S(366, 161), S(263, 239), S(209, 266), S(320, 224), // - S(136, 182), S(170, 209), S(211, 132), S(192, 79), S(167, 70), S(145, 113), S(122, 155), S(76, 181), // - S(99, 149), S(87, 147), S(125, 79), S(125, 62), S(111, 65), S(83, 98), S(37, 139), S(31, 162), // - S(67, 113), S(58, 131), S(93, 79), S(90, 70), S(68, 77), S(52, 103), S(-8, 143), S(-6, 136), // - S(63, 92), S(103, 94), S(92, 119), S(83, 105), S(54, 105), S(31, 113), S(-4, 129), S(-10, 122), // - S(77, 94), S(172, 97), S(161, 148), S(111, 130), S(80, 124), S(58, 122), S(27, 133), S(9, 136), // + S(552, 158), S(412, 261), S(515, 231), S(437, 133), S(437, 115), S(381, 161), S(343, 194), S(475, 128), // + S(226, 114), S(269, 159), S(252, 94), S(192, 37), S(160, 28), S(161, 68), S(165, 107), S(138, 126), // + S(155, 108), S(130, 110), S(142, 66), S(126, 46), S(109, 47), S(95, 74), S(64, 108), S(78, 121), // + S(98, 85), S(99, 94), S(113, 62), S(105, 55), S(80, 58), S(76, 77), S(26, 109), S(30, 105), // + S(86, 67), S(135, 64), S(122, 89), S(109, 77), S(76, 77), S(58, 80), S(28, 96), S(23, 90), // + S(104, 68), S(216, 54), S(211, 94), S(147, 88), S(107, 90), S(92, 80), S(63, 95), S(48, 100), // }; inline const std::array KNIGHT_PSQT = { - S(-302, 34), S(-161, 193), S(-287, 259), S(116, 159), S(56, 155), S(-93, 161), S(-216, 186), S(-340, 104), // - S(87, 149), S(140, 154), S(228, 113), S(221, 134), S(208, 150), S(144, 139), S(104, 162), S(76, 143), // - S(183, 125), S(207, 163), S(235, 173), S(228, 169), S(203, 177), S(139, 195), S(153, 137), S(118, 134), // - S(255, 141), S(266, 155), S(262, 177), S(254, 202), S(257, 202), S(208, 192), S(198, 166), S(194, 137), // - S(237, 145), S(270, 132), S(248, 174), S(245, 190), S(221, 193), S(218, 178), S(214, 132), S(175, 144), // - S(175, 122), S(203, 123), S(195, 156), S(207, 177), S(204, 175), S(164, 161), S(153, 131), S(121, 106), // - S(190, 118), S(209, 119), S(178, 121), S(182, 140), S(173, 139), S(142, 102), S(135, 118), S(110, 60), // - S(115, 94), S(164, 153), S(185, 103), S(200, 98), S(183, 116), S(147, 94), S(131, 125), S(85, 65), // + S(-333, -71), S(-65, 146), S(-36, -79), S(204, 134), S(124, 155), S(2, 130), S(-155, 178), S(-376, 13), // + S(166, 105), S(229, 111), S(298, 111), S(308, 110), S(304, 118), S(221, 139), S(185, 140), S(149, 125), // + S(277, 86), S(323, 99), S(349, 126), S(332, 148), S(308, 165), S(242, 170), S(234, 130), S(192, 133), // + S(352, 107), S(380, 113), S(376, 139), S(375, 161), S(372, 170), S(317, 163), S(291, 152), S(276, 129), // + S(330, 113), S(364, 100), S(352, 143), S(353, 156), S(327, 160), S(319, 154), S(299, 125), S(249, 142), // + S(248, 108), S(285, 99), S(290, 119), S(306, 143), S(305, 141), S(252, 136), S(229, 118), S(178, 117), // + S(268, 100), S(281, 102), S(259, 100), S(265, 124), S(255, 123), S(210, 100), S(199, 118), S(152, 74), // + S(170, 83), S(222, 152), S(247, 92), S(263, 96), S(248, 110), S(200, 105), S(187, 132), S(116, 95), // }; inline const std::array BISHOP_PSQT = { - S(17, 273), S(12, 257), S(-270, 315), S(-157, 280), S(-172, 306), S(-193, 311), S(-62, 302), S(38, 269), // - S(138, 189), S(85, 254), S(115, 221), S(49, 252), S(64, 252), S(97, 240), S(137, 230), S(117, 207), // - S(223, 198), S(229, 222), S(222, 228), S(207, 216), S(175, 213), S(181, 219), S(198, 211), S(193, 189), // - S(191, 192), S(226, 203), S(227, 220), S(230, 246), S(265, 225), S(190, 213), S(197, 186), S(156, 189), // - S(216, 153), S(235, 182), S(242, 202), S(252, 219), S(229, 232), S(210, 217), S(177, 197), S(167, 164), // - S(244, 158), S(279, 167), S(294, 188), S(239, 215), S(233, 195), S(229, 205), S(235, 180), S(172, 188), // - S(212, 122), S(311, 141), S(270, 154), S(235, 174), S(216, 180), S(219, 153), S(218, 157), S(212, 151), // - S(239, 141), S(228, 155), S(228, 187), S(245, 142), S(234, 150), S(235, 196), S(231, 175), S(217, 166), // + S(98, 238), S(146, 205), S(-60, 244), S(40, 204), S(76, 194), S(49, 214), S(134, 205), S(116, 204), // + S(243, 115), S(224, 185), S(231, 171), S(193, 184), S(210, 188), S(218, 191), S(265, 172), S(227, 159), // + S(358, 127), S(372, 150), S(363, 167), S(333, 171), S(299, 169), S(315, 160), S(324, 164), S(309, 145), // + S(302, 150), S(346, 145), S(356, 165), S(368, 187), S(394, 183), S(312, 172), S(299, 156), S(264, 156), // + S(321, 109), S(343, 146), S(361, 152), S(385, 160), S(362, 177), S(329, 171), S(284, 171), S(260, 146), // + S(347, 125), S(395, 125), S(418, 143), S(365, 165), S(350, 154), S(352, 160), S(351, 143), S(280, 149), // + S(312, 102), S(422, 109), S(386, 120), S(348, 140), S(326, 145), S(326, 128), S(323, 127), S(322, 107), // + S(342, 105), S(330, 131), S(328, 165), S(351, 107), S(342, 124), S(349, 160), S(343, 138), S(317, 130), // }; inline const std::array ROOK_PSQT = { - S(488, 304), S(521, 312), S(486, 326), S(485, 316), S(483, 304), S(460, 306), S(454, 321), S(433, 333), // - S(367, 372), S(461, 353), S(540, 322), S(480, 334), S(461, 345), S(439, 350), S(368, 379), S(348, 387), // - S(339, 366), S(464, 329), S(507, 312), S(482, 305), S(436, 329), S(395, 347), S(396, 347), S(326, 385), // - S(336, 340), S(424, 334), S(454, 318), S(428, 324), S(422, 329), S(384, 347), S(379, 340), S(301, 370), // - S(304, 301), S(377, 302), S(367, 320), S(346, 320), S(326, 339), S(318, 348), S(287, 342), S(265, 343), // - S(287, 259), S(357, 271), S(346, 291), S(331, 289), S(320, 296), S(299, 312), S(290, 296), S(251, 308), // - S(175, 281), S(313, 234), S(328, 251), S(322, 269), S(308, 272), S(301, 275), S(282, 262), S(254, 278), // - S(239, 274), S(265, 287), S(328, 260), S(342, 253), S(330, 262), S(311, 277), S(299, 275), S(276, 295), // + S(621, 247), S(662, 248), S(643, 264), S(618, 243), S(585, 258), S(561, 268), S(568, 278), S(560, 286), // + S(560, 276), S(649, 272), S(699, 258), S(632, 264), S(610, 285), S(589, 289), S(539, 305), S(532, 303), // + S(513, 286), S(634, 266), S(660, 241), S(607, 255), S(567, 276), S(546, 282), S(548, 289), S(506, 307), // + S(472, 274), S(574, 256), S(597, 242), S(559, 251), S(551, 266), S(525, 282), S(522, 274), S(459, 297), // + S(408, 234), S(497, 235), S(495, 244), S(463, 256), S(453, 263), S(460, 266), S(418, 277), S(396, 269), // + S(372, 201), S(457, 203), S(455, 226), S(432, 233), S(423, 240), S(410, 256), S(399, 233), S(359, 243), // + S(251, 234), S(393, 194), S(423, 201), S(422, 213), S(407, 219), S(400, 224), S(374, 219), S(342, 238), // + S(310, 228), S(342, 243), S(421, 200), S(435, 202), S(422, 214), S(405, 228), S(392, 225), S(364, 242), // }; inline const std::array QUEEN_PSQT = { - S(639, 486), S(691, 451), S(653, 515), S(612, 589), S(606, 567), S(615, 542), S(634, 476), S(560, 545), // - S(643, 535), S(609, 624), S(595, 657), S(439, 762), S(447, 753), S(522, 692), S(560, 585), S(570, 563), // - S(614, 579), S(665, 594), S(607, 676), S(541, 720), S(519, 710), S(559, 655), S(608, 558), S(615, 499), // - S(648, 513), S(666, 574), S(601, 646), S(586, 688), S(574, 696), S(577, 623), S(629, 540), S(605, 524), // - S(664, 482), S(660, 538), S(631, 598), S(598, 647), S(596, 648), S(597, 601), S(608, 536), S(631, 461), // - S(639, 437), S(678, 481), S(676, 539), S(642, 542), S(634, 542), S(633, 556), S(643, 481), S(619, 455), // - S(614, 339), S(654, 345), S(663, 402), S(679, 432), S(664, 466), S(655, 434), S(620, 469), S(629, 449), // - S(596, 347), S(623, 209), S(649, 229), S(668, 327), S(669, 386), S(666, 338), S(654, 362), S(617, 408), // + S(914, 420), S(944, 392), S(918, 479), S(894, 564), S(892, 495), S(893, 504), S(881, 461), S(821, 548), // + S(911, 506), S(924, 540), S(926, 557), S(807, 604), S(793, 650), S(831, 661), S(827, 599), S(844, 527), // + S(937, 405), S(965, 530), S(934, 579), S(871, 638), S(835, 644), S(869, 568), S(879, 545), S(879, 483), // + S(942, 391), S(955, 528), S(901, 601), S(913, 590), S(886, 652), S(864, 594), S(899, 517), S(867, 539), // + S(943, 405), S(950, 460), S(937, 506), S(906, 577), S(893, 613), S(891, 532), S(877, 514), S(884, 466), // + S(914, 331), S(966, 380), S(973, 456), S(934, 475), S(911, 520), S(910, 549), S(897, 502), S(884, 397), // + S(864, 285), S(910, 256), S(928, 353), S(958, 354), S(931, 442), S(911, 429), S(876, 481), S(886, 449), // + S(834, 302), S(848, 148), S(876, 186), S(913, 286), S(922, 385), S(916, 320), S(909, 319), S(859, 425), // }; inline const std::array KING_PSQT = { - S(-249, -268), S(236, 93), S(163, 61), S(-164, 45), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(268, -99), S(403, 64), S(187, 97), S(83, 3), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(209, 31), S(447, 38), S(299, 63), S(129, -3), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(8, 27), S(313, 28), S(140, 54), S(52, 23), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-98, 21), S(211, 4), S(136, 20), S(16, 21), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-46, 18), S(210, -7), S(121, 11), S(78, -16), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-3, -2), S(92, 24), S(11, 35), S(-41, 1), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-124, -31), S(-14, -10), S(-113, 6), S(-119, -65), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-224, -243), S(550, 73), S(441, 70), S(237, -44), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(285, -71), S(580, 61), S(497, 84), S(331, 6), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(377, -9), S(640, 40), S(618, 43), S(455, -5), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(185, -30), S(504, 12), S(499, 24), S(426, 5), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-15, -37), S(318, -20), S(381, -17), S(346, -17), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-80, -11), S(185, -8), S(193, -1), S(187, -18), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-78, -12), S(22, 34), S(-31, 48), S(-65, 37), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-229, -26), S(-94, -19), S(-198, 19), S(-212, -8), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // }; inline const std::array, 4> KING_SHELTER = {{ - {{ S(10, -27), S(-9, 7), S(-13, 12), S(-5, -0), S(-5, -2), S(-12, 13), S(-7, 11), }}, - {{ S(1, -5), S(-28, 30), S(-25, 26), S(-15, 8), S(-14, 9), S(-24, 32), S(-27, 43), }}, - {{ S(-15, -3), S(-26, 22), S(-25, 4), S(-22, -11), S(-21, -10), S(-25, 5), S(-25, 20), }}, - {{ S(-3, -14), S(-22, -21), S(-14, -22), S(-9, -25), S(-10, -23), S(-15, -18), S(-18, -19), }}, + {{ S(4, -22), S(-10, 11), S(-12, 4), S(-7, -7), S(-11, -6), S(-17, 9), S(-11, 12), }}, + {{ S(1, -16), S(-19, 4), S(-16, 1), S(-10, -12), S(-17, -2), S(-23, 34), S(-27, 79), }}, + {{ S(-5, -1), S(-16, 28), S(-11, 4), S(-10, -6), S(-16, 3), S(-21, 26), S(-18, 31), }}, + {{ S(-3, -13), S(-18, -8), S(-10, -15), S(-8, -20), S(-13, -14), S(-19, -4), S(-21, -6), }}, }}; inline const std::array BLOCKED_SHELTER_STORM = { - S(0, 0), S(0, 0), S(9, 20), S(-15, 37), S(-12, 24), S(-6, 13), S(-6, -2), + S(0, 0), S(0, 0), S(9, 11), S(-8, 22), S(-4, 16), S(10, -5), S(13, -33), }; inline const std::array, 4> SHELTER_STORM = {{ - {{ S(-2, 14), S(-13, 20), S(-11, 18), S(-9, 14), S(-10, 9), S(-9, 9), S(-13, 18), }}, - {{ S(-0, 9), S(-9, 16), S(-16, 21), S(-12, 11), S(-11, 7), S(-15, 17), S(-9, 14), }}, - {{ S(-7, 12), S(-12, 6), S(-14, 15), S(-8, 12), S(-8, 11), S(-13, 13), S(-12, 8), }}, - {{ S(-8, 12), S(-14, 13), S(-15, 11), S(-9, 16), S(-7, 16), S(-14, 11), S(-16, 12), }}, + {{ S(4, 2), S(-9, 45), S(-9, 30), S(-7, 19), S(-5, 3), S(-2, -4), S(-4, -2), }}, + {{ S(2, 6), S(-10, 44), S(-20, 43), S(-14, 26), S(-10, 11), S(-6, 6), S(-3, 10), }}, + {{ S(-3, 6), S(-14, 29), S(-18, 35), S(-11, 20), S(-6, 9), S(-5, 4), S(-5, 3), }}, + {{ S(-3, 5), S(-11, 20), S(-16, 22), S(-7, 14), S(-4, 10), S(-4, 3), S(-4, 3), }}, }}; inline TunableSigmoid<32> KING_SAFETY_ACTIVATION( - 1112, 423, -28, 44 + 1525, 546, -42, 59 ); -// Epoch duration: 9.97031s + +inline VParam WINNABLE_PAWNS = V(27); +inline VParam WINNABLE_BIAS = V(-249); + +// Epoch duration: 7.3709s +// Epoch duration: 9.05276s // clang-format on -} // namespace Clockwork +} // namespace Clockwork \ No newline at end of file diff --git a/src/eval_types.hpp b/src/eval_types.hpp index 9228f486..d6b8f5c0 100644 --- a/src/eval_types.hpp +++ b/src/eval_types.hpp @@ -101,6 +101,11 @@ class PScore { return static_cast((mg() * alpha + eg() * (max - alpha)) / max); } + // relu_add + PScore relu_add(Score val){ + return PScore{mg(), static_cast(std::max(0, eg()+val))}; + } + friend std::ostream& operator<<(std::ostream& stream, const PScore& score) { stream << "(" << score.mg() << "\t" << score.eg() << ")"; return stream; @@ -108,11 +113,13 @@ class PScore { }; using PParam = PScore; +using VParam = Score; #else using Score = Autograd::ValueHandle; using PScore = Autograd::PairHandle; using PParam = Autograd::PairPlaceholder; // Handle for the TUNABLE parameter +using VParam = Autograd::ValuePlaceholder; // Handle for the TUNABLE parameter #endif @@ -124,6 +131,12 @@ using PParam = Autograd::PairPlaceholder; // Handle for the TUNABLE parameter // Constant scalar pair (mg, eg) #define CS(a, b) Autograd::PairPlaceholder::create((a), (b)) + // Tunable scalar + #define V(a) Autograd::ValuePlaceholder::create_tunable((a)) + + // Constant scalar + #define CV(a) Autograd::ValuePlaceholder::create((a)) + // Zero pair FOR PARAMETERS (e.g., in an array) #define PPARAM_ZERO Autograd::PairPlaceholder::create(0, 0) @@ -134,6 +147,9 @@ using PParam = Autograd::PairPlaceholder; // Handle for the TUNABLE parameter // ... (non-tuning definitions) ... #define S(a, b) PScore((a), (b)) #define CS(a, b) PScore((a), (b)) + + #define V(a) Value((a)) + #define CV(a) Value((a)) #define PPARAM_ZERO PScore(0, 0) #define PSCORE_ZERO PScore(0, 0) #endif diff --git a/src/evaltune_main.cpp b/src/evaltune_main.cpp index 2dc7c87e..b8acfdd5 100644 --- a/src/evaltune_main.cpp +++ b/src/evaltune_main.cpp @@ -133,7 +133,7 @@ int main() { current_parameter_values = Parameters::rand_init(parameter_count); // The optimizer will now start with all-zero parameters - AdamW optim(parameter_count, 10, 0.9, 0.999, 1e-8, 0.0); + AdamW optim(parameter_count, 1, 0.9, 0.999, 1e-8, 0.0); #ifdef PROFILE_RUN const i32 epochs = 8; #else @@ -412,6 +412,12 @@ int main() { }; print_sigmoid("KING_SAFETY_ACTIVATION", KING_SAFETY_ACTIVATION, 32); + std::cout << std::endl; + + std::cout << "inline VParam WINNABLE_PAWNS = " << WINNABLE_PAWNS << ";\n"; + std::cout << "inline VParam WINNABLE_BIAS = " << WINNABLE_BIAS << ";\n"; + std::cout << std::endl; + #endif const auto end = time::Clock::now(); std::cout << "// Epoch duration: " << time::cast(end - start).count() diff --git a/src/evaluation.cpp b/src/evaluation.cpp index 8d65e7df..f5a12d6a 100644 --- a/src/evaluation.cpp +++ b/src/evaluation.cpp @@ -415,6 +415,14 @@ PScore king_safety_activation(const Position& pos, PScore& king_safety_score) { return activated; } +PScore apply_winnable(const Position& pos, PScore& score) { + i32 pawn_count = (pos.bitboard_for(Color::White, PieceType::Pawn) | pos.bitboard_for(Color::Black, PieceType::Pawn)).ipopcount(); + Score winnable = WINNABLE_PAWNS * pawn_count + + WINNABLE_BIAS; + + return score.relu_add(winnable); +} + Score evaluate_white_pov(const Position& pos, const PsqtState& psqt_state) { const Color us = pos.active_color(); usize phase = pos.piece_count(Color::White, PieceType::Knight) @@ -450,6 +458,10 @@ Score evaluate_white_pov(const Position& pos, const PsqtState& psqt_state) { - king_safety_activation(pos, black_king_attack_total); eval += (us == Color::White) ? TEMPO_VAL : -TEMPO_VAL; + + // Winnable + eval = apply_winnable(pos, eval); + return static_cast(eval.phase<24>(static_cast(phase))); }; diff --git a/src/tuning/graph.cpp b/src/tuning/graph.cpp index 84ae7cb7..809638dc 100644 --- a/src/tuning/graph.cpp +++ b/src/tuning/graph.cpp @@ -189,6 +189,11 @@ PairHandle Graph::record_pair_value(OpType op, PairHandle lhs, ValueHandle rhs) case OpType::ValueDivPair: res = f64x2::scalar_div(v, pair_val); break; + case OpType::ReluAdd: { + f64 add_res = pair_val.second() + v; + res = f64x2::make(pair_val.first(), std::max(0.0, add_res)); + break; + } default: break; } @@ -488,6 +493,23 @@ void Graph::backward() { pair_grads[node.rhs()] = f64x2::add(pair_grads[node.rhs()], grad_rhs); break; } + case OpType::ReluAdd: { + const f64x2 grad_out = pair_grads[out_idx]; + f64x2 lhs_val = pair_vals[node.lhs()]; + f64 rhs_val = vals[node.rhs()]; + + f64 mask = (lhs_val.second() + rhs_val > 0.0) ? 1.0 : 0.0; + + f64x2 grad_lhs = f64x2::make(grad_out.first(), // y0 = x0 + grad_out.second() * mask // y1 = relu(x1 + v) + ); + + pair_grads[node.lhs()] = f64x2::add(pair_grads[node.lhs()], grad_lhs); + + grads[node.rhs()] += grad_out.second() * mask; + break; + } + default: unreachable(); diff --git a/src/tuning/operations.hpp b/src/tuning/operations.hpp index fb162fb7..df152a94 100644 --- a/src/tuning/operations.hpp +++ b/src/tuning/operations.hpp @@ -50,6 +50,7 @@ enum class OpType : u32 { ValueMulPair, PairDivValue, ValueDivPair, + ReluAdd, // For complexity // Pair-Pair Ops PairMulPair, diff --git a/src/tuning/value.cpp b/src/tuning/value.cpp index f2a1e43d..fdb09ef1 100644 --- a/src/tuning/value.cpp +++ b/src/tuning/value.cpp @@ -204,6 +204,11 @@ std::ostream& operator<<(std::ostream& os, const PairHandle& p) { return os; } +std::ostream& operator<<(std::ostream& os, const ValueHandle& v) { + os << "V(" << std::round(v.get_value()) << ")"; + return os; +} + // Value Inplaces ValueHandle& operator+=(ValueHandle& a, ValueHandle b) { a = a + b; @@ -265,4 +270,9 @@ PairHandle& operator/=(PairHandle& a, ValueHandle v) { return a; } + +PairHandle PairHandle::relu_add(ValueHandle value) const { + return Graph::get().record_pair_value(OpType::ReluAdd, *this, value); +} + } // namespace Clockwork::Autograd diff --git a/src/tuning/value.hpp b/src/tuning/value.hpp index 4cfc244a..4fc4d38b 100644 --- a/src/tuning/value.hpp +++ b/src/tuning/value.hpp @@ -73,6 +73,8 @@ struct PairHandle { } PairHandle sigmoid() const; + + PairHandle relu_add(ValueHandle value) const; }; // Operation decls @@ -105,6 +107,7 @@ PairHandle operator*(PairHandle a, PairHandle b); PairHandle operator/(PairHandle a, ValueHandle v); PairHandle operator/(ValueHandle v, PairHandle a); std::ostream& operator<<(std::ostream& os, const PairHandle& p); +std::ostream& operator<<(std::ostream& os, const ValueHandle& v); // Value Inplaces ValueHandle& operator+=(ValueHandle& a, ValueHandle b); From 141073655befe643508c222fe1996f04d285ef0e Mon Sep 17 00:00:00 2001 From: TheRealGioviok <425gioviok@gmail.com> Date: Sun, 1 Feb 2026 22:20:11 +0100 Subject: [PATCH 2/9] Format Bench: 17344937 --- src/eval_constants.hpp | 2 +- src/eval_types.hpp | 6 +++--- src/evaluation.cpp | 9 +++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/eval_constants.hpp b/src/eval_constants.hpp index 1e5a9317..f85aafde 100644 --- a/src/eval_constants.hpp +++ b/src/eval_constants.hpp @@ -177,4 +177,4 @@ inline VParam WINNABLE_BIAS = V(-249); // Epoch duration: 7.3709s // Epoch duration: 9.05276s // clang-format on -} // namespace Clockwork \ No newline at end of file +} // namespace Clockwork diff --git a/src/eval_types.hpp b/src/eval_types.hpp index d6b8f5c0..8557a78c 100644 --- a/src/eval_types.hpp +++ b/src/eval_types.hpp @@ -102,8 +102,8 @@ class PScore { } // relu_add - PScore relu_add(Score val){ - return PScore{mg(), static_cast(std::max(0, eg()+val))}; + PScore relu_add(Score val) { + return PScore{mg(), static_cast(std::max(0, eg() + val))}; } friend std::ostream& operator<<(std::ostream& stream, const PScore& score) { @@ -118,7 +118,7 @@ using VParam = Score; using Score = Autograd::ValueHandle; using PScore = Autograd::PairHandle; -using PParam = Autograd::PairPlaceholder; // Handle for the TUNABLE parameter +using PParam = Autograd::PairPlaceholder; // Handle for the TUNABLE parameter using VParam = Autograd::ValuePlaceholder; // Handle for the TUNABLE parameter #endif diff --git a/src/evaluation.cpp b/src/evaluation.cpp index f5a12d6a..1a98e80c 100644 --- a/src/evaluation.cpp +++ b/src/evaluation.cpp @@ -416,10 +416,11 @@ PScore king_safety_activation(const Position& pos, PScore& king_safety_score) { } PScore apply_winnable(const Position& pos, PScore& score) { - i32 pawn_count = (pos.bitboard_for(Color::White, PieceType::Pawn) | pos.bitboard_for(Color::Black, PieceType::Pawn)).ipopcount(); - Score winnable = WINNABLE_PAWNS * pawn_count - + WINNABLE_BIAS; - + i32 pawn_count = (pos.bitboard_for(Color::White, PieceType::Pawn) + | pos.bitboard_for(Color::Black, PieceType::Pawn)) + .ipopcount(); + Score winnable = WINNABLE_PAWNS * pawn_count + WINNABLE_BIAS; + return score.relu_add(winnable); } From 1d4ac3c11e556abda5de21f369113a74d11ba421 Mon Sep 17 00:00:00 2001 From: TheRealGioviok <425gioviok@gmail.com> Date: Sun, 1 Feb 2026 23:02:00 +0100 Subject: [PATCH 3/9] oopsiedaisy --- src/eval_types.hpp | 4 ++-- src/evaluation.cpp | 4 +++- src/tuning/graph.cpp | 38 +++++++++++++++++++++++++++----------- src/tuning/operations.hpp | 2 +- src/tuning/value.cpp | 4 ++-- src/tuning/value.hpp | 2 +- 6 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/eval_types.hpp b/src/eval_types.hpp index 8557a78c..91869be2 100644 --- a/src/eval_types.hpp +++ b/src/eval_types.hpp @@ -101,8 +101,8 @@ class PScore { return static_cast((mg() * alpha + eg() * (max - alpha)) / max); } - // relu_add - PScore relu_add(Score val) { + // complexity_add + PScore complexity_add(Score val) { return PScore{mg(), static_cast(std::max(0, eg() + val))}; } diff --git a/src/evaluation.cpp b/src/evaluation.cpp index 1a98e80c..6b6934ee 100644 --- a/src/evaluation.cpp +++ b/src/evaluation.cpp @@ -416,12 +416,14 @@ PScore king_safety_activation(const Position& pos, PScore& king_safety_score) { } PScore apply_winnable(const Position& pos, PScore& score) { + const Color color = pos.active_color(); + i32 pawn_count = (pos.bitboard_for(Color::White, PieceType::Pawn) | pos.bitboard_for(Color::Black, PieceType::Pawn)) .ipopcount(); Score winnable = WINNABLE_PAWNS * pawn_count + WINNABLE_BIAS; - return score.relu_add(winnable); + return score.complexity_add(color == Color::White ? winnable : -winnable); } Score evaluate_white_pov(const Position& pos, const PsqtState& psqt_state) { diff --git a/src/tuning/graph.cpp b/src/tuning/graph.cpp index 809638dc..c882cfc9 100644 --- a/src/tuning/graph.cpp +++ b/src/tuning/graph.cpp @@ -189,9 +189,15 @@ PairHandle Graph::record_pair_value(OpType op, PairHandle lhs, ValueHandle rhs) case OpType::ValueDivPair: res = f64x2::scalar_div(v, pair_val); break; - case OpType::ReluAdd: { + case OpType::PairAddClampedSecond: { f64 add_res = pair_val.second() + v; - res = f64x2::make(pair_val.first(), std::max(0.0, add_res)); + if (pair_val.second() > 0) { + res = f64x2::make(pair_val.first(), std::max(0.0, add_res)); + } else if (pair_val.second() < 0) { + res = f64x2::make(pair_val.first(), std::min(0.0, add_res)); + } else { + res = pair_val; + } break; } default: @@ -493,20 +499,30 @@ void Graph::backward() { pair_grads[node.rhs()] = f64x2::add(pair_grads[node.rhs()], grad_rhs); break; } - case OpType::ReluAdd: { + case OpType::PairAddClampedSecond: { const f64x2 grad_out = pair_grads[out_idx]; - f64x2 lhs_val = pair_vals[node.lhs()]; - f64 rhs_val = vals[node.rhs()]; + f64x2 val_lhs = pair_vals[node.lhs()]; + f64 val_rhs = vals[node.rhs()]; - f64 mask = (lhs_val.second() + rhs_val > 0.0) ? 1.0 : 0.0; + f64x2 grad_pair = f64x2::make(grad_out.first(), 0.0); - f64x2 grad_lhs = f64x2::make(grad_out.first(), // y0 = x0 - grad_out.second() * mask // y1 = relu(x1 + v) - ); + f64 add_res = val_lhs.second() + val_rhs; - pair_grads[node.lhs()] = f64x2::add(pair_grads[node.lhs()], grad_lhs); + if (val_lhs.second() > 0) { + if (add_res > 0.0) { + grad_pair = f64x2::make(grad_out.first(), grad_out.second()); + grads[node.rhs()] += grad_out.second(); + } + } else if (val_lhs.second() < 0) { + if (add_res < 0.0) { + grad_pair = f64x2::make(grad_out.first(), grad_out.second()); + grads[node.rhs()] += grad_out.second(); + } + } else { + grad_pair = grad_out; + } - grads[node.rhs()] += grad_out.second() * mask; + pair_grads[node.lhs()] = f64x2::add(pair_grads[node.lhs()], grad_pair); break; } diff --git a/src/tuning/operations.hpp b/src/tuning/operations.hpp index df152a94..945ba2f7 100644 --- a/src/tuning/operations.hpp +++ b/src/tuning/operations.hpp @@ -50,7 +50,7 @@ enum class OpType : u32 { ValueMulPair, PairDivValue, ValueDivPair, - ReluAdd, // For complexity + PairAddClampedSecond, // For complexity // Pair-Pair Ops PairMulPair, diff --git a/src/tuning/value.cpp b/src/tuning/value.cpp index fdb09ef1..0d5b66b9 100644 --- a/src/tuning/value.cpp +++ b/src/tuning/value.cpp @@ -271,8 +271,8 @@ PairHandle& operator/=(PairHandle& a, ValueHandle v) { } -PairHandle PairHandle::relu_add(ValueHandle value) const { - return Graph::get().record_pair_value(OpType::ReluAdd, *this, value); +PairHandle PairHandle::complexity_add(ValueHandle value) const { + return Graph::get().record_pair_value(OpType::PairAddClampedSecond, *this, value); } } // namespace Clockwork::Autograd diff --git a/src/tuning/value.hpp b/src/tuning/value.hpp index 4fc4d38b..806fabd0 100644 --- a/src/tuning/value.hpp +++ b/src/tuning/value.hpp @@ -74,7 +74,7 @@ struct PairHandle { PairHandle sigmoid() const; - PairHandle relu_add(ValueHandle value) const; + PairHandle complexity_add(ValueHandle value) const; }; // Operation decls From 62769647570316f687ae679b3570c6760043a014 Mon Sep 17 00:00:00 2001 From: TheRealGioviok <425gioviok@gmail.com> Date: Mon, 2 Feb 2026 04:48:01 +0100 Subject: [PATCH 4/9] Bench: 18563228 --- src/eval_constants.hpp | 207 ++++++++++++++++++++--------------------- src/eval_types.hpp | 4 +- src/evaltune_main.cpp | 2 +- src/evaluation.cpp | 7 +- src/tuning/graph.cpp | 18 +++- src/tuning/value.cpp | 6 ++ src/tuning/value.hpp | 2 + 7 files changed, 135 insertions(+), 111 deletions(-) diff --git a/src/eval_constants.hpp b/src/eval_constants.hpp index f85aafde..f83531be 100644 --- a/src/eval_constants.hpp +++ b/src/eval_constants.hpp @@ -5,176 +5,175 @@ namespace Clockwork { // clang-format off -inline const PParam PAWN_MAT = S(266, 126); -inline const PParam KNIGHT_MAT = S(925, 328); -inline const PParam BISHOP_MAT = S(971, 350); -inline const PParam ROOK_MAT = S(883, 305); -inline const PParam QUEEN_MAT = S(1889, 361); -inline const PParam TEMPO_VAL = S(77, 2); +inline const PParam PAWN_MAT = S(152, 201); +inline const PParam KNIGHT_MAT = S(564, 560); +inline const PParam BISHOP_MAT = S(601, 597); +inline const PParam ROOK_MAT = S(445, 670); +inline const PParam QUEEN_MAT = S(1049, 1156); +inline const PParam TEMPO_VAL = S(60, 17); -inline const PParam BISHOP_PAIR_VAL = S(154, 111); -inline const PParam ROOK_OPEN_VAL = S(110, -16); -inline const PParam ROOK_SEMIOPEN_VAL = S(58, 13); +inline const PParam BISHOP_PAIR_VAL = S(50, 193); +inline const PParam ROOK_OPEN_VAL = S(111, -18); +inline const PParam ROOK_SEMIOPEN_VAL = S(46, 21); -inline const PParam DOUBLED_PAWN_VAL = S(-39, -46); -inline const PParam ISOLATED_PAWN_VAL = S(-28, -12); +inline const PParam DOUBLED_PAWN_VAL = S(-8, -65); +inline const PParam ISOLATED_PAWN_VAL = S(-19, -20); -inline const PParam POTENTIAL_CHECKER_VAL = S(-77, -1); -inline const PParam OUTPOST_KNIGHT_VAL = S(69, 30); -inline const PParam OUTPOST_BISHOP_VAL = S(83, 12); +inline const PParam POTENTIAL_CHECKER_VAL = S(-56, -11); +inline const PParam OUTPOST_KNIGHT_VAL = S(37, 57); +inline const PParam OUTPOST_BISHOP_VAL = S(58, 25); -inline const PParam PAWN_PUSH_THREAT_KNIGHT = S(48, 6); -inline const PParam PAWN_PUSH_THREAT_BISHOP = S(54, -18); -inline const PParam PAWN_PUSH_THREAT_ROOK = S(55, 27); -inline const PParam PAWN_PUSH_THREAT_QUEEN = S(72, -71); +inline const PParam PAWN_PUSH_THREAT_KNIGHT = S(44, 5); +inline const PParam PAWN_PUSH_THREAT_BISHOP = S(56, -20); +inline const PParam PAWN_PUSH_THREAT_ROOK = S(29, 49); +inline const PParam PAWN_PUSH_THREAT_QUEEN = S(70, -34); inline const std::array PAWN_PHALANX = { - S(17, 3), S(58, 17), S(87, 33), S(227, 81), S(666, 156), S(701, 438), + S(15, 1), S(41, 24), S(60, 49), S(139, 142), S(386, 214), S(496, 515), }; inline const std::array DEFENDED_PAWN = { - S(78, 18), S(64, 14), S(91, 30), S(216, 77), S(561, 59), + S(55, 32), S(47, 22), S(55, 49), S(117, 140), S(423, 68), }; inline const std::array PASSED_PAWN = { - S(-176, -86), S(-165, -77), S(-81, -18), S(34, 50), S(220, 147), S(524, 191), + S(-92, -128), S(-86, -104), S(-65, 4), S(-7, 103), S(81, 236), S(271, 350), }; inline const std::array DEFENDED_PASSED_PUSH = { - S(4, -21), S(29, -1), S(64, 11), S(123, 42), S(308, 61), S(495, 141), + S(41, -49), S(38, -7), S(24, 32), S(2, 109), S(51, 212), S(215, 256), }; inline const std::array BLOCKED_PASSED_PAWN = { - S(-5, -24), S(0, -1), S(-23, -18), S(-42, -36), S(-104, -71), S(-471, -97), + S(24, -45), S(7, 2), S(2, -25), S(-4, -52), S(-3, -130), S(-205, -230), }; inline const std::array FRIENDLY_KING_PASSED_PAWN_DISTANCE = { - S(0, 0), S(138, 86), S(103, 65), S(38, 37), S(10, 19), S(18, 15), S(58, 16), S(38, 16), + S(0, 0), S(-2, 155), S(-18, 129), S(-6, 55), S(4, 17), S(9, 15), S(44, 11), S(20, 1), }; inline const std::array ENEMY_KING_PASSED_PAWN_DISTANCE = { - S(0, 0), S(-280, -12), S(31, 28), S(37, 38), S(93, 56), S(111, 63), S(110, 69), S(112, 51), + S(0, 0), S(-289, -50), S(-15, 12), S(-17, 69), S(21, 106), S(40, 128), S(58, 132), S(39, 128), }; inline const std::array KNIGHT_MOBILITY = { - S(151, -15), S(276, 122), S(343, 182), S(389, 204), S(441, 211), S(481, 235), S(517, 232), S(558, 238), S(577, 194), + S(100, -5), S(172, 163), S(208, 248), S(236, 283), S(278, 298), S(303, 328), S(337, 325), S(371, 332), S(428, 242), }; inline const std::array BISHOP_MOBILITY = { - S(171, 5), S(254, 141), S(343, 162), S(390, 186), S(430, 204), S(458, 213), S(473, 226), S(495, 230), S(512, 236), S(532, 228), S(546, 230), S(572, 202), S(571, 212), S(565, 200), + S(111, -0), S(156, 165), S(212, 223), S(241, 264), S(267, 291), S(286, 310), S(296, 325), S(313, 330), S(323, 341), S(350, 321), S(370, 311), S(420, 258), S(434, 253), S(468, 203), }; inline const std::array ROOK_MOBILITY = { - S(490, 166), S(467, 305), S(505, 312), S(532, 308), S(550, 312), S(562, 318), S(575, 320), S(589, 317), S(601, 322), S(615, 321), S(631, 320), S(642, 323), S(644, 326), S(643, 313), S(698, 240), + S(352, 220), S(270, 394), S(295, 418), S(312, 427), S(324, 439), S(330, 450), S(337, 459), S(346, 461), S(353, 470), S(365, 470), S(379, 469), S(390, 468), S(397, 466), S(416, 437), S(514, 323), }; inline const std::array QUEEN_MOBILITY = { - S(849, 311), S(1079, 77), S(1121, 255), S(1155, 370), S(1176, 456), S(1188, 547), S(1199, 585), S(1212, 577), S(1218, 616), S(1227, 616), S(1238, 609), S(1250, 593), S(1259, 583), S(1261, 594), S(1268, 578), S(1266, 585), S(1269, 577), S(1275, 569), S(1284, 553), S(1295, 544), S(1297, 528), S(1303, 507), S(1298, 512), S(1279, 461), S(1246, 472), S(1239, 446), S(1180, 504), S(1173, 417), + S(556, 415), S(693, 441), S(717, 552), S(736, 661), S(751, 706), S(760, 749), S(766, 778), S(773, 790), S(776, 815), S(779, 829), S(785, 834), S(790, 841), S(798, 838), S(801, 841), S(806, 837), S(804, 840), S(804, 840), S(812, 832), S(820, 821), S(825, 822), S(832, 802), S(859, 760), S(845, 774), S(847, 715), S(833, 708), S(820, 688), S(752, 748), S(774, 651), }; inline const std::array KING_MOBILITY = { - S(482, 10), S(93, -89), S(20, -6), S(13, 20), S(-9, 21), S(-20, 10), S(-14, 7), S(-13, -0), S(7, -42), + S(415, -60), S(112, -106), S(27, -17), S(14, 15), S(-7, 14), S(-26, 16), S(-17, 7), S(-31, 14), S(-13, -32), }; inline const std::array PT_INNER_RING_ATTACKS = { - S(10, -5), S(11, -13), S(10, -10), S(4, -5), S(1, 97), + S(11, -2), S(14, 87), S(12, 78), S(4, 10), S(4, -86), }; inline const std::array PT_OUTER_RING_ATTACKS = { - S(6, -3), S(4, -8), S(4, -7), S(4, -4), S(6, 300), + S(4, -19), S(5, 21), S(4, 12), S(4, 15), S(8, 862), }; -inline const PParam PAWN_THREAT_KNIGHT = S(282, 33); -inline const PParam PAWN_THREAT_BISHOP = S(281, 46); -inline const PParam PAWN_THREAT_ROOK = S(287, 22); -inline const PParam PAWN_THREAT_QUEEN = S(216, -134); +inline const PParam PAWN_THREAT_KNIGHT = S(220, 80); +inline const PParam PAWN_THREAT_BISHOP = S(200, 125); +inline const PParam PAWN_THREAT_ROOK = S(191, 119); +inline const PParam PAWN_THREAT_QUEEN = S(177, -35); -inline const PParam KNIGHT_THREAT_BISHOP = S(169, 52); -inline const PParam KNIGHT_THREAT_ROOK = S(311, -12); -inline const PParam KNIGHT_THREAT_QUEEN = S(211, -99); +inline const PParam KNIGHT_THREAT_BISHOP = S(113, 92); +inline const PParam KNIGHT_THREAT_ROOK = S(231, 58); +inline const PParam KNIGHT_THREAT_QUEEN = S(151, 1); -inline const PParam BISHOP_THREAT_KNIGHT = S(143, 23); -inline const PParam BISHOP_THREAT_ROOK = S(314, 23); -inline const PParam BISHOP_THREAT_QUEEN = S(256, -0); +inline const PParam BISHOP_THREAT_KNIGHT = S(107, 51); +inline const PParam BISHOP_THREAT_ROOK = S(217, 114); +inline const PParam BISHOP_THREAT_QUEEN = S(181, 83); inline const std::array BISHOP_PAWNS = { - S(-3, -20), S(-4, -9), S(-11, -14), S(-21, -19), S(-32, -22), S(-41, -25), S(-49, -32), S(-55, -32), S(-66, -32), + S(7, -29), S(-4, -8), S(-6, -16), S(-10, -25), S(-14, -35), S(-19, -40), S(-21, -52), S(-28, -50), S(-38, -51), }; -inline const PParam ROOK_LINEUP = S(20, 87); +inline const PParam ROOK_LINEUP = S(12, 64); inline const std::array PAWN_PSQT = { - S(552, 158), S(412, 261), S(515, 231), S(437, 133), S(437, 115), S(381, 161), S(343, 194), S(475, 128), // - S(226, 114), S(269, 159), S(252, 94), S(192, 37), S(160, 28), S(161, 68), S(165, 107), S(138, 126), // - S(155, 108), S(130, 110), S(142, 66), S(126, 46), S(109, 47), S(95, 74), S(64, 108), S(78, 121), // - S(98, 85), S(99, 94), S(113, 62), S(105, 55), S(80, 58), S(76, 77), S(26, 109), S(30, 105), // - S(86, 67), S(135, 64), S(122, 89), S(109, 77), S(76, 77), S(58, 80), S(28, 96), S(23, 90), // - S(104, 68), S(216, 54), S(211, 94), S(147, 88), S(107, 90), S(92, 80), S(63, 95), S(48, 100), // + S(310, 267), S(178, 336), S(307, 324), S(281, 253), S(307, 205), S(202, 282), S(140, 319), S(231, 294), // + S(139, 152), S(180, 174), S(201, 131), S(169, 94), S(148, 76), S(119, 123), S(94, 175), S(47, 198), // + S(89, 129), S(73, 138), S(104, 96), S(100, 77), S(88, 71), S(61, 97), S(11, 143), S(2, 170), // + S(60, 91), S(47, 117), S(75, 92), S(64, 87), S(41, 88), S(25, 109), S(-37, 148), S(-32, 139), // + S(63, 60), S(104, 59), S(85, 104), S(65, 106), S(33, 104), S(6, 114), S(-31, 133), S(-33, 123), // + S(74, 65), S(173, 64), S(154, 117), S(90, 135), S(57, 126), S(34, 118), S(2, 134), S(-14, 137), // }; inline const std::array KNIGHT_PSQT = { - S(-333, -71), S(-65, 146), S(-36, -79), S(204, 134), S(124, 155), S(2, 130), S(-155, 178), S(-376, 13), // - S(166, 105), S(229, 111), S(298, 111), S(308, 110), S(304, 118), S(221, 139), S(185, 140), S(149, 125), // - S(277, 86), S(323, 99), S(349, 126), S(332, 148), S(308, 165), S(242, 170), S(234, 130), S(192, 133), // - S(352, 107), S(380, 113), S(376, 139), S(375, 161), S(372, 170), S(317, 163), S(291, 152), S(276, 129), // - S(330, 113), S(364, 100), S(352, 143), S(353, 156), S(327, 160), S(319, 154), S(299, 125), S(249, 142), // - S(248, 108), S(285, 99), S(290, 119), S(306, 143), S(305, 141), S(252, 136), S(229, 118), S(178, 117), // - S(268, 100), S(281, 102), S(259, 100), S(265, 124), S(255, 123), S(210, 100), S(199, 118), S(152, 74), // - S(170, 83), S(222, 152), S(247, 92), S(263, 96), S(248, 110), S(200, 105), S(187, 132), S(116, 95), // + S(-237, -104), S(-131, 173), S(-128, 81), S(133, 140), S(75, 137), S(-91, 166), S(-237, 218), S(-286, -16), // + S(97, 131), S(146, 144), S(247, 96), S(249, 106), S(234, 127), S(154, 138), S(101, 165), S(73, 145), // + S(199, 111), S(237, 124), S(265, 146), S(265, 133), S(219, 172), S(149, 195), S(150, 151), S(117, 143), // + S(254, 148), S(276, 150), S(275, 166), S(265, 193), S(261, 204), S(209, 201), S(194, 182), S(186, 155), // + S(227, 161), S(272, 130), S(244, 179), S(238, 201), S(213, 208), S(206, 200), S(204, 153), S(159, 169), // + S(162, 143), S(191, 144), S(181, 183), S(191, 201), S(186, 203), S(146, 193), S(136, 162), S(106, 132), // + S(171, 150), S(192, 146), S(162, 151), S(165, 172), S(154, 173), S(127, 132), S(114, 153), S(102, 72), // + S(106, 107), S(154, 165), S(169, 132), S(183, 125), S(167, 144), S(133, 120), S(117, 146), S(77, 75), // }; inline const std::array BISHOP_PSQT = { - S(98, 238), S(146, 205), S(-60, 244), S(40, 204), S(76, 194), S(49, 214), S(134, 205), S(116, 204), // - S(243, 115), S(224, 185), S(231, 171), S(193, 184), S(210, 188), S(218, 191), S(265, 172), S(227, 159), // - S(358, 127), S(372, 150), S(363, 167), S(333, 171), S(299, 169), S(315, 160), S(324, 164), S(309, 145), // - S(302, 150), S(346, 145), S(356, 165), S(368, 187), S(394, 183), S(312, 172), S(299, 156), S(264, 156), // - S(321, 109), S(343, 146), S(361, 152), S(385, 160), S(362, 177), S(329, 171), S(284, 171), S(260, 146), // - S(347, 125), S(395, 125), S(418, 143), S(365, 165), S(350, 154), S(352, 160), S(351, 143), S(280, 149), // - S(312, 102), S(422, 109), S(386, 120), S(348, 140), S(326, 145), S(326, 128), S(323, 127), S(322, 107), // - S(342, 105), S(330, 131), S(328, 165), S(351, 107), S(342, 124), S(349, 160), S(343, 138), S(317, 130), // + S(27, 258), S(26, 250), S(-249, 315), S(-114, 249), S(-125, 272), S(-144, 275), S(-30, 273), S(54, 247), // + S(150, 174), S(98, 246), S(136, 194), S(75, 227), S(86, 229), S(110, 224), S(149, 220), S(128, 197), // + S(230, 194), S(240, 209), S(241, 209), S(224, 198), S(188, 205), S(187, 222), S(203, 213), S(193, 194), // + S(200, 182), S(238, 185), S(238, 210), S(238, 241), S(270, 229), S(197, 213), S(200, 187), S(160, 189), // + S(225, 142), S(242, 171), S(246, 198), S(251, 226), S(227, 240), S(209, 222), S(175, 204), S(170, 165), // + S(248, 155), S(281, 167), S(289, 200), S(236, 222), S(228, 207), S(221, 219), S(232, 190), S(176, 184), // + S(213, 130), S(306, 158), S(265, 168), S(227, 193), S(210, 193), S(214, 169), S(216, 166), S(212, 154), // + S(242, 139), S(230, 162), S(224, 197), S(239, 157), S(228, 169), S(231, 206), S(227, 184), S(219, 160), // }; inline const std::array ROOK_PSQT = { - S(621, 247), S(662, 248), S(643, 264), S(618, 243), S(585, 258), S(561, 268), S(568, 278), S(560, 286), // - S(560, 276), S(649, 272), S(699, 258), S(632, 264), S(610, 285), S(589, 289), S(539, 305), S(532, 303), // - S(513, 286), S(634, 266), S(660, 241), S(607, 255), S(567, 276), S(546, 282), S(548, 289), S(506, 307), // - S(472, 274), S(574, 256), S(597, 242), S(559, 251), S(551, 266), S(525, 282), S(522, 274), S(459, 297), // - S(408, 234), S(497, 235), S(495, 244), S(463, 256), S(453, 263), S(460, 266), S(418, 277), S(396, 269), // - S(372, 201), S(457, 203), S(455, 226), S(432, 233), S(423, 240), S(410, 256), S(399, 233), S(359, 243), // - S(251, 234), S(393, 194), S(423, 201), S(422, 213), S(407, 219), S(400, 224), S(374, 219), S(342, 238), // - S(310, 228), S(342, 243), S(421, 200), S(435, 202), S(422, 214), S(405, 228), S(392, 225), S(364, 242), // + S(424, 324), S(456, 324), S(428, 342), S(450, 308), S(432, 310), S(397, 321), S(379, 350), S(369, 356), // + S(309, 395), S(397, 378), S(477, 342), S(426, 350), S(406, 362), S(386, 363), S(308, 403), S(285, 415), // + S(287, 383), S(401, 357), S(462, 315), S(443, 303), S(390, 337), S(345, 360), S(340, 367), S(266, 412), // + S(283, 354), S(369, 351), S(404, 323), S(380, 325), S(371, 335), S(326, 365), S(318, 367), S(239, 399), // + S(258, 297), S(328, 306), S(320, 319), S(298, 317), S(275, 341), S(262, 360), S(228, 362), S(204, 363), // + S(245, 247), S(313, 266), S(301, 286), S(285, 284), S(268, 298), S(240, 327), S(236, 306), S(198, 319), // + S(131, 271), S(271, 227), S(283, 246), S(274, 267), S(257, 275), S(248, 283), S(231, 269), S(204, 283), // + S(198, 253), S(223, 273), S(281, 257), S(295, 251), S(283, 260), S(262, 277), S(250, 276), S(229, 286), // }; inline const std::array QUEEN_PSQT = { - S(914, 420), S(944, 392), S(918, 479), S(894, 564), S(892, 495), S(893, 504), S(881, 461), S(821, 548), // - S(911, 506), S(924, 540), S(926, 557), S(807, 604), S(793, 650), S(831, 661), S(827, 599), S(844, 527), // - S(937, 405), S(965, 530), S(934, 579), S(871, 638), S(835, 644), S(869, 568), S(879, 545), S(879, 483), // - S(942, 391), S(955, 528), S(901, 601), S(913, 590), S(886, 652), S(864, 594), S(899, 517), S(867, 539), // - S(943, 405), S(950, 460), S(937, 506), S(906, 577), S(893, 613), S(891, 532), S(877, 514), S(884, 466), // - S(914, 331), S(966, 380), S(973, 456), S(934, 475), S(911, 520), S(910, 549), S(897, 502), S(884, 397), // - S(864, 285), S(910, 256), S(928, 353), S(958, 354), S(931, 442), S(911, 429), S(876, 481), S(886, 449), // - S(834, 302), S(848, 148), S(876, 186), S(913, 286), S(922, 385), S(916, 320), S(909, 319), S(859, 425), // + S(583, 566), S(644, 498), S(549, 625), S(503, 686), S(495, 661), S(543, 607), S(561, 559), S(505, 620), // + S(569, 646), S(540, 730), S(526, 738), S(367, 820), S(375, 811), S(454, 777), S(501, 669), S(508, 652), // + S(533, 694), S(576, 703), S(514, 771), S(455, 796), S(432, 789), S(486, 719), S(533, 645), S(548, 584), // + S(580, 583), S(588, 657), S(520, 729), S(513, 750), S(506, 760), S(516, 677), S(567, 600), S(542, 599), // + S(601, 545), S(592, 610), S(561, 663), S(538, 694), S(533, 711), S(532, 669), S(548, 599), S(577, 520), // + S(583, 494), S(618, 554), S(616, 604), S(584, 594), S(576, 597), S(572, 621), S(583, 554), S(562, 524), // + S(570, 373), S(606, 400), S(612, 459), S(623, 498), S(606, 532), S(600, 502), S(563, 538), S(571, 523), // + S(548, 397), S(582, 252), S(603, 280), S(618, 386), S(615, 460), S(613, 409), S(600, 436), S(563, 474), // }; inline const std::array KING_PSQT = { - S(-224, -243), S(550, 73), S(441, 70), S(237, -44), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(285, -71), S(580, 61), S(497, 84), S(331, 6), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(377, -9), S(640, 40), S(618, 43), S(455, -5), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(185, -30), S(504, 12), S(499, 24), S(426, 5), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-15, -37), S(318, -20), S(381, -17), S(346, -17), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-80, -11), S(185, -8), S(193, -1), S(187, -18), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-78, -12), S(22, 34), S(-31, 48), S(-65, 37), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-229, -26), S(-94, -19), S(-198, 19), S(-212, -8), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-149, -313), S(187, 238), S(109, 132), S(-21, -20), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(161, -45), S(238, 249), S(108, 212), S(75, 29), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(158, 56), S(300, 154), S(212, 132), S(153, 27), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(22, 13), S(278, 79), S(125, 109), S(76, 100), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-84, -6), S(171, 49), S(90, 89), S(-22, 142), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-45, -38), S(153, 12), S(37, 66), S(-6, 105), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(16, -91), S(80, -23), S(-32, 29), S(-100, 73), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-87, -158), S(10, -107), S(-102, -71), S(-110, -83), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // }; inline const std::array, 4> KING_SHELTER = {{ - {{ S(4, -22), S(-10, 11), S(-12, 4), S(-7, -7), S(-11, -6), S(-17, 9), S(-11, 12), }}, - {{ S(1, -16), S(-19, 4), S(-16, 1), S(-10, -12), S(-17, -2), S(-23, 34), S(-27, 79), }}, - {{ S(-5, -1), S(-16, 28), S(-11, 4), S(-10, -6), S(-16, 3), S(-21, 26), S(-18, 31), }}, - {{ S(-3, -13), S(-18, -8), S(-10, -15), S(-8, -20), S(-13, -14), S(-19, -4), S(-21, -6), }}, + {{ S(9, -92), S(-7, -63), S(-11, -85), S(-4, -110), S(-4, -103), S(-10, -109), S(-5, -62), }}, + {{ S(-4, -79), S(-31, -183), S(-28, -113), S(-19, -70), S(-18, -45), S(-26, -131), S(-28, -193), }}, + {{ S(-17, -85), S(-24, -239), S(-25, -66), S(-24, -35), S(-22, -32), S(-24, -43), S(-23, -195), }}, + {{ S(-4, -9), S(-25, -180), S(-15, 10), S(-11, 16), S(-11, -4), S(-16, 58), S(-19, -104), }}, }}; inline const std::array BLOCKED_SHELTER_STORM = { - S(0, 0), S(0, 0), S(9, 11), S(-8, 22), S(-4, 16), S(10, -5), S(13, -33), + S(0, 0), S(0, 0), S(6, -26), S(-17, -129), S(-16, -94), S(-12, 2), S(-14, -76), }; inline const std::array, 4> SHELTER_STORM = {{ - {{ S(4, 2), S(-9, 45), S(-9, 30), S(-7, 19), S(-5, 3), S(-2, -4), S(-4, -2), }}, - {{ S(2, 6), S(-10, 44), S(-20, 43), S(-14, 26), S(-10, 11), S(-6, 6), S(-3, 10), }}, - {{ S(-3, 6), S(-14, 29), S(-18, 35), S(-11, 20), S(-6, 9), S(-5, 4), S(-5, 3), }}, - {{ S(-3, 5), S(-11, 20), S(-16, 22), S(-7, 14), S(-4, 10), S(-4, 3), S(-4, 3), }}, + {{ S(-7, -58), S(-18, -115), S(-16, -74), S(-14, -88), S(-15, -108), S(-15, -81), S(-18, -113), }}, + {{ S(-7, -106), S(-15, -104), S(-22, -117), S(-18, -121), S(-18, -127), S(-21, -93), S(-15, -86), }}, + {{ S(-14, -58), S(-19, -11), S(-19, -68), S(-14, -81), S(-14, -84), S(-19, -61), S(-18, -22), }}, + {{ S(-16, -93), S(-21, -73), S(-22, -144), S(-15, -80), S(-13, -67), S(-21, -120), S(-23, -50), }}, }}; inline TunableSigmoid<32> KING_SAFETY_ACTIVATION( - 1525, 546, -42, 59 + 1129, 74, -11, -279 ); -inline VParam WINNABLE_PAWNS = V(27); -inline VParam WINNABLE_BIAS = V(-249); +inline VParam WINNABLE_PAWNS = V(46); +inline VParam WINNABLE_BIAS = V(-439); -// Epoch duration: 7.3709s -// Epoch duration: 9.05276s +// Epoch duration: 7.41143s // clang-format on } // namespace Clockwork diff --git a/src/eval_types.hpp b/src/eval_types.hpp index 91869be2..191ddc17 100644 --- a/src/eval_types.hpp +++ b/src/eval_types.hpp @@ -103,7 +103,9 @@ class PScore { // complexity_add PScore complexity_add(Score val) { - return PScore{mg(), static_cast(std::max(0, eg() + val))}; + i32 m = (eg() > 0) - (eg() < 0); + return PScore{ + mg(), static_cast(eg() + std::max(val, static_cast(-std::abs(eg()))) * m)}; } friend std::ostream& operator<<(std::ostream& stream, const PScore& score) { diff --git a/src/evaltune_main.cpp b/src/evaltune_main.cpp index b8acfdd5..71349373 100644 --- a/src/evaltune_main.cpp +++ b/src/evaltune_main.cpp @@ -424,7 +424,7 @@ int main() { << "s\n"; if (epoch > 5) { - optim.set_lr(optim.get_lr() * 0.99); + optim.set_lr(optim.get_lr() * 0.99274); } } diff --git a/src/evaluation.cpp b/src/evaluation.cpp index 6b6934ee..b6753c15 100644 --- a/src/evaluation.cpp +++ b/src/evaluation.cpp @@ -418,12 +418,17 @@ PScore king_safety_activation(const Position& pos, PScore& king_safety_score) { PScore apply_winnable(const Position& pos, PScore& score) { const Color color = pos.active_color(); + i32 pawn_count = (pos.bitboard_for(Color::White, PieceType::Pawn) | pos.bitboard_for(Color::Black, PieceType::Pawn)) .ipopcount(); Score winnable = WINNABLE_PAWNS * pawn_count + WINNABLE_BIAS; - return score.complexity_add(color == Color::White ? winnable : -winnable); + if (score.eg() < 0) { + winnable = -winnable; + } + + return score.complexity_add(winnable); } Score evaluate_white_pov(const Position& pos, const PsqtState& psqt_state) { diff --git a/src/tuning/graph.cpp b/src/tuning/graph.cpp index c882cfc9..3b9edf20 100644 --- a/src/tuning/graph.cpp +++ b/src/tuning/graph.cpp @@ -504,25 +504,35 @@ void Graph::backward() { f64x2 val_lhs = pair_vals[node.lhs()]; f64 val_rhs = vals[node.rhs()]; + // First component always passes through f64x2 grad_pair = f64x2::make(grad_out.first(), 0.0); + f64 grad_rhs = 0.0; - f64 add_res = val_lhs.second() + val_rhs; - + // For the second component if (val_lhs.second() > 0) { + // Forward: res.second = max(0.0, val_lhs.second() + val_rhs) + f64 add_res = val_lhs.second() + val_rhs; if (add_res > 0.0) { + // Gradient flows through both inputs grad_pair = f64x2::make(grad_out.first(), grad_out.second()); - grads[node.rhs()] += grad_out.second(); + grad_rhs = grad_out.second(); } } else if (val_lhs.second() < 0) { + // Forward: res.second = min(0.0, val_lhs.second() + val_rhs) + f64 add_res = val_lhs.second() + val_rhs; if (add_res < 0.0) { + // Gradient flows through both inputs grad_pair = f64x2::make(grad_out.first(), grad_out.second()); - grads[node.rhs()] += grad_out.second(); + grad_rhs = grad_out.second(); } } else { + // val_lhs.second() == 0: output = input (no addition) grad_pair = grad_out; + grad_rhs = 0.0; } pair_grads[node.lhs()] = f64x2::add(pair_grads[node.lhs()], grad_pair); + grads[node.rhs()] += grad_rhs; break; } diff --git a/src/tuning/value.cpp b/src/tuning/value.cpp index 0d5b66b9..50534dc4 100644 --- a/src/tuning/value.cpp +++ b/src/tuning/value.cpp @@ -87,6 +87,12 @@ f64 PairHandle::first() const { f64 PairHandle::second() const { return get_values().second(); } +f64 PairHandle::mg() const { + return get_values().first(); +} +f64 PairHandle::eg() const { + return get_values().second(); +} void PairHandle::set_values(const f64x2& v) const { Graph::get().set_pair_values(index, v); diff --git a/src/tuning/value.hpp b/src/tuning/value.hpp index 806fabd0..b24ff6a0 100644 --- a/src/tuning/value.hpp +++ b/src/tuning/value.hpp @@ -59,7 +59,9 @@ struct PairHandle { f64x2 get_values() const; f64x2 get_gradients() const; f64 first() const; + f64 mg() const; f64 second() const; + f64 eg() const; void set_values(const f64x2& v) const; void set_values(f64 f, f64 s) const; void zero_grad() const; From 9d9839890537e03499e0fd50d29f3959316488aa Mon Sep 17 00:00:00 2001 From: TheRealGioviok <425gioviok@gmail.com> Date: Mon, 2 Feb 2026 04:55:10 +0100 Subject: [PATCH 5/9] Bench: 18563228 --- src/eval_types.hpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/eval_types.hpp b/src/eval_types.hpp index 191ddc17..5f8552f0 100644 --- a/src/eval_types.hpp +++ b/src/eval_types.hpp @@ -103,9 +103,14 @@ class PScore { // complexity_add PScore complexity_add(Score val) { - i32 m = (eg() > 0) - (eg() < 0); - return PScore{ - mg(), static_cast(eg() + std::max(val, static_cast(-std::abs(eg()))) * m)}; + if (eg() == 0) { + return *this; + } + else if (eg() > 0) { + return PScore{mg(), static_cast(std::max(0, eg() + val))}; + } else { + return PScore{mg(), static_cast(std::min(0, eg() + val))}; + } } friend std::ostream& operator<<(std::ostream& stream, const PScore& score) { From 04a010f0b79f4882de9064f439a72f84cd254d6e Mon Sep 17 00:00:00 2001 From: TheRealGioviok <425gioviok@gmail.com> Date: Mon, 2 Feb 2026 04:56:30 +0100 Subject: [PATCH 6/9] Bench: 19080916 From c38c2aa89e90919f5cba0fd133171a474dc3539b Mon Sep 17 00:00:00 2001 From: TheRealGioviok <425gioviok@gmail.com> Date: Mon, 2 Feb 2026 04:58:02 +0100 Subject: [PATCH 7/9] Bench: 19080916 --- src/eval_types.hpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/eval_types.hpp b/src/eval_types.hpp index 5f8552f0..8a117d01 100644 --- a/src/eval_types.hpp +++ b/src/eval_types.hpp @@ -102,16 +102,19 @@ class PScore { } // complexity_add - PScore complexity_add(Score val) { - if (eg() == 0) { - return *this; - } - else if (eg() > 0) { - return PScore{mg(), static_cast(std::max(0, eg() + val))}; - } else { - return PScore{mg(), static_cast(std::min(0, eg() + val))}; - } - } +PScore complexity_add(Score val) { + const Score e = eg(); + if (e == 0) + return *this; + + const Score sum = e + val; + return PScore{ + mg(), + static_cast((e > 0) ? std::max(sum, Score{0}) + : std::min(sum, Score{0})) + }; +} + friend std::ostream& operator<<(std::ostream& stream, const PScore& score) { stream << "(" << score.mg() << "\t" << score.eg() << ")"; From b76262628000a96ee70204c504739b2cc8066289 Mon Sep 17 00:00:00 2001 From: TheRealGioviok <425gioviok@gmail.com> Date: Mon, 2 Feb 2026 20:06:00 +0100 Subject: [PATCH 8/9] Bench: 17899948 --- src/eval_constants.hpp | 206 ++++++++++++++++++++--------------------- src/evaltune_main.cpp | 4 +- src/evaluation.cpp | 2 - 3 files changed, 105 insertions(+), 107 deletions(-) diff --git a/src/eval_constants.hpp b/src/eval_constants.hpp index f83531be..c57d03ef 100644 --- a/src/eval_constants.hpp +++ b/src/eval_constants.hpp @@ -5,175 +5,175 @@ namespace Clockwork { // clang-format off -inline const PParam PAWN_MAT = S(152, 201); -inline const PParam KNIGHT_MAT = S(564, 560); -inline const PParam BISHOP_MAT = S(601, 597); -inline const PParam ROOK_MAT = S(445, 670); -inline const PParam QUEEN_MAT = S(1049, 1156); -inline const PParam TEMPO_VAL = S(60, 17); - -inline const PParam BISHOP_PAIR_VAL = S(50, 193); -inline const PParam ROOK_OPEN_VAL = S(111, -18); -inline const PParam ROOK_SEMIOPEN_VAL = S(46, 21); - -inline const PParam DOUBLED_PAWN_VAL = S(-8, -65); +inline const PParam PAWN_MAT = S(140, 194); +inline const PParam KNIGHT_MAT = S(591, 590); +inline const PParam BISHOP_MAT = S(635, 620); +inline const PParam ROOK_MAT = S(495, 643); +inline const PParam QUEEN_MAT = S(1166, 1021); +inline const PParam TEMPO_VAL = S(59, 20); + +inline const PParam BISHOP_PAIR_VAL = S(54, 190); +inline const PParam ROOK_OPEN_VAL = S(106, -12); +inline const PParam ROOK_SEMIOPEN_VAL = S(43, 23); + +inline const PParam DOUBLED_PAWN_VAL = S(-6, -67); inline const PParam ISOLATED_PAWN_VAL = S(-19, -20); -inline const PParam POTENTIAL_CHECKER_VAL = S(-56, -11); -inline const PParam OUTPOST_KNIGHT_VAL = S(37, 57); -inline const PParam OUTPOST_BISHOP_VAL = S(58, 25); +inline const PParam POTENTIAL_CHECKER_VAL = S(-51, -21); +inline const PParam OUTPOST_KNIGHT_VAL = S(36, 63); +inline const PParam OUTPOST_BISHOP_VAL = S(50, 38); -inline const PParam PAWN_PUSH_THREAT_KNIGHT = S(44, 5); +inline const PParam PAWN_PUSH_THREAT_KNIGHT = S(43, 5); inline const PParam PAWN_PUSH_THREAT_BISHOP = S(56, -20); -inline const PParam PAWN_PUSH_THREAT_ROOK = S(29, 49); -inline const PParam PAWN_PUSH_THREAT_QUEEN = S(70, -34); +inline const PParam PAWN_PUSH_THREAT_ROOK = S(28, 50); +inline const PParam PAWN_PUSH_THREAT_QUEEN = S(70, -41); inline const std::array PAWN_PHALANX = { - S(15, 1), S(41, 24), S(60, 49), S(139, 142), S(386, 214), S(496, 515), + S(17, -0), S(40, 24), S(58, 49), S(136, 148), S(359, 242), S(442, 735), }; inline const std::array DEFENDED_PAWN = { - S(55, 32), S(47, 22), S(55, 49), S(117, 140), S(423, 68), + S(55, 32), S(46, 24), S(55, 51), S(121, 140), S(423, 73), }; inline const std::array PASSED_PAWN = { - S(-92, -128), S(-86, -104), S(-65, 4), S(-7, 103), S(81, 236), S(271, 350), + S(-79, -112), S(-74, -89), S(-49, 18), S(12, 120), S(104, 256), S(279, 359), }; inline const std::array DEFENDED_PASSED_PUSH = { - S(41, -49), S(38, -7), S(24, 32), S(2, 109), S(51, 212), S(215, 256), + S(34, -41), S(32, 0), S(21, 39), S(2, 112), S(57, 212), S(204, 277), }; inline const std::array BLOCKED_PASSED_PAWN = { - S(24, -45), S(7, 2), S(2, -25), S(-4, -52), S(-3, -130), S(-205, -230), + S(23, -46), S(4, 6), S(0, -22), S(-5, -50), S(-16, -113), S(-221, -216), }; inline const std::array FRIENDLY_KING_PASSED_PAWN_DISTANCE = { - S(0, 0), S(-2, 155), S(-18, 129), S(-6, 55), S(4, 17), S(9, 15), S(44, 11), S(20, 1), + S(0, 0), S(-6, 152), S(-16, 116), S(-9, 45), S(-3, 9), S(2, 7), S(34, 6), S(5, 3), }; inline const std::array ENEMY_KING_PASSED_PAWN_DISTANCE = { - S(0, 0), S(-289, -50), S(-15, 12), S(-17, 69), S(21, 106), S(40, 128), S(58, 132), S(39, 128), + S(0, 0), S(-329, -35), S(-49, 27), S(-27, 60), S(13, 98), S(34, 116), S(55, 118), S(35, 115), }; inline const std::array KNIGHT_MOBILITY = { - S(100, -5), S(172, 163), S(208, 248), S(236, 283), S(278, 298), S(303, 328), S(337, 325), S(371, 332), S(428, 242), + S(66, 3), S(137, 172), S(173, 258), S(201, 293), S(241, 310), S(266, 343), S(298, 341), S(329, 355), S(381, 272), }; inline const std::array BISHOP_MOBILITY = { - S(111, -0), S(156, 165), S(212, 223), S(241, 264), S(267, 291), S(286, 310), S(296, 325), S(313, 330), S(323, 341), S(350, 321), S(370, 311), S(420, 258), S(434, 253), S(468, 203), + S(85, -2), S(129, 168), S(184, 228), S(211, 272), S(236, 302), S(253, 325), S(260, 344), S(275, 353), S(281, 371), S(305, 355), S(317, 354), S(365, 304), S(365, 315), S(391, 276), }; inline const std::array ROOK_MOBILITY = { - S(352, 220), S(270, 394), S(295, 418), S(312, 427), S(324, 439), S(330, 450), S(337, 459), S(346, 461), S(353, 470), S(365, 470), S(379, 469), S(390, 468), S(397, 466), S(416, 437), S(514, 323), + S(317, 237), S(237, 410), S(263, 434), S(280, 443), S(291, 455), S(298, 466), S(304, 476), S(314, 477), S(320, 487), S(332, 487), S(344, 488), S(353, 490), S(358, 489), S(374, 465), S(478, 344), }; inline const std::array QUEEN_MOBILITY = { - S(556, 415), S(693, 441), S(717, 552), S(736, 661), S(751, 706), S(760, 749), S(766, 778), S(773, 790), S(776, 815), S(779, 829), S(785, 834), S(790, 841), S(798, 838), S(801, 841), S(806, 837), S(804, 840), S(804, 840), S(812, 832), S(820, 821), S(825, 822), S(832, 802), S(859, 760), S(845, 774), S(847, 715), S(833, 708), S(820, 688), S(752, 748), S(774, 651), + S(494, 521), S(649, 495), S(674, 604), S(692, 716), S(708, 763), S(716, 806), S(722, 837), S(730, 847), S(733, 871), S(737, 883), S(743, 888), S(748, 895), S(757, 890), S(760, 892), S(765, 889), S(765, 889), S(767, 886), S(775, 876), S(783, 865), S(789, 864), S(801, 836), S(826, 793), S(820, 799), S(820, 740), S(807, 730), S(799, 706), S(735, 768), S(756, 666), }; inline const std::array KING_MOBILITY = { - S(415, -60), S(112, -106), S(27, -17), S(14, 15), S(-7, 14), S(-26, 16), S(-17, 7), S(-31, 14), S(-13, -32), + S(481, -173), S(107, -108), S(29, -27), S(16, 6), S(-3, 6), S(-21, 3), S(-23, 7), S(-38, 16), S(-27, -24), }; inline const std::array PT_INNER_RING_ATTACKS = { - S(11, -2), S(14, 87), S(12, 78), S(4, 10), S(4, -86), + S(12, -8), S(15, -16), S(13, -12), S(6, -8), S(2, 179), }; inline const std::array PT_OUTER_RING_ATTACKS = { - S(4, -19), S(5, 21), S(4, 12), S(4, 15), S(8, 862), + S(4, -0), S(7, -11), S(6, -9), S(5, -5), S(6, 429), }; -inline const PParam PAWN_THREAT_KNIGHT = S(220, 80); -inline const PParam PAWN_THREAT_BISHOP = S(200, 125); -inline const PParam PAWN_THREAT_ROOK = S(191, 119); -inline const PParam PAWN_THREAT_QUEEN = S(177, -35); +inline const PParam PAWN_THREAT_KNIGHT = S(216, 87); +inline const PParam PAWN_THREAT_BISHOP = S(193, 138); +inline const PParam PAWN_THREAT_ROOK = S(196, 116); +inline const PParam PAWN_THREAT_QUEEN = S(175, -37); -inline const PParam KNIGHT_THREAT_BISHOP = S(113, 92); -inline const PParam KNIGHT_THREAT_ROOK = S(231, 58); -inline const PParam KNIGHT_THREAT_QUEEN = S(151, 1); +inline const PParam KNIGHT_THREAT_BISHOP = S(112, 95); +inline const PParam KNIGHT_THREAT_ROOK = S(232, 57); +inline const PParam KNIGHT_THREAT_QUEEN = S(153, -6); -inline const PParam BISHOP_THREAT_KNIGHT = S(107, 51); -inline const PParam BISHOP_THREAT_ROOK = S(217, 114); -inline const PParam BISHOP_THREAT_QUEEN = S(181, 83); +inline const PParam BISHOP_THREAT_KNIGHT = S(107, 55); +inline const PParam BISHOP_THREAT_ROOK = S(216, 117); +inline const PParam BISHOP_THREAT_QUEEN = S(179, 93); inline const std::array BISHOP_PAWNS = { - S(7, -29), S(-4, -8), S(-6, -16), S(-10, -25), S(-14, -35), S(-19, -40), S(-21, -52), S(-28, -50), S(-38, -51), + S(7, -31), S(-3, -10), S(-6, -18), S(-9, -28), S(-13, -37), S(-18, -42), S(-20, -54), S(-27, -51), S(-38, -51), }; -inline const PParam ROOK_LINEUP = S(12, 64); +inline const PParam ROOK_LINEUP = S(11, 72); inline const std::array PAWN_PSQT = { - S(310, 267), S(178, 336), S(307, 324), S(281, 253), S(307, 205), S(202, 282), S(140, 319), S(231, 294), // - S(139, 152), S(180, 174), S(201, 131), S(169, 94), S(148, 76), S(119, 123), S(94, 175), S(47, 198), // - S(89, 129), S(73, 138), S(104, 96), S(100, 77), S(88, 71), S(61, 97), S(11, 143), S(2, 170), // - S(60, 91), S(47, 117), S(75, 92), S(64, 87), S(41, 88), S(25, 109), S(-37, 148), S(-32, 139), // - S(63, 60), S(104, 59), S(85, 104), S(65, 106), S(33, 104), S(6, 114), S(-31, 133), S(-33, 123), // - S(74, 65), S(173, 64), S(154, 117), S(90, 135), S(57, 126), S(34, 118), S(2, 134), S(-14, 137), // + S(313, 328), S(167, 420), S(300, 401), S(315, 264), S(333, 225), S(227, 306), S(166, 341), S(266, 306), // + S(117, 207), S(148, 241), S(190, 158), S(175, 96), S(153, 82), S(125, 133), S(97, 189), S(50, 216), // + S(82, 169), S(68, 169), S(110, 99), S(111, 79), S(99, 76), S(71, 107), S(24, 154), S(13, 183), // + S(55, 126), S(45, 146), S(81, 99), S(79, 89), S(57, 91), S(41, 115), S(-19, 156), S(-18, 149), // + S(54, 101), S(94, 105), S(79, 137), S(73, 122), S(44, 117), S(22, 123), S(-12, 139), S(-20, 134), // + S(68, 101), S(160, 113), S(144, 170), S(96, 150), S(66, 139), S(46, 132), S(16, 144), S(-2, 148), // }; inline const std::array KNIGHT_PSQT = { - S(-237, -104), S(-131, 173), S(-128, 81), S(133, 140), S(75, 137), S(-91, 166), S(-237, 218), S(-286, -16), // - S(97, 131), S(146, 144), S(247, 96), S(249, 106), S(234, 127), S(154, 138), S(101, 165), S(73, 145), // - S(199, 111), S(237, 124), S(265, 146), S(265, 133), S(219, 172), S(149, 195), S(150, 151), S(117, 143), // - S(254, 148), S(276, 150), S(275, 166), S(265, 193), S(261, 204), S(209, 201), S(194, 182), S(186, 155), // - S(227, 161), S(272, 130), S(244, 179), S(238, 201), S(213, 208), S(206, 200), S(204, 153), S(159, 169), // - S(162, 143), S(191, 144), S(181, 183), S(191, 201), S(186, 203), S(146, 193), S(136, 162), S(106, 132), // - S(171, 150), S(192, 146), S(162, 151), S(165, 172), S(154, 173), S(127, 132), S(114, 153), S(102, 72), // - S(106, 107), S(154, 165), S(169, 132), S(183, 125), S(167, 144), S(133, 120), S(117, 146), S(77, 75), // + S(-266, -64), S(-145, 183), S(-143, 91), S(92, 180), S(38, 173), S(-122, 199), S(-231, 210), S(-303, 4), // + S(67, 165), S(118, 178), S(201, 144), S(188, 167), S(180, 180), S(109, 187), S(72, 204), S(50, 173), // + S(162, 147), S(194, 168), S(207, 204), S(200, 201), S(169, 223), S(108, 239), S(119, 187), S(86, 176), // + S(228, 172), S(236, 194), S(233, 214), S(220, 247), S(221, 253), S(176, 240), S(168, 209), S(164, 178), // + S(211, 177), S(244, 162), S(216, 216), S(213, 234), S(189, 240), S(187, 225), S(185, 173), S(148, 179), // + S(155, 146), S(182, 153), S(172, 191), S(181, 215), S(177, 214), S(141, 195), S(130, 164), S(101, 133), // + S(167, 149), S(189, 143), S(156, 154), S(159, 174), S(150, 174), S(122, 132), S(107, 158), S(96, 75), // + S(101, 103), S(147, 163), S(164, 130), S(181, 123), S(162, 144), S(128, 119), S(113, 143), S(73, 70), // }; inline const std::array BISHOP_PSQT = { - S(27, 258), S(26, 250), S(-249, 315), S(-114, 249), S(-125, 272), S(-144, 275), S(-30, 273), S(54, 247), // - S(150, 174), S(98, 246), S(136, 194), S(75, 227), S(86, 229), S(110, 224), S(149, 220), S(128, 197), // - S(230, 194), S(240, 209), S(241, 209), S(224, 198), S(188, 205), S(187, 222), S(203, 213), S(193, 194), // - S(200, 182), S(238, 185), S(238, 210), S(238, 241), S(270, 229), S(197, 213), S(200, 187), S(160, 189), // - S(225, 142), S(242, 171), S(246, 198), S(251, 226), S(227, 240), S(209, 222), S(175, 204), S(170, 165), // - S(248, 155), S(281, 167), S(289, 200), S(236, 222), S(228, 207), S(221, 219), S(232, 190), S(176, 184), // - S(213, 130), S(306, 158), S(265, 168), S(227, 193), S(210, 193), S(214, 169), S(216, 166), S(212, 154), // - S(242, 139), S(230, 162), S(224, 197), S(239, 157), S(228, 169), S(231, 206), S(227, 184), S(219, 160), // + S(-3, 287), S(-12, 297), S(-285, 354), S(-155, 292), S(-164, 313), S(-186, 320), S(-58, 305), S(22, 281), // + S(123, 196), S(65, 279), S(93, 238), S(32, 268), S(47, 267), S(78, 258), S(119, 249), S(101, 220), // + S(194, 226), S(203, 245), S(200, 248), S(176, 247), S(146, 245), S(154, 253), S(172, 240), S(168, 213), // + S(164, 217), S(200, 225), S(198, 251), S(198, 282), S(230, 269), S(158, 251), S(170, 215), S(131, 213), // + S(192, 176), S(209, 206), S(214, 231), S(221, 255), S(196, 271), S(180, 250), S(147, 229), S(142, 191), // + S(218, 184), S(255, 193), S(265, 221), S(210, 246), S(206, 224), S(200, 236), S(208, 212), S(146, 214), // + S(186, 155), S(286, 172), S(243, 185), S(209, 205), S(189, 208), S(194, 182), S(193, 183), S(187, 176), // + S(217, 158), S(205, 177), S(204, 208), S(220, 167), S(209, 181), S(208, 222), S(205, 202), S(195, 180), // }; inline const std::array ROOK_PSQT = { - S(424, 324), S(456, 324), S(428, 342), S(450, 308), S(432, 310), S(397, 321), S(379, 350), S(369, 356), // - S(309, 395), S(397, 378), S(477, 342), S(426, 350), S(406, 362), S(386, 363), S(308, 403), S(285, 415), // - S(287, 383), S(401, 357), S(462, 315), S(443, 303), S(390, 337), S(345, 360), S(340, 367), S(266, 412), // - S(283, 354), S(369, 351), S(404, 323), S(380, 325), S(371, 335), S(326, 365), S(318, 367), S(239, 399), // - S(258, 297), S(328, 306), S(320, 319), S(298, 317), S(275, 341), S(262, 360), S(228, 362), S(204, 363), // - S(245, 247), S(313, 266), S(301, 286), S(285, 284), S(268, 298), S(240, 327), S(236, 306), S(198, 319), // - S(131, 271), S(271, 227), S(283, 246), S(274, 267), S(257, 275), S(248, 283), S(231, 269), S(204, 283), // - S(198, 253), S(223, 273), S(281, 257), S(295, 251), S(283, 260), S(262, 277), S(250, 276), S(229, 286), // + S(421, 375), S(445, 384), S(417, 399), S(434, 367), S(412, 374), S(377, 387), S(377, 399), S(365, 407), // + S(303, 453), S(383, 444), S(462, 405), S(407, 414), S(385, 429), S(373, 424), S(300, 461), S(279, 472), // + S(270, 451), S(373, 434), S(431, 395), S(414, 379), S(365, 408), S(324, 430), S(325, 430), S(257, 471), // + S(277, 410), S(355, 415), S(390, 390), S(368, 389), S(358, 401), S(321, 419), S(316, 416), S(238, 447), // + S(259, 344), S(327, 354), S(315, 376), S(295, 373), S(274, 394), S(263, 408), S(230, 407), S(210, 403), // + S(250, 288), S(313, 312), S(301, 336), S(286, 334), S(272, 344), S(248, 365), S(242, 345), S(205, 355), // + S(145, 295), S(276, 264), S(286, 293), S(277, 314), S(263, 319), S(252, 327), S(237, 307), S(210, 321), // + S(206, 287), S(229, 309), S(286, 296), S(299, 293), S(288, 302), S(268, 316), S(257, 312), S(237, 321), // }; inline const std::array QUEEN_PSQT = { - S(583, 566), S(644, 498), S(549, 625), S(503, 686), S(495, 661), S(543, 607), S(561, 559), S(505, 620), // - S(569, 646), S(540, 730), S(526, 738), S(367, 820), S(375, 811), S(454, 777), S(501, 669), S(508, 652), // - S(533, 694), S(576, 703), S(514, 771), S(455, 796), S(432, 789), S(486, 719), S(533, 645), S(548, 584), // - S(580, 583), S(588, 657), S(520, 729), S(513, 750), S(506, 760), S(516, 677), S(567, 600), S(542, 599), // - S(601, 545), S(592, 610), S(561, 663), S(538, 694), S(533, 711), S(532, 669), S(548, 599), S(577, 520), // - S(583, 494), S(618, 554), S(616, 604), S(584, 594), S(576, 597), S(572, 621), S(583, 554), S(562, 524), // - S(570, 373), S(606, 400), S(612, 459), S(623, 498), S(606, 532), S(600, 502), S(563, 538), S(571, 523), // - S(548, 397), S(582, 252), S(603, 280), S(618, 386), S(615, 460), S(613, 409), S(600, 436), S(563, 474), // + S(567, 609), S(619, 561), S(544, 685), S(509, 759), S(498, 736), S(522, 694), S(548, 610), S(493, 661), // + S(563, 674), S(530, 767), S(512, 813), S(375, 897), S(377, 890), S(444, 834), S(485, 716), S(499, 688), // + S(528, 738), S(571, 766), S(515, 851), S(455, 887), S(428, 882), S(477, 804), S(520, 712), S(538, 635), // + S(570, 650), S(575, 737), S(510, 814), S(501, 845), S(488, 854), S(500, 757), S(551, 673), S(531, 653), // + S(584, 621), S(574, 687), S(542, 750), S(513, 791), S(510, 796), S(509, 750), S(531, 662), S(557, 588), // + S(563, 566), S(598, 617), S(591, 681), S(558, 680), S(555, 668), S(550, 691), S(564, 612), S(543, 584), // + S(543, 459), S(583, 466), S(589, 528), S(599, 572), S(583, 604), S(577, 569), S(542, 601), S(552, 582), // + S(527, 470), S(557, 327), S(582, 345), S(596, 456), S(592, 528), S(591, 475), S(579, 498), S(545, 533), // }; inline const std::array KING_PSQT = { - S(-149, -313), S(187, 238), S(109, 132), S(-21, -20), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(161, -45), S(238, 249), S(108, 212), S(75, 29), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(158, 56), S(300, 154), S(212, 132), S(153, 27), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(22, 13), S(278, 79), S(125, 109), S(76, 100), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-84, -6), S(171, 49), S(90, 89), S(-22, 142), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-45, -38), S(153, 12), S(37, 66), S(-6, 105), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(16, -91), S(80, -23), S(-32, 29), S(-100, 73), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-87, -158), S(10, -107), S(-102, -71), S(-110, -83), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-67, -360), S(261, 213), S(164, 128), S(35, -43), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(238, -87), S(334, 188), S(178, 181), S(141, -24), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(225, 27), S(379, 100), S(276, 93), S(185, -22), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(72, 2), S(323, 43), S(169, 63), S(107, 25), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-31, -16), S(230, 7), S(148, 20), S(15, 38), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-21, -13), S(215, -5), S(109, 12), S(60, -6), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-1, -16), S(84, 32), S(-5, 40), S(-60, 16), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-115, -66), S(-16, -22), S(-119, -13), S(-120, -81), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // }; inline const std::array, 4> KING_SHELTER = {{ - {{ S(9, -92), S(-7, -63), S(-11, -85), S(-4, -110), S(-4, -103), S(-10, -109), S(-5, -62), }}, - {{ S(-4, -79), S(-31, -183), S(-28, -113), S(-19, -70), S(-18, -45), S(-26, -131), S(-28, -193), }}, - {{ S(-17, -85), S(-24, -239), S(-25, -66), S(-24, -35), S(-22, -32), S(-24, -43), S(-23, -195), }}, - {{ S(-4, -9), S(-25, -180), S(-15, 10), S(-11, 16), S(-11, -4), S(-16, 58), S(-19, -104), }}, + {{ S(15, -17), S(-3, 18), S(-7, 21), S(-0, 8), S(-0, 4), S(-7, 21), S(-1, 21), }}, + {{ S(4, -3), S(-23, 30), S(-19, 24), S(-11, 7), S(-10, 7), S(-19, 29), S(-22, 38), }}, + {{ S(-14, 4), S(-26, 31), S(-24, 12), S(-20, -1), S(-20, -0), S(-23, 12), S(-24, 27), }}, + {{ S(1, -12), S(-17, -12), S(-9, -15), S(-4, -19), S(-5, -17), S(-9, -13), S(-13, -13), }}, }}; inline const std::array BLOCKED_SHELTER_STORM = { - S(0, 0), S(0, 0), S(6, -26), S(-17, -129), S(-16, -94), S(-12, 2), S(-14, -76), + S(0, 0), S(0, 0), S(5, 26), S(-16, 31), S(-14, 20), S(-6, 8), S(-7, -8), }; inline const std::array, 4> SHELTER_STORM = {{ - {{ S(-7, -58), S(-18, -115), S(-16, -74), S(-14, -88), S(-15, -108), S(-15, -81), S(-18, -113), }}, - {{ S(-7, -106), S(-15, -104), S(-22, -117), S(-18, -121), S(-18, -127), S(-21, -93), S(-15, -86), }}, - {{ S(-14, -58), S(-19, -11), S(-19, -68), S(-14, -81), S(-14, -84), S(-19, -61), S(-18, -22), }}, - {{ S(-16, -93), S(-21, -73), S(-22, -144), S(-15, -80), S(-13, -67), S(-21, -120), S(-23, -50), }}, + {{ S(-3, 4), S(-13, 12), S(-12, 10), S(-11, 10), S(-11, 5), S(-10, 2), S(-13, 9), }}, + {{ S(-2, 2), S(-10, 8), S(-16, 13), S(-13, 10), S(-13, 6), S(-15, 10), S(-9, 7), }}, + {{ S(-8, 5), S(-13, 3), S(-14, 9), S(-10, 9), S(-9, 7), S(-13, 8), S(-12, 4), }}, + {{ S(-9, 7), S(-14, 9), S(-15, 8), S(-10, 12), S(-8, 12), S(-14, 8), S(-16, 8), }}, }}; inline TunableSigmoid<32> KING_SAFETY_ACTIVATION( - 1129, 74, -11, -279 + 1192, 541, -31, 51 ); -inline VParam WINNABLE_PAWNS = V(46); -inline VParam WINNABLE_BIAS = V(-439); +inline VParam WINNABLE_PAWNS = V(47); +inline VParam WINNABLE_BIAS = V(-451); -// Epoch duration: 7.41143s +// Epoch duration: 7.46582s // clang-format on } // namespace Clockwork diff --git a/src/evaltune_main.cpp b/src/evaltune_main.cpp index 71349373..3b5d3d47 100644 --- a/src/evaltune_main.cpp +++ b/src/evaltune_main.cpp @@ -133,7 +133,7 @@ int main() { current_parameter_values = Parameters::rand_init(parameter_count); // The optimizer will now start with all-zero parameters - AdamW optim(parameter_count, 1, 0.9, 0.999, 1e-8, 0.0); + AdamW optim(parameter_count, 10, 0.9, 0.999, 1e-8, 0.0); #ifdef PROFILE_RUN const i32 epochs = 8; #else @@ -424,7 +424,7 @@ int main() { << "s\n"; if (epoch > 5) { - optim.set_lr(optim.get_lr() * 0.99274); + optim.set_lr(optim.get_lr() * 0.99); } } diff --git a/src/evaluation.cpp b/src/evaluation.cpp index b6753c15..53d9ef56 100644 --- a/src/evaluation.cpp +++ b/src/evaluation.cpp @@ -416,8 +416,6 @@ PScore king_safety_activation(const Position& pos, PScore& king_safety_score) { } PScore apply_winnable(const Position& pos, PScore& score) { - const Color color = pos.active_color(); - i32 pawn_count = (pos.bitboard_for(Color::White, PieceType::Pawn) | pos.bitboard_for(Color::Black, PieceType::Pawn)) From 732803b2ea4649b9cc8f64835a931876a4d51bae Mon Sep 17 00:00:00 2001 From: TheRealGioviok <425gioviok@gmail.com> Date: Tue, 3 Feb 2026 07:38:15 +0100 Subject: [PATCH 9/9] Bench: 17899948 --- src/eval_types.hpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/eval_types.hpp b/src/eval_types.hpp index 8a117d01..84ba789e 100644 --- a/src/eval_types.hpp +++ b/src/eval_types.hpp @@ -102,18 +102,16 @@ class PScore { } // complexity_add -PScore complexity_add(Score val) { - const Score e = eg(); - if (e == 0) - return *this; + PScore complexity_add(Score val) { + const Score e = eg(); + if (e == 0) { + return *this; + } - const Score sum = e + val; - return PScore{ - mg(), - static_cast((e > 0) ? std::max(sum, Score{0}) - : std::min(sum, Score{0})) - }; -} + const Score sum = e + val; + return PScore{ + mg(), static_cast((e > 0) ? std::max(sum, Score{0}) : std::min(sum, Score{0}))}; + } friend std::ostream& operator<<(std::ostream& stream, const PScore& score) {