diff --git a/src/eval_constants.hpp b/src/eval_constants.hpp index 44b5cf2a..c57d03ef 100644 --- a/src/eval_constants.hpp +++ b/src/eval_constants.hpp @@ -5,171 +5,175 @@ 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(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(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(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(-13, -57); -inline const PParam ISOLATED_PAWN_VAL = S(-22, -18); +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(-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(-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, 6); +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(34, 43); -inline const PParam PAWN_PUSH_THREAT_QUEEN = S(69, -47); +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(19, -4), S(45, 17), S(64, 46), S(155, 124), S(438, 152), S(603, 501), + 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(62, 19), S(50, 17), S(62, 43), S(149, 98), S(511, -24), + S(55, 32), S(46, 24), S(55, 51), S(121, 140), S(423, 73), }; 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(-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(34, -37), S(37, -10), S(28, 17), S(18, 68), S(82, 137), S(180, 224), + 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(20, -33), S(5, 8), S(-3, -14), S(-10, -37), S(-30, -78), S(-279, -102), + 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(15, 113), S(-8, 92), S(-10, 39), S(-6, 9), S(4, 5), S(43, 3), S(14, -7), + 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(-358, -6), S(-33, 17), S(-12, 45), S(25, 75), S(43, 89), S(58, 92), S(36, 83), + 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(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(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, -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(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(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(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(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(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(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(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(12, -13), S(17, -17), S(14, -13), S(7, -9), S(3, 232), + 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, -2), S(7, -10), S(6, -8), S(6, -5), S(7, 454), + S(4, -0), S(7, -11), S(6, -9), S(5, -5), S(6, 429), }; -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(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(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(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(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(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(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(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(14, 71); +inline const PParam ROOK_LINEUP = S(11, 72); 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(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(-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(-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(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(-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(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(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(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(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(-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(-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(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(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(9, 20), S(-15, 37), S(-12, 24), S(-6, 13), S(-6, -2), + 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(-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(-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( - 1112, 423, -28, 44 + 1192, 541, -31, 51 ); -// Epoch duration: 9.97031s + +inline VParam WINNABLE_PAWNS = V(47); +inline VParam WINNABLE_BIAS = V(-451); + +// Epoch duration: 7.46582s // clang-format on } // namespace Clockwork diff --git a/src/eval_types.hpp b/src/eval_types.hpp index 9228f486..84ba789e 100644 --- a/src/eval_types.hpp +++ b/src/eval_types.hpp @@ -101,6 +101,19 @@ class PScore { return static_cast((mg() * alpha + eg() * (max - alpha)) / max); } + // complexity_add + 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() << ")"; return stream; @@ -108,11 +121,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 PParam = Autograd::PairPlaceholder; // Handle for the TUNABLE parameter +using VParam = Autograd::ValuePlaceholder; // Handle for the TUNABLE parameter #endif @@ -124,6 +139,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 +155,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..3b5d3d47 100644 --- a/src/evaltune_main.cpp +++ b/src/evaltune_main.cpp @@ -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..53d9ef56 100644 --- a/src/evaluation.cpp +++ b/src/evaluation.cpp @@ -415,6 +415,20 @@ 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; + + if (score.eg() < 0) { + winnable = -winnable; + } + + return score.complexity_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 +464,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..3b9edf20 100644 --- a/src/tuning/graph.cpp +++ b/src/tuning/graph.cpp @@ -189,6 +189,17 @@ PairHandle Graph::record_pair_value(OpType op, PairHandle lhs, ValueHandle rhs) case OpType::ValueDivPair: res = f64x2::scalar_div(v, pair_val); break; + case OpType::PairAddClampedSecond: { + f64 add_res = pair_val.second() + v; + 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: break; } @@ -488,6 +499,43 @@ void Graph::backward() { pair_grads[node.rhs()] = f64x2::add(pair_grads[node.rhs()], grad_rhs); break; } + case OpType::PairAddClampedSecond: { + const f64x2 grad_out = pair_grads[out_idx]; + 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; + + // 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()); + 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()); + 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; + } + default: unreachable(); diff --git a/src/tuning/operations.hpp b/src/tuning/operations.hpp index fb162fb7..945ba2f7 100644 --- a/src/tuning/operations.hpp +++ b/src/tuning/operations.hpp @@ -50,6 +50,7 @@ enum class OpType : u32 { ValueMulPair, PairDivValue, ValueDivPair, + PairAddClampedSecond, // For complexity // Pair-Pair Ops PairMulPair, diff --git a/src/tuning/value.cpp b/src/tuning/value.cpp index f2a1e43d..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); @@ -204,6 +210,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 +276,9 @@ PairHandle& operator/=(PairHandle& a, ValueHandle v) { return a; } + +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 4cfc244a..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; @@ -73,6 +75,8 @@ struct PairHandle { } PairHandle sigmoid() const; + + PairHandle complexity_add(ValueHandle value) const; }; // Operation decls @@ -105,6 +109,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);