diff --git a/src/eval_constants.hpp b/src/eval_constants.hpp index 4575bfbd..dcc99089 100644 --- a/src/eval_constants.hpp +++ b/src/eval_constants.hpp @@ -5,156 +5,170 @@ namespace Clockwork { // clang-format off -inline const PParam PAWN_MAT = S(180, 164); -inline const PParam KNIGHT_MAT = S(741, 541); -inline const PParam BISHOP_MAT = S(780, 532); -inline const PParam ROOK_MAT = S(751, 703); -inline const PParam QUEEN_MAT = S(1632, 1199); -inline const PParam TEMPO_VAL = S(58, 15); +inline const PParam PAWN_MAT = S(287, 340); +inline const PParam KNIGHT_MAT = S(917, 685); +inline const PParam BISHOP_MAT = S(868, 596); +inline const PParam ROOK_MAT = S(1292, 1272); +inline const PParam QUEEN_MAT = S(2710, 1855); +inline const PParam TEMPO_VAL = S(59, 15); -inline const PParam BISHOP_PAIR_VAL = S(77, 175); -inline const PParam ROOK_OPEN_VAL = S(101, -25); -inline const PParam ROOK_SEMIOPEN_VAL = S(38, 14); +inline const PParam BISHOP_PAIR_VAL = S(80, 177); +inline const PParam ROOK_OPEN_VAL = S(101, -27); +inline const PParam ROOK_SEMIOPEN_VAL = S(36, 15); -inline const PParam DOUBLED_PAWN_VAL = S(-35, -77); +inline const PParam DOUBLED_PAWN_VAL = S(-36, -78); -inline const PParam POTENTIAL_CHECKER_VAL = S(-77, -1); -inline const PParam OUTPOST_KNIGHT_VAL = S(53, 31); -inline const PParam OUTPOST_BISHOP_VAL = S(63, 21); +inline const PParam POTENTIAL_CHECKER_VAL = S(-66, -8); +inline const PParam OUTPOST_KNIGHT_VAL = S(53, 32); +inline const PParam OUTPOST_BISHOP_VAL = S(62, 22); -inline const PParam PAWN_PUSH_THREAT_KNIGHT = S(45, 9); -inline const PParam PAWN_PUSH_THREAT_BISHOP = S(50, -19); -inline const PParam PAWN_PUSH_THREAT_ROOK = S(33, 32); -inline const PParam PAWN_PUSH_THREAT_QUEEN = S(51, -46); +inline const PParam PAWN_PUSH_THREAT_KNIGHT = S(48, 7); +inline const PParam PAWN_PUSH_THREAT_BISHOP = S(55, -22); +inline const PParam PAWN_PUSH_THREAT_ROOK = S(34, 31); +inline const PParam PAWN_PUSH_THREAT_QUEEN = S(60, -50); inline const std::array PAWN_PHALANX = { - S(19, 19), S(61, 31), S(72, 69), S(184, 138), S(520, 249), S(638, 693), + S(21, 18), S(62, 30), S(76, 70), S(186, 145), S(538, 261), S(940, 1138) }; inline const std::array DEFENDED_PAWN = { - S(61, 42), S(58, 30), S(66, 56), S(144, 117), S(605, -50), + S(66, 40), S(60, 31), S(67, 58), S(150, 121), S(689, -86) }; inline const std::array PASSED_PAWN = { - S(-69, -94), S(-59, -76), S(-33, -3), S(22, 75), S(50, 207), S(281, 300), + S(-77, -92), S(-77, -69), S(-51, 5), S(25, 75), S(89, 196), S(291, 304) }; inline const std::array DEFENDED_PASSED_PUSH = { - S(51, -43), S(37, -5), S(20, 29), S(20, 78), S(84, 157), S(163, 283), + S(50, -44), S(33, -3), S(20, 28), S(27, 71), S(106, 142), S(152, 290) }; inline const std::array BLOCKED_PASSED_PAWN = { - S(15, -45), S(1, 3), S(-0, -25), S(5, -45), S(1, -90), S(-190, -140), + S(13, -43), S(-1, 6), S(-3, -22), S(4, -44), S(-2, -89), S(-212, -130) }; inline const std::array FRIENDLY_KING_PASSED_PAWN_DISTANCE = { - S(0, 0), S(12, 98), S(-21, 86), S(-14, 36), S(-0, 7), S(9, 12), S(40, 9), S(19, -4), + S(0, 0), S(-3, 114), S(-14, 85), S(-7, 32), S(2, 4), S(11, 9), S(38, 8), S(17, -5) }; inline const std::array ENEMY_KING_PASSED_PAWN_DISTANCE = { - S(0, 0), S(-184, -54), S(27, -7), S(-13, 40), S(10, 70), S(15, 94), S(35, 94), S(-13, 114), + S(0, 0), S(-273, -17), S(-34, 19), S(-14, 45), S(29, 55), S(33, 82), S(50, 84), S(3, 102) }; inline const std::array KNIGHT_MOBILITY = { - S(3, -15), S(106, 146), S(160, 199), S(202, 234), S(247, 250), S(273, 288), S(309, 284), S(342, 287), S(389, 228), + S(-233, -223), S(-125, -63), S(-67, -10), S(-24, 24), S(23, 38), S(50, 76), S(88, 71), S(122, 73), + S(168, 16) }; inline const std::array BISHOP_MOBILITY = { - S(34, -61), S(105, 120), S(178, 181), S(213, 231), S(243, 262), S(260, 284), S(279, 298), S(297, 304), S(317, 308), S(331, 304), S(355, 292), S(421, 245), S(447, 224), S(513, 187), + S(-245, -299), S(-172, -116), S(-101, -51), S(-68, 0), S(-39, 33), S(-23, 55), S(-6, 71), S(12, 77), + S(30, 83), S(42, 80), S(66, 69), S(131, 22), S(158, 1), S(219, -32) }; inline const std::array ROOK_MOBILITY = { - S(164, 217), S(292, 413), S(343, 478), S(375, 487), S(401, 511), S(415, 533), S(432, 545), S(451, 551), S(467, 563), S(485, 572), S(503, 574), S(515, 576), S(536, 578), S(548, 564), S(691, 439), + S(-300, -251), S(-148, -97), S(-96, -33), S(-63, -24), S(-38, 0), S(-24, 22), S(-6, 34), S(12, 40), + S(29, 53), S(46, 62), S(63, 65), S(74, 68), S(94, 71), S(106, 57), S(251, -70) }; inline const std::array QUEEN_MOBILITY = { - S(-1, 2), S(722, 361), S(819, 488), S(878, 652), S(890, 834), S(929, 929), S(934, 1031), S(960, 1040), S(966, 1091), S(979, 1112), S(988, 1133), S(995, 1144), S(1015, 1132), S(1028, 1138), S(1036, 1128), S(1052, 1118), S(1062, 1102), S(1067, 1099), S(1099, 1044), S(1129, 995), S(1158, 958), S(1226, 862), S(1227, 862), S(1319, 735), S(1281, 738), S(1250, 729), S(1013, 798), S(907, 782), + S(-790, -500), S(-307, -661), S(-217, -505), S(-165, -301), S(-158, -95), S(-122, 11), S(-119, 121), S(-95, 133), + S(-91, 189), S(-79, 213), S(-70, 238), S(-65, 253), S(-47, 244), S(-37, 255), S(-31, 249), S(-19, 244), + S(-12, 234), S(-13, 240), S(12, 196), S(34, 157), S(51, 137), S(96, 69), S(108, 61), S(272, -118), + S(308, -162), S(544, -315), S(373, -232), S(625, -368) }; inline const std::array KING_MOBILITY = { - S(333, 145), S(139, -115), S(39, -29), S(24, 8), S(-2, 11), S(-35, 17), S(-15, 18), S(-24, 12), S(-24, -36), + S(561, -76), S(168, -162), S(37, -56), S(0, -6), S(-50, 11), S(-112, 36), S(-159, 77), S(-207, 99), + S(-242, 77) }; inline const std::array KNIGHT_KING_RING = { - S(0, 0), S(88, -30), S(158, -76), + S(206, 236), S(309, 188), S(383, 128) }; inline const std::array BISHOP_KING_RING = { - S(0, 0), S(33, -5), S(132, -42), + S(378, 386), S(229, 246), S(144, 77) }; inline const std::array ROOK_KING_RING = { - S(0, 0), S(65, -46), S(47, -59), S(96, -56), S(143, -116), + S(414, 435), S(515, 416), S(539, 428), S(620, 462), S(695, 433) }; inline const std::array QUEEN_KING_RING = { - S(0, 0), S(-53, 64), S(-85, 99), S(-50, 78), S(81, 23), S(211, -62), + S(1034, 998), S(716, 810), S(422, 616), S(204, 352), S(104, 38), S(26, -329) }; -inline const PParam PAWN_THREAT_KNIGHT = S(228, 62); -inline const PParam PAWN_THREAT_BISHOP = S(203, 102); -inline const PParam PAWN_THREAT_ROOK = S(194, 57); -inline const PParam PAWN_THREAT_QUEEN = S(175, -65); +inline const std::array PT_INNER_RING_ATTACKS = { + S(-110, 63), S(9, -18), S(-183, -134), S(34, 31), S(-279, -205) +}; +inline const std::array PT_OUTER_RING_ATTACKS = { + S(-27, 23), S(-21, 18), S(-25, 13), S(-15, 9), S(-22, -8) +}; -inline const PParam KNIGHT_THREAT_BISHOP = S(103, 72); -inline const PParam KNIGHT_THREAT_ROOK = S(240, 4); -inline const PParam KNIGHT_THREAT_QUEEN = S(158, -79); +inline const PParam PAWN_THREAT_KNIGHT = S(234, 62); +inline const PParam PAWN_THREAT_BISHOP = S(204, 104); +inline const PParam PAWN_THREAT_ROOK = S(199, 56); +inline const PParam PAWN_THREAT_QUEEN = S(175, -53); -inline const PParam BISHOP_THREAT_KNIGHT = S(110, 32); -inline const PParam BISHOP_THREAT_ROOK = S(238, 55); -inline const PParam BISHOP_THREAT_QUEEN = S(194, 33); +inline const PParam KNIGHT_THREAT_BISHOP = S(106, 73); +inline const PParam KNIGHT_THREAT_ROOK = S(246, 4); +inline const PParam KNIGHT_THREAT_QUEEN = S(161, -70); + +inline const PParam BISHOP_THREAT_KNIGHT = S(112, 34); +inline const PParam BISHOP_THREAT_ROOK = S(245, 56); +inline const PParam BISHOP_THREAT_QUEEN = S(192, 54); inline const std::array BISHOP_PAWNS = { - S(-0, -10), S(-3, -5), S(-3, -15), S(-8, -26), S(-14, -31), S(-19, -39), S(-20, -45), S(-27, -40), S(-36, -43), + S(0, -12), S(-3, -6), S(-3, -16), S(-8, -27), S(-14, -32), S(-19, -40), S(-20, -47), S(-26, -42), + S(-34, -48) }; inline const std::array PAWN_PSQT = { - S(232, 316), S(229, 360), S(289, 331), S(352, 214), S(300, 208), S(284, 273), S(180, 294), S(239, 271), // - S(178, 192), S(288, 220), S(267, 164), S(266, 109), S(221, 93), S(168, 139), S(128, 185), S(79, 188), // - S(101, 156), S(120, 160), S(137, 116), S(126, 102), S(109, 98), S(66, 105), S(26, 151), S(-1, 173), // - S(76, 109), S(92, 137), S(89, 104), S(71, 107), S(46, 99), S(26, 107), S(-25, 156), S(-42, 144), // - S(74, 79), S(134, 82), S(86, 126), S(55, 128), S(36, 119), S(-3, 118), S(-22, 131), S(-44, 125), // - S(83, 86), S(208, 91), S(163, 126), S(107, 143), S(71, 130), S(36, 125), S(10, 150), S(-25, 138), // + S(133, 152), S(99, 213), S(182, 175), S(246, 56), S(195, 49), S(186, 110), S(74, 134), S(153, 99), + S(21, 52), S(113, 90), S(92, 36), S(98, -23), S(61, -44), S(11, 1), S(-24, 43), S(-60, 40), + S(-23, 1), S(-15, 13), S(-2, -27), S(-7, -44), S(-18, -51), S(-54, -49), S(-93, -3), S(-111, 13), + S(-29, -59), S(-17, -24), S(-19, -57), S(-35, -55), S(-57, -65), S(-75, -58), S(-125, -9), S(-143, -22), + S(-33, -87), S(26, -78), S(-25, -31), S(-49, -33), S(-69, -43), S(-105, -47), S(-124, -33), S(-146, -40), + S(-34, -76), S(90, -66), S(42, -27), S(-6, -14), S(-38, -30), S(-68, -40), S(-93, -15), S(-127, -28) }; inline const std::array KNIGHT_PSQT = { - S(-256, -8), S(-198, 194), S(-277, 344), S(4, 211), S(-116, 231), S(-193, 235), S(-403, 212), S(-392, 124), // - S(124, 145), S(190, 155), S(288, 89), S(236, 151), S(238, 158), S(178, 135), S(120, 155), S(99, 114), // - S(174, 120), S(209, 163), S(291, 161), S(243, 183), S(240, 175), S(165, 182), S(153, 156), S(74, 159), // - S(224, 154), S(212, 178), S(238, 185), S(220, 210), S(224, 200), S(191, 193), S(169, 150), S(148, 156), // - S(217, 137), S(244, 135), S(240, 161), S(211, 176), S(201, 186), S(199, 181), S(174, 152), S(156, 97), // - S(137, 120), S(167, 107), S(162, 127), S(172, 171), S(179, 168), S(123, 146), S(128, 108), S(90, 103), // - S(140, 137), S(161, 108), S(145, 113), S(145, 131), S(132, 125), S(106, 105), S(116, 93), S(60, 28), // - S(91, 91), S(130, 130), S(148, 105), S(156, 112), S(148, 120), S(103, 90), S(89, 115), S(40, 68), // + S(-396, -157), S(-342, 56), S(-455, 232), S(-124, 68), S(-256, 96), S(-323, 92), S(-565, 82), S(-535, -22), + S(5, -4), S(72, 9), S(165, -51), S(113, 11), S(120, 15), S(51, -3), S(10, 4), S(-11, -42), + S(58, -28), S(84, 28), S(167, 25), S(121, 46), S(118, 37), S(46, 42), S(42, 9), S(-38, 8), + S(107, 9), S(92, 37), S(109, 52), S(91, 77), S(104, 61), S(71, 54), S(58, 3), S(38, 5), + S(100, -8), S(124, -4), S(109, 30), S(90, 39), S(78, 50), S(83, 39), S(60, 6), S(49, -56), + S(28, -31), S(56, -40), S(49, -17), S(62, 26), S(70, 21), S(15, -3), S(21, -44), S(-16, -52), + S(37, -20), S(59, -47), S(40, -39), S(39, -19), S(26, -26), S(-2, -46), S(11, -61), S(-47, -130), + S(-15, -69), S(21, -24), S(44, -50), S(52, -43), S(43, -35), S(-5, -66), S(-18, -41), S(-65, -95) }; inline const std::array BISHOP_PSQT = { - S(-20, 262), S(-44, 244), S(-273, 267), S(-156, 281), S(-108, 284), S(-269, 308), S(-26, 288), S(24, 263), // - S(146, 153), S(128, 228), S(149, 209), S(128, 214), S(104, 228), S(140, 220), S(118, 210), S(84, 213), // - S(173, 209), S(212, 199), S(284, 209), S(215, 209), S(189, 213), S(166, 224), S(224, 195), S(134, 211), // - S(188, 165), S(199, 197), S(231, 200), S(230, 225), S(234, 226), S(174, 223), S(165, 200), S(121, 206), // - S(189, 138), S(203, 175), S(212, 192), S(208, 216), S(200, 233), S(161, 224), S(145, 187), S(136, 144), // - S(203, 146), S(240, 159), S(246, 173), S(187, 213), S(170, 219), S(171, 214), S(198, 171), S(168, 151), // - S(191, 113), S(239, 135), S(209, 147), S(182, 176), S(173, 161), S(174, 152), S(156, 167), S(175, 104), // - S(185, 133), S(173, 177), S(177, 183), S(188, 149), S(197, 139), S(193, 181), S(185, 154), S(167, 152), // + S(-179, 73), S(-197, 51), S(-441, 78), S(-318, 90), S(-275, 94), S(-436, 117), S(-175, 94), S(-132, 72), + S(-4, -41), S(-17, 31), S(-2, 15), S(-35, 24), S(-55, 37), S(-4, 23), S(-24, 12), S(-61, 16), + S(32, 13), S(71, 2), S(139, 15), S(69, 13), S(42, 18), S(24, 26), S(90, -6), S(-1, 10), + S(37, -28), S(36, 11), S(73, 11), S(75, 35), S(86, 32), S(24, 30), S(21, 3), S(-18, 6), + S(31, -51), S(51, -16), S(59, 1), S(61, 22), S(55, 37), S(22, 25), S(4, -12), S(-9, -53), + S(54, -48), S(101, -38), S(111, -26), S(46, 16), S(32, 20), S(37, 13), S(62, -29), S(26, -48), + S(45, -83), S(110, -69), S(80, -56), S(51, -25), S(38, -38), S(38, -48), S(21, -35), S(36, -96), + S(45, -67), S(31, -18), S(45, -18), S(56, -52), S(64, -62), S(53, -17), S(48, -47), S(27, -48) }; inline const std::array ROOK_PSQT = { - S(551, 468), S(616, 467), S(546, 496), S(548, 490), S(558, 478), S(505, 492), S(514, 494), S(522, 499), // - S(469, 521), S(553, 498), S(626, 476), S(555, 517), S(569, 505), S(518, 514), S(460, 532), S(451, 538), // - S(456, 500), S(602, 460), S(632, 454), S(632, 450), S(588, 459), S(515, 499), S(531, 488), S(415, 536), // - S(426, 493), S(501, 487), S(533, 478), S(555, 441), S(524, 465), S(464, 513), S(445, 513), S(375, 520), // - S(364, 445), S(444, 450), S(429, 466), S(412, 467), S(407, 464), S(389, 504), S(361, 501), S(342, 490), // - S(341, 424), S(414, 398), S(409, 427), S(388, 428), S(405, 410), S(356, 464), S(355, 446), S(333, 443), // - S(281, 435), S(377, 376), S(401, 390), S(405, 393), S(399, 397), S(380, 414), S(361, 391), S(330, 408), // - S(314, 438), S(344, 442), S(396, 408), S(420, 391), S(407, 405), S(395, 417), S(380, 409), S(363, 426), // + S(105, 5), S(173, 3), S(100, 33), S(97, 30), S(111, 17), S(62, 29), S(73, 30), S(80, 36), + S(18, 59), S(101, 37), S(171, 18), S(94, 63), S(117, 47), S(68, 55), S(11, 70), S(5, 75), + S(-4, 42), S(141, 3), S(165, 2), S(162, 0), S(123, 7), S(56, 43), S(78, 28), S(-39, 76), + S(-28, 33), S(47, 28), S(74, 22), S(92, -12), S(70, 7), S(14, 51), S(-1, 49), S(-73, 57), + S(-89, -16), S(-8, -10), S(-25, 8), S(-43, 10), S(-41, 2), S(-57, 40), S(-83, 35), S(-105, 26), + S(-110, -38), S(-36, -62), S(-41, -34), S(-62, -32), S(-41, -53), S(-90, 0), S(-91, -19), S(-114, -21), + S(-169, -29), S(-67, -90), S(-46, -73), S(-44, -69), S(-48, -66), S(-68, -49), S(-86, -73), S(-118, -56), + S(-133, -31), S(-104, -23), S(-50, -58), S(-28, -73), S(-40, -59), S(-52, -48), S(-67, -57), S(-85, -40) }; inline const std::array QUEEN_PSQT = { - S(835, 784), S(890, 739), S(891, 756), S(789, 871), S(832, 824), S(780, 844), S(821, 784), S(752, 812), // - S(777, 892), S(712, 978), S(725, 1006), S(649, 1028), S(658, 1001), S(635, 1017), S(672, 941), S(710, 875), // - S(739, 919), S(824, 922), S(771, 990), S(753, 1002), S(709, 993), S(668, 1010), S(736, 908), S(703, 877), // - S(795, 850), S(796, 923), S(761, 958), S(746, 1032), S(721, 1024), S(712, 958), S(746, 875), S(738, 832), // - S(754, 889), S(786, 856), S(758, 930), S(712, 1002), S(699, 994), S(708, 948), S(722, 863), S(724, 815), // - S(759, 744), S(782, 788), S(781, 862), S(725, 897), S(736, 858), S(738, 866), S(752, 789), S(732, 788), // - S(742, 648), S(772, 555), S(759, 688), S(774, 767), S(748, 787), S(766, 717), S(740, 777), S(727, 769), // - S(688, 731), S(746, 489), S(742, 496), S(765, 598), S(769, 682), S(772, 637), S(760, 672), S(709, 743), // + S(32, 30), S(72, -8), S(69, 0), S(-55, 132), S(17, 48), S(-28, 71), S(47, -15), S(-18, 15), + S(20, 75), S(-52, 172), S(-63, 219), S(-165, 251), S(-136, 200), S(-119, 194), S(-70, 113), S(-33, 50), + S(-23, 102), S(54, 99), S(-16, 178), S(-41, 187), S(-77, 169), S(-102, 172), S(-13, 63), S(-40, 36), + S(42, 9), S(31, 78), S(-5, 116), S(-17, 176), S(-23, 156), S(-29, 98), S(13, 3), S(6, -24), + S(9, 38), S(41, 3), S(15, 71), S(-20, 122), S(-24, 116), S(-17, 79), S(-1, -4), S(-1, -53), + S(24, -114), S(50, -57), S(54, 4), S(2, 18), S(19, -17), S(26, -10), S(37, -80), S(8, -75), + S(15, -212), S(53, -304), S(47, -181), S(61, -116), S(34, -92), S(51, -158), S(26, -95), S(7, -95), + S(-40, -123), S(24, -374), S(29, -375), S(55, -291), S(56, -197), S(57, -245), S(44, -202), S(-11, -125) }; inline const std::array KING_PSQT = { - S(-233, -320), S(30, 5), S(-98, 45), S(-169, 61), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(124, -85), S(-17, 153), S(1, 139), S(117, 68), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-66, 71), S(48, 145), S(86, 114), S(73, 69), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-277, 92), S(10, 106), S(2, 104), S(-50, 89), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-247, 48), S(-68, 80), S(-48, 85), S(-128, 119), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-153, 17), S(34, 23), S(-54, 74), S(-95, 98), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(58, -71), S(109, -29), S(23, 17), S(-56, 59), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-61, -101), S(65, -88), S(-33, -54), S(-50, -53), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-281, -298), S(18, 20), S(-127, 72), S(-233, 98), S(-19, -5), S(-19, -5), S(-19, -5), S(-19, -5), + S(110, -70), S(81, 88), S(126, 66), S(233, -3), S(-19, -5), S(-19, -5), S(-19, -5), S(-19, -5), + S(-76, 87), S(175, 70), S(243, 28), S(219, -13), S(-19, -5), S(-19, -5), S(-19, -5), S(-19, -5), + S(-284, 108), S(163, 23), S(173, 11), S(114, -6), S(-19, -5), S(-19, -5), S(-19, -5), S(-19, -5), + S(-256, 61), S(94, -10), S(149, -26), S(61, 7), S(-19, -5), S(-19, -5), S(-19, -5), S(-19, -5), + S(-190, 44), S(155, -48), S(113, -23), S(85, -7), S(-19, -5), S(-19, -5), S(-19, -5), S(-19, -5), + S(-30, -18), S(157, -63), S(110, -39), S(45, -6), S(-19, -5), S(-19, -5), S(-19, -5), S(-19, -5), + S(-230, 2), S(-49, -17), S(-127, 5), S(-141, 4), S(-19, -5), S(-19, -5), S(-19, -5), S(-19, -5) }; - // Epoch duration: 6.87929s // clang-format on } // namespace Clockwork diff --git a/src/evaltune_main.cpp b/src/evaltune_main.cpp index 44a5ec3b..f567af24 100644 --- a/src/evaltune_main.cpp +++ b/src/evaltune_main.cpp @@ -276,6 +276,9 @@ int main() { print_table("ROOK_KING_RING", ROOK_KING_RING); print_table("QUEEN_KING_RING", QUEEN_KING_RING); std::cout << std::endl; + print_table("PT_INNER_RING_ATTACKS", PT_INNER_RING_ATTACKS); + print_table("PT_OUTER_RING_ATTACKS", PT_OUTER_RING_ATTACKS); + std::cout << std::endl; std::cout << "inline const PParam PAWN_THREAT_KNIGHT = " << PAWN_THREAT_KNIGHT << ";" << std::endl; @@ -336,7 +339,7 @@ int main() { << "s\n"; if (epoch > 5) { - optim.set_lr(optim.get_lr() * 0.91); + optim.set_lr(optim.get_lr() * 0.99); } } diff --git a/src/evaluation.cpp b/src/evaluation.cpp index 508dbaf9..d259d5d5 100644 --- a/src/evaluation.cpp +++ b/src/evaluation.cpp @@ -70,6 +70,24 @@ std::array king_ring_table = []() { return king_ring_table; }(); +std::array extended_ring_table = []() { + std::array extended_ring_table{}; + for (u8 sq_idx = 0; sq_idx < 64; sq_idx++) { + Bitboard sq_bb = king_ring_table[sq_idx]; + Bitboard extended_ring = sq_bb; + extended_ring |= sq_bb.shift(Direction::North); + extended_ring |= sq_bb.shift(Direction::South); + extended_ring |= sq_bb.shift(Direction::East); + extended_ring |= sq_bb.shift(Direction::West); + extended_ring |= sq_bb.shift(Direction::NorthEast); + extended_ring |= sq_bb.shift(Direction::SouthEast); + extended_ring |= sq_bb.shift(Direction::NorthWest); + extended_ring |= sq_bb.shift(Direction::SouthWest); + extended_ring_table[sq_idx] = extended_ring; + } + return extended_ring_table; +}(); + std::array, 2> passed_pawn_spans = []() { std::array, 2> passed_pawn_masks{}; for (Color color : {Color::White, Color::Black}) { @@ -260,6 +278,29 @@ PScore evaluate_potential_checkers(const Position& pos) { return POTENTIAL_CHECKER_VAL * mask.popcount(); } +template +PScore evaluate_king_safety(const Position& pos) { + constexpr Color opp = ~color; + + // Iterate over the opponent's attack bbs + PScore eval = PSCORE_ZERO; + + Bitboard king_ring = king_ring_table[pos.king_sq(color).raw]; + Bitboard extended_ring = extended_ring_table[pos.king_sq(color).raw]; + + for (PieceType pt : {PieceType::Pawn, PieceType::Knight, PieceType::Bishop, PieceType::Rook, + PieceType::Queen}) { + Bitboard attacked = pos.attacked_by(opp, pt); + Bitboard inner = attacked & king_ring; + Bitboard outer = attacked & extended_ring & ~king_ring; + eval += PT_INNER_RING_ATTACKS[static_cast(pt) - static_cast(PieceType::Pawn)] + * inner.ipopcount(); + eval += PT_OUTER_RING_ATTACKS[static_cast(pt) - static_cast(PieceType::Pawn)] + * outer.ipopcount(); + } + return eval; +} + template PScore evaluate_threats(const Position& pos) { constexpr Color opp = ~color; @@ -332,6 +373,7 @@ Score evaluate_white_pov(const Position& pos, const PsqtState& psqt_state) { eval += evaluate_potential_checkers(pos) - evaluate_potential_checkers(pos); eval += evaluate_threats(pos) - evaluate_threats(pos); + eval += evaluate_king_safety(pos) - evaluate_king_safety(pos); eval += evaluate_space(pos) - evaluate_space(pos); eval += evaluate_outposts(pos) - evaluate_outposts(pos); eval += (us == Color::White) ? TEMPO_VAL : -TEMPO_VAL;