From 2d533ee7121907a5168d7df7b69cbe1a87f7b757 Mon Sep 17 00:00:00 2001 From: TheRealGioviok <425gioviok@gmail.com> Date: Tue, 9 Jun 2026 04:12:19 +0200 Subject: [PATCH 1/3] Format Bench: 14740904 --- src/evaluation.cpp | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/evaluation.cpp b/src/evaluation.cpp index 7f5d4c01..85b40476 100644 --- a/src/evaluation.cpp +++ b/src/evaluation.cpp @@ -13,13 +13,14 @@ namespace Clockwork { struct EvalData { - i32 m_piece_count[2][6]; - i32 wcount = 0; - i32 bcount = 0; Bitboard any_attacks_by[2]; Bitboard any2_attacks_by[2]; Bitboard attacks_by_pt[2][7]; + Bitboard m_pawn_files[2]; + i32 m_piece_count[2][6]; + i32 wcount = 0; + i32 bcount = 0; void init(const Position& pos) { any_attacks_by[0] = pos.attack_table(Color::White).get_attacked_bitboard(); @@ -47,6 +48,9 @@ struct EvalData { pos.attacked_by(Color::White, PieceType::King); attacks_by_pt[static_cast(Color::Black)][static_cast(PieceType::King)] = pos.attacked_by(Color::Black, PieceType::King); + + m_pawn_files[0] = Bitboard::fill_verticals(pos.bitboard_for(Color::White, PieceType::Pawn)); + m_pawn_files[1] = Bitboard::fill_verticals(pos.bitboard_for(Color::Black, PieceType::Pawn)); } inline i32 piece_count(const Color color, const PieceType pt) const { @@ -68,6 +72,10 @@ struct EvalData { inline Bitboard attacked_by_2(const Color color) const { return any2_attacks_by[static_cast(color)]; } + + inline Bitboard pawn_files(const Color color) const { + return m_pawn_files[static_cast(color)]; + } }; static i32 chebyshev_distance(Square a, Square b) { @@ -236,7 +244,7 @@ std::tuple evaluate_pawns(const Position& pos, const EvalData& data Bitboard pawns = pos.board().bitboard_for(color, PieceType::Pawn); Bitboard opp_pawns = pos.board().bitboard_for(~color, PieceType::Pawn); - Bitboard pawn_files = Bitboard::fill_verticals(pawns); + Bitboard pawn_files = data.pawn_files(color); Bitboard doubled = pawns & pawns.shift(Direction::North); Bitboard isolated = pawns & ~(pawn_files.shift(Direction::East) | pawn_files.shift(Direction::West)); @@ -516,11 +524,11 @@ PScore evaluate_threats(const Position& pos, const EvalData& data) { template PScore evaluate_space(const Position& pos, const EvalData& data) { - PScore eval = PSCORE_ZERO; - constexpr Color them = color == Color::White ? Color::Black : Color::White; - Bitboard ourfiles = Bitboard::fill_verticals(pos.bitboard_for(color, PieceType::Pawn)); - Bitboard theirfiles = Bitboard::fill_verticals(pos.bitboard_for(them, PieceType::Pawn)); - Bitboard openfiles = ~(ourfiles | theirfiles); + PScore eval = PSCORE_ZERO; + constexpr Color them = color == Color::White ? Color::Black : Color::White; + Bitboard ourfiles = data.pawn_files(color); + Bitboard theirfiles = data.pawn_files(them); + Bitboard openfiles = ~(ourfiles | theirfiles); Bitboard half_open_files = (~ourfiles) & theirfiles; Bitboard ourminors = pos.bitboard_for(color, PieceType::Knight) | pos.bitboard_for(color, PieceType::Bishop); @@ -550,7 +558,7 @@ PScore king_safety_activation(PScore& king_safety_score) { return activated; } -PScore apply_winnable(const Position& pos, PScore& score, i32 phase) { +PScore apply_winnable(const Position& pos, PScore& score, i32 phase, EvalData& eval_data) { bool pawn_endgame = phase == 0; @@ -559,8 +567,8 @@ PScore apply_winnable(const Position& pos, PScore& score, i32 phase) { i32 pawn_count = (white_pawns | black_pawns).ipopcount(); - Bitboard white_files = Bitboard::fill_verticals(white_pawns); - Bitboard black_files = Bitboard::fill_verticals(black_pawns); + Bitboard white_files = eval_data.pawn_files(Color::White); + Bitboard black_files = eval_data.pawn_files(Color::Black); i32 sym_files = (white_files & black_files).ipopcount() / 8; i32 asym_files = (white_files ^ black_files).ipopcount() / 8; @@ -670,7 +678,7 @@ Score evaluate_white_pov(const Position& pos, const PsqtState& psqt_state) { eval += (us == Color::White) ? TEMPO_VAL : -TEMPO_VAL; // Winnable - eval = apply_winnable(pos, eval, phase); + eval = apply_winnable(pos, eval, phase, eval_data); // Eg scaling eval = From 198f3bf2089fa1a189732fb65e3fef2dcdca3c0b Mon Sep 17 00:00:00 2001 From: TheRealGioviok <425gioviok@gmail.com> Date: Tue, 9 Jun 2026 13:25:24 +0200 Subject: [PATCH 2/3] Bench: 15632420 --- src/eval_constants.hpp | 210 +++++++++++++++++++++-------------------- src/evaltune_main.cpp | 4 + src/evaluation.cpp | 97 ++++++++++++++----- src/square.hpp | 4 +- 4 files changed, 192 insertions(+), 123 deletions(-) diff --git a/src/eval_constants.hpp b/src/eval_constants.hpp index a7f576a4..356c3a81 100644 --- a/src/eval_constants.hpp +++ b/src/eval_constants.hpp @@ -5,188 +5,198 @@ namespace Clockwork { // clang-format off -inline const PParam PAWN_MAT = S(194, 503); -inline const PParam KNIGHT_MAT = S(826, 1543); -inline const PParam BISHOP_MAT = S(867, 1632); -inline const PParam ROOK_MAT = S(1028, 2561); -inline const PParam QUEEN_MAT = S(2449, 3864); +inline const PParam PAWN_MAT = S(197, 501); +inline const PParam KNIGHT_MAT = S(824, 1540); +inline const PParam BISHOP_MAT = S(865, 1627); +inline const PParam ROOK_MAT = S(1032, 2550); +inline const PParam QUEEN_MAT = S(2451, 3871); inline const PParam TEMPO_VAL = S(69, 50); inline const PParam BISHOP_XRAY_PAWNS = S(-13, -4); -inline const PParam BISHOP_PAIR_VAL = S(65, 230); -inline const PParam ROOK_OPEN_VAL = S(112, -3); -inline const PParam ROOK_SEMIOPEN_VAL = S(45, 12); -inline const PParam MINOR_BEHIND_PAWN = S(15, 38); -inline const PParam RESTRICTED_SQUARES = S(-22, -3); +inline const PParam BISHOP_PAIR_VAL = S(64, 230); +inline const PParam ROOK_OPEN_VAL = S(109, -2); +inline const PParam ROOK_SEMIOPEN_VAL = S(43, 13); +inline const PParam MINOR_BEHIND_PAWN = S(15, 39); +inline const PParam RESTRICTED_SQUARES = S(-20, -4); inline const PParam DOUBLED_PAWN_VAL = S(-20, -82); inline const PParam ISOLATED_PAWN_VAL = S(-14, -36); -inline const PParam POTENTIAL_CHECKER_VAL = S(-45, -41); -inline const PParam OUTPOST_KNIGHT_VAL = S(53, 41); +inline const PParam POTENTIAL_CHECKER_VAL = S(-46, -40); +inline const PParam OUTPOST_KNIGHT_VAL = S(51, 42); inline const PParam OUTPOST_BISHOP_VAL = S(42, 39); -inline const PParam PAWN_PUSH_THREAT_KNIGHT = S(37, 49); -inline const PParam PAWN_PUSH_THREAT_BISHOP = S(41, 3); -inline const PParam PAWN_PUSH_THREAT_ROOK = S(24, 58); -inline const PParam PAWN_PUSH_THREAT_QUEEN = S(61, -49); +inline const PParam PAWN_PUSH_THREAT_KNIGHT = S(38, 48); +inline const PParam PAWN_PUSH_THREAT_BISHOP = S(41, 2); +inline const PParam PAWN_PUSH_THREAT_ROOK = S(21, 59); +inline const PParam PAWN_PUSH_THREAT_QUEEN = S(62, -51); inline const std::array PAWN_PHALANX = { - S(14, -1), S(31, 36), S(61, 63), S(129, 194), S(438, 267), S(565, 548), + S(14, -1), S(31, 36), S(61, 62), S(128, 194), S(441, 264), S(568, 549), }; inline const std::array DEFENDED_PAWN = { - S(46, 34), S(38, 25), S(55, 54), S(98, 170), S(409, 89), + S(46, 34), S(38, 25), S(56, 53), S(99, 170), S(409, 89), }; inline const std::array PASSED_PAWN = { - S(-88, -264), S(-88, -229), S(-65, -90), S(-26, 48), S(69, 243), S(214, 416), + S(-88, -270), S(-88, -234), S(-66, -96), S(-27, 42), S(69, 238), S(214, 411), }; inline const std::array DEFENDED_PASSED_PUSH = { - S(25, -39), S(25, -0), S(13, 41), S(11, 121), S(79, 246), S(103, 457), + S(25, -40), S(25, -1), S(12, 41), S(11, 121), S(77, 247), S(106, 455), }; inline const std::array BLOCKED_PASSED_PAWN = { - S(16, -38), S(3, 8), S(-5, -22), S(-2, -58), S(-10, -166), S(-168, -335), + S(15, -38), S(2, 9), S(-4, -23), S(-1, -59), S(-10, -166), S(-169, -335), }; inline const std::array FRIENDLY_KING_PASSED_PAWN_DISTANCE = { - S(0, 0), S(14, 237), S(1, 189), S(-2, 112), S(10, 70), S(20, 73), S(59, 71), S(55, 46), + S(0, 0), S(14, 239), S(1, 191), S(-2, 115), S(9, 73), S(20, 76), S(59, 74), S(55, 49), }; inline const std::array ENEMY_KING_PASSED_PAWN_DISTANCE = { - S(0, 0), S(-137, -64), S(15, 2), S(1, 105), S(25, 156), S(38, 192), S(50, 198), S(32, 186), + S(0, 0), S(-137, -60), S(17, 4), S(2, 108), S(27, 158), S(40, 194), S(52, 200), S(32, 191), }; inline const std::array KNIGHT_MOBILITY = { - S(-89, -372), S(-28, -133), S(1, -15), S(25, 32), S(54, 62), S(69, 98), S(87, 106), S(106, 113), S(126, 68), + S(-88, -373), S(-27, -134), S(1, -16), S(25, 31), S(53, 62), S(68, 98), S(86, 106), S(105, 115), S(124, 69), }; inline const std::array BISHOP_MOBILITY = { - S(-65, -283), S(-17, -103), S(33, -29), S(57, 20), S(79, 60), S(92, 88), S(99, 110), S(103, 129), S(108, 141), S(116, 147), S(123, 143), S(144, 124), S(146, 125), S(126, 98), + S(-62, -284), S(-14, -104), S(34, -29), S(57, 21), S(78, 62), S(89, 91), S(94, 113), S(97, 133), S(101, 146), S(107, 153), S(113, 149), S(133, 131), S(134, 132), S(116, 104), }; inline const std::array ROOK_MOBILITY = { - S(108, -178), S(24, 10), S(45, 42), S(61, 58), S(71, 76), S(75, 90), S(80, 105), S(87, 110), S(92, 122), S(98, 128), S(105, 132), S(108, 139), S(111, 143), S(114, 133), S(138, 89), + S(108, -177), S(24, 10), S(44, 43), S(60, 60), S(71, 77), S(74, 91), S(79, 106), S(85, 111), S(89, 124), S(95, 130), S(101, 135), S(102, 142), S(105, 147), S(107, 137), S(132, 93), }; inline const std::array QUEEN_MOBILITY = { - S(-219, -149), S(-64, 21), S(-39, 146), S(-17, 271), S(-1, 310), S(5, 363), S(12, 396), S(19, 412), S(22, 437), S(25, 455), S(30, 464), S(34, 473), S(36, 480), S(37, 486), S(37, 490), S(34, 495), S(30, 496), S(33, 487), S(32, 487), S(36, 478), S(33, 461), S(39, 440), S(7, 468), S(-34, 453), S(-64, 456), S(-93, 474), S(-133, 480), S(-102, 411), + S(-206, -159), S(-51, 6), S(-26, 132), S(-4, 256), S(13, 295), S(19, 348), S(26, 381), S(32, 396), S(36, 420), S(40, 437), S(45, 445), S(49, 453), S(52, 459), S(54, 465), S(55, 468), S(54, 470), S(51, 470), S(56, 461), S(56, 460), S(59, 452), S(55, 436), S(59, 418), S(28, 444), S(-17, 432), S(-46, 434), S(-75, 451), S(-118, 463), S(-85, 391), }; -inline const PParam PAWN_THREAT_KNIGHT = S(193, 149); +inline const PParam PAWN_THREAT_KNIGHT = S(194, 147); inline const PParam PAWN_THREAT_BISHOP = S(170, 212); -inline const PParam PAWN_THREAT_ROOK = S(196, 136); -inline const PParam PAWN_THREAT_QUEEN = S(150, 23); +inline const PParam PAWN_THREAT_ROOK = S(194, 137); +inline const PParam PAWN_THREAT_QUEEN = S(155, 17); inline const std::array MINOR_THREAT = { - S(8, 55), S(93, 90), S(103, 124), S(203, 124), S(159, 18), S(0, 0), + S(6, 56), S(91, 91), S(102, 124), S(203, 124), S(159, 12), S(0, 0), }; inline const std::array ROOK_THREAT = { - S(9, 55), S(54, 92), S(72, 94), S(20, -6), S(173, -56), S(0, 0), + S(7, 56), S(52, 93), S(72, 94), S(21, -6), S(148, -51), S(0, 0), +}; +inline const PParam KING_THREAT = S(-19, 157); +inline const PParam HANGING_PAWN = S(32, 88); +inline const PParam HANGING_NON_PAWN = S(69, 22); + +inline const std::array KNIGHT_ON_QUEEN = { + S(21, -18), S(27, -2), +}; +inline const std::array BISHOP_ON_QUEEN = { + S(40, 46), S(123, -120), +}; +inline const std::array ROOK_ON_QUEEN = { + S(36, 12), S(49, -7), }; -inline const PParam KING_THREAT = S(-17, 156); -inline const PParam HANGING_PAWN = S(31, 89); -inline const PParam HANGING_NON_PAWN = S(67, 23); inline const std::array BISHOP_PAWNS = { - S(4, -16), S(4, -15), S(-0, -21), S(-6, -29), S(-12, -37), S(-17, -44), S(-19, -56), S(-25, -59), S(-29, -74), + S(3, -16), S(4, -14), S(-0, -21), S(-5, -29), S(-11, -37), S(-16, -44), S(-18, -56), S(-24, -60), S(-28, -74), }; -inline const PParam ROOK_LINEUP = S(16, 79); +inline const PParam ROOK_LINEUP = S(17, 78); inline const std::array PAWN_PSQT = { - S(189, 277), S(41, 395), S(66, 365), S(148, 260), S(198, 159), S(126, 226), S(87, 271), S(229, 203), // - S(40, 70), S(51, 111), S(31, 54), S(48, -24), S(39, -57), S(11, -17), S(7, 35), S(-21, 65), // - S(36, -7), S(10, 1), S(41, -45), S(26, -67), S(18, -86), S(-1, -71), S(-40, -33), S(-40, 5), // - S(-6, -69), S(-32, -38), S(2, -61), S(-7, -73), S(-29, -83), S(-38, -70), S(-86, -49), S(-77, -47), // - S(-10, -107), S(22, -104), S(8, -46), S(-8, -52), S(-35, -62), S(-51, -70), S(-81, -66), S(-81, -70), // - S(12, -105), S(85, -94), S(73, -44), S(29, -18), S(-3, -38), S(-22, -62), S(-49, -54), S(-61, -53), // + S(188, 277), S(42, 392), S(66, 363), S(147, 259), S(196, 158), S(124, 226), S(88, 269), S(229, 203), // + S(38, 69), S(51, 110), S(30, 53), S(47, -25), S(39, -57), S(10, -18), S(7, 34), S(-22, 65), // + S(34, -7), S(10, 0), S(41, -46), S(27, -69), S(17, -87), S(-2, -71), S(-41, -34), S(-42, 5), // + S(-8, -70), S(-32, -39), S(2, -62), S(-6, -75), S(-28, -84), S(-38, -71), S(-86, -49), S(-79, -47), // + S(-12, -107), S(21, -105), S(8, -47), S(-7, -53), S(-35, -62), S(-51, -71), S(-81, -67), S(-83, -70), // + S(10, -105), S(85, -95), S(71, -45), S(29, -20), S(-3, -40), S(-22, -63), S(-50, -55), S(-63, -53), // }; inline const std::array KNIGHT_PSQT = { - S(-256, -499), S(-253, 52), S(-267, -78), S(35, 14), S(-92, 39), S(-261, 70), S(-366, 116), S(-347, -395), // - S(-6, -6), S(1, 33), S(98, 17), S(84, 51), S(88, 46), S(57, 19), S(-26, 29), S(-28, 14), // - S(48, -30), S(38, 28), S(72, 46), S(75, 67), S(67, 62), S(25, 53), S(11, 30), S(-41, 17), // - S(94, 24), S(91, 48), S(105, 63), S(107, 106), S(110, 107), S(74, 71), S(51, 41), S(37, 36), // - S(75, 17), S(103, 6), S(100, 50), S(92, 82), S(80, 83), S(74, 65), S(61, 13), S(22, 32), // - S(15, -36), S(42, -15), S(47, 24), S(60, 59), S(55, 57), S(28, 19), S(13, -7), S(-27, -31), // - S(38, -24), S(39, -7), S(24, -11), S(31, 17), S(29, 13), S(1, -35), S(-32, 0), S(-40, -88), // - S(-46, -71), S(4, -18), S(24, -37), S(42, -24), S(22, -6), S(-14, -43), S(-22, -16), S(-67, -124), // + S(-256, -496), S(-253, 54), S(-268, -74), S(33, 17), S(-94, 42), S(-260, 72), S(-366, 117), S(-346, -394), // + S(-7, -4), S(-0, 36), S(95, 20), S(80, 55), S(84, 49), S(53, 23), S(-27, 30), S(-30, 18), // + S(48, -28), S(36, 31), S(69, 48), S(70, 72), S(60, 68), S(20, 56), S(7, 34), S(-42, 20), // + S(95, 25), S(89, 51), S(102, 66), S(99, 111), S(104, 111), S(68, 76), S(49, 43), S(37, 37), // + S(77, 17), S(103, 6), S(97, 52), S(90, 84), S(76, 86), S(72, 67), S(60, 15), S(22, 33), // + S(18, -36), S(45, -17), S(49, 24), S(61, 59), S(56, 57), S(30, 18), S(15, -7), S(-25, -31), // + S(41, -25), S(41, -7), S(27, -11), S(34, 16), S(32, 12), S(5, -37), S(-29, -0), S(-38, -88), // + S(-42, -71), S(8, -19), S(27, -37), S(44, -24), S(25, -7), S(-12, -43), S(-19, -18), S(-64, -125), // }; inline const std::array BISHOP_PSQT = { - S(-127, 27), S(-179, 111), S(-423, 184), S(-259, 87), S(-293, 140), S(-298, 149), S(-209, 126), S(-121, 68), // - S(-30, -12), S(-75, 95), S(-37, 59), S(-68, 69), S(-67, 75), S(-34, 46), S(-8, 40), S(-41, 22), // - S(38, 27), S(12, 69), S(31, 75), S(24, 67), S(23, 48), S(17, 52), S(13, 49), S(17, 18), // - S(15, 4), S(53, 25), S(62, 44), S(75, 63), S(101, 49), S(48, 22), S(51, -2), S(3, 1), // - S(45, -43), S(47, 7), S(81, 16), S(94, 30), S(78, 46), S(68, 27), S(22, 13), S(19, -30), // - S(61, -26), S(85, -24), S(98, 9), S(67, 35), S(63, 19), S(60, 21), S(65, -1), S(20, -14), // - S(31, -76), S(113, -45), S(71, -12), S(49, 5), S(32, 6), S(52, -37), S(50, -46), S(44, -51), // - S(50, -73), S(21, -9), S(26, -0), S(49, -26), S(31, -14), S(38, 20), S(45, -12), S(42, -52), // + S(-126, 28), S(-177, 113), S(-421, 185), S(-256, 87), S(-290, 141), S(-295, 151), S(-209, 128), S(-121, 72), // + S(-30, -10), S(-75, 97), S(-36, 60), S(-66, 69), S(-66, 76), S(-34, 47), S(-7, 43), S(-43, 25), // + S(37, 29), S(15, 68), S(33, 77), S(26, 68), S(23, 50), S(19, 54), S(13, 51), S(17, 20), // + S(16, 4), S(52, 27), S(63, 46), S(75, 65), S(101, 51), S(46, 25), S(51, 0), S(2, 4), // + S(44, -39), S(47, 9), S(79, 20), S(94, 32), S(77, 49), S(69, 29), S(22, 14), S(19, -28), // + S(61, -24), S(85, -21), S(98, 10), S(66, 38), S(64, 20), S(60, 23), S(66, 1), S(20, -12), // + S(31, -74), S(115, -45), S(71, -11), S(49, 6), S(31, 9), S(53, -37), S(50, -44), S(44, -48), // + S(52, -73), S(21, -7), S(26, 1), S(48, -25), S(31, -14), S(37, 22), S(46, -11), S(43, -50), // }; inline const std::array ROOK_PSQT = { - S(190, 91), S(222, 107), S(164, 140), S(149, 120), S(215, 69), S(178, 94), S(191, 99), S(164, 104), // - S(95, 149), S(150, 148), S(209, 110), S(154, 111), S(196, 92), S(157, 116), S(106, 146), S(100, 149), // - S(65, 142), S(188, 87), S(215, 68), S(192, 50), S(192, 70), S(132, 110), S(132, 120), S(77, 161), // - S(41, 109), S(106, 113), S(135, 84), S(109, 89), S(140, 72), S(99, 116), S(91, 126), S(32, 153), // - S(7, 53), S(73, 59), S(69, 73), S(40, 82), S(51, 86), S(38, 114), S(18, 113), S(-5, 119), // - S(20, -24), S(91, -0), S(81, 22), S(61, 30), S(72, 38), S(43, 66), S(44, 49), S(-2, 59), // - S(-65, -20), S(66, -59), S(71, -23), S(59, 10), S(64, 8), S(48, 24), S(36, 9), S(5, 17), // - S(-4, -42), S(12, -2), S(83, -19), S(93, -22), S(93, -16), S(70, 10), S(67, -1), S(48, 5), // + S(192, 92), S(223, 108), S(165, 141), S(150, 121), S(217, 70), S(179, 95), S(191, 101), S(167, 106), // + S(96, 151), S(148, 150), S(205, 114), S(150, 114), S(191, 96), S(153, 120), S(102, 151), S(99, 152), // + S(63, 145), S(181, 92), S(207, 73), S(184, 55), S(183, 76), S(123, 116), S(125, 125), S(72, 165), // + S(36, 114), S(97, 120), S(125, 91), S(99, 96), S(128, 80), S(88, 125), S(81, 133), S(25, 159), // + S(4, 56), S(68, 63), S(61, 79), S(31, 89), S(41, 94), S(29, 120), S(11, 119), S(-9, 122), // + S(17, -21), S(84, 5), S(75, 27), S(54, 36), S(64, 43), S(37, 72), S(37, 55), S(-5, 62), // + S(-64, -19), S(63, -57), S(69, -20), S(58, 12), S(61, 11), S(45, 28), S(34, 11), S(4, 19), // + S(-4, -41), S(12, -1), S(83, -18), S(93, -21), S(92, -14), S(69, 12), S(66, 1), S(48, 6), // }; inline const std::array QUEEN_PSQT = { - S(69, 178), S(139, 155), S(47, 298), S(-9, 392), S(34, 338), S(63, 255), S(58, 176), S(2, 225), // - S(48, 208), S(54, 260), S(15, 336), S(-124, 469), S(-73, 431), S(-22, 328), S(25, 197), S(17, 180), // - S(4, 262), S(34, 294), S(-8, 382), S(-52, 423), S(-28, 400), S(21, 283), S(58, 181), S(46, 132), // - S(15, 179), S(3, 275), S(-28, 322), S(-51, 403), S(-37, 406), S(2, 260), S(41, 174), S(24, 137), // - S(7, 170), S(-1, 196), S(-15, 247), S(-40, 315), S(-29, 337), S(-5, 266), S(1, 198), S(30, 102), // - S(6, 65), S(29, 85), S(25, 158), S(1, 180), S(10, 190), S(12, 216), S(34, 145), S(19, 115), // - S(-20, -76), S(7, -72), S(12, 1), S(36, 41), S(31, 82), S(34, 59), S(8, 92), S(22, 69), // - S(-31, -55), S(-15, -206), S(16, -213), S(30, -100), S(38, -24), S(37, -55), S(34, -28), S(5, 23), // + S(78, 170), S(151, 143), S(61, 284), S(6, 378), S(51, 321), S(79, 239), S(72, 163), S(10, 218), // + S(60, 196), S(82, 231), S(48, 303), S(-85, 433), S(-33, 394), S(12, 298), S(56, 168), S(27, 171), // + S(18, 246), S(56, 276), S(19, 358), S(-18, 393), S(4, 371), S(52, 256), S(82, 160), S(61, 119), // + S(18, 177), S(20, 260), S(-11, 309), S(-23, 377), S(-8, 377), S(22, 245), S(60, 157), S(29, 134), // + S(10, 169), S(6, 191), S(-4, 240), S(-29, 305), S(-18, 327), S(6, 255), S(9, 191), S(32, 101), // + S(3, 72), S(31, 87), S(28, 159), S(6, 179), S(14, 188), S(15, 214), S(36, 142), S(15, 119), // + S(-27, -65), S(2, -59), S(9, 11), S(33, 48), S(29, 86), S(30, 64), S(5, 94), S(16, 74), // + S(-38, -50), S(-22, -195), S(8, -196), S(23, -87), S(31, -13), S(29, -44), S(27, -23), S(-2, 25), // }; inline const std::array KING_PSQT = { - S(102, -577), S(486, 1), S(296, 176), S(3, 153), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(343, -181), S(375, 134), S(207, 179), S(20, 136), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(187, 42), S(225, 159), S(118, 190), S(-39, 166), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(15, 10), S(93, 114), S(-18, 161), S(-92, 177), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-116, -2), S(-33, 78), S(-90, 141), S(-172, 188), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-54, -30), S(12, 35), S(-73, 116), S(-124, 160), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(22, -81), S(29, -5), S(-33, 56), S(-109, 112), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // - S(-19, -198), S(4, -81), S(-77, -17), S(-74, -38), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(99, -577), S(482, 4), S(295, 176), S(2, 153), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(341, -179), S(377, 134), S(207, 179), S(20, 136), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(187, 43), S(227, 158), S(120, 189), S(-37, 165), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(16, 10), S(96, 112), S(-17, 159), S(-91, 176), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-115, -3), S(-32, 77), S(-89, 140), S(-171, 187), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-53, -31), S(14, 34), S(-72, 115), S(-123, 158), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(22, -83), S(30, -6), S(-34, 56), S(-110, 111), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // + S(-19, -199), S(4, -82), S(-79, -17), S(-76, -38), S(0, 0), S(0, 0), S(0, 0), S(0, 0), // }; -inline const PParam KS_NO_QUEEN = S(-87, -436); +inline const PParam KS_NO_QUEEN = S(-86, -435); inline const std::array PT_INNER_RING_ATTACKS = { - S(8, -5), S(10, 11), S(10, 5), S(5, 1), S(3, -10), + S(8, -4), S(10, 11), S(10, 5), S(5, 1), S(3, -10), }; inline const std::array PT_OUTER_RING_ATTACKS = { - S(4, -7), S(5, 4), S(2, 2), S(3, -0), S(4, -2), + S(4, -7), S(5, 4), S(2, 2), S(3, -0), S(4, -1), }; inline const PParam KS_FLANK_ATTACK = S(3, -2); -inline const PParam KS_FLANK_DEFENSE = S(-3, -0); +inline const PParam KS_FLANK_DEFENSE = S(-3, 0); inline const PParam KS_FLANK_DOUBLE_ATTACK = S(3, -1); inline const PParam KS_FLANK_DOUBLE_DEFENSE = S(-2, 2); inline const std::array, 4> KING_SHELTER = {{ - {{ S(18, -20), S(-6, 5), S(-2, -9), S(9, -16), S(13, -27), S(7, -54), S(-4, -46), }}, - {{ S(3, 2), S(-21, 0), S(-16, 8), S(-9, 17), S(-6, 7), S(-9, -12), S(-19, -24), }}, - {{ S(-4, -0), S(-12, -9), S(-14, 20), S(-9, 19), S(-8, 12), S(-9, -16), S(-26, -43), }}, - {{ S(7, 8), S(-9, 18), S(-6, 40), S(-1, 44), S(-1, 39), S(4, 16), S(8, -14), }}, + {{ S(18, -20), S(-7, 5), S(-3, -10), S(8, -17), S(12, -27), S(6, -54), S(-5, -45), }}, + {{ S(2, 2), S(-22, -0), S(-17, 8), S(-10, 16), S(-7, 7), S(-10, -11), S(-20, -24), }}, + {{ S(-3, -2), S(-12, -11), S(-13, 18), S(-8, 17), S(-7, 10), S(-9, -17), S(-25, -44), }}, + {{ S(7, 8), S(-10, 18), S(-7, 39), S(-2, 43), S(-2, 38), S(4, 16), S(8, -14), }}, }}; inline const std::array BLOCKED_SHELTER_STORM = { - S(0, 0), S(0, 0), S(10, 26), S(-5, 4), S(-7, 12), S(-5, 29), S(2, 50), + S(0, 0), S(0, 0), S(10, 25), S(-5, 3), S(-7, 10), S(-5, 28), S(2, 48), }; inline const std::array, 4> SHELTER_STORM = {{ - {{ S(6, 12), S(-45, -145), S(-8, -45), S(0, 5), S(-2, 5), S(-5, 11), S(-5, 10), }}, - {{ S(10, 1), S(-24, -132), S(-6, -32), S(-3, 2), S(-0, -2), S(-7, 5), S(2, 3), }}, - {{ S(0, 11), S(-10, -83), S(7, -15), S(1, 9), S(-3, 11), S(-9, 20), S(-5, 21), }}, - {{ S(2, 1), S(3, -63), S(-1, 29), S(-2, 26), S(-6, 10), S(-12, 13), S(-10, 21), }}, + {{ S(6, 11), S(-45, -143), S(-8, -45), S(0, 4), S(-2, 4), S(-5, 11), S(-5, 9), }}, + {{ S(10, -0), S(-24, -130), S(-6, -31), S(-3, 1), S(-0, -3), S(-7, 4), S(2, 3), }}, + {{ S(0, 10), S(-10, -81), S(7, -15), S(1, 9), S(-3, 10), S(-9, 19), S(-5, 20), }}, + {{ S(2, -1), S(3, -61), S(-1, 27), S(-2, 25), S(-5, 9), S(-12, 11), S(-9, 19), }}, }}; inline TunableSigmoid<32> KING_SAFETY_ACTIVATION( - 1362, 848, -22, -7 + 1362, 856, -20, -3 ); inline VParam WINNABLE_PAWNS = V(-20); -inline VParam WINNABLE_SYM = V(102); +inline VParam WINNABLE_SYM = V(101); inline VParam WINNABLE_ASYM = V(84); inline VParam WINNABLE_PAWN_ENDGAME = V(105); -inline VParam WINNABLE_BIAS = V(-379); +inline VParam WINNABLE_BIAS = V(-378); -// Epoch duration: 6.95597s +// Epoch duration: 7.18402s // clang-format on } // namespace Clockwork diff --git a/src/evaltune_main.cpp b/src/evaltune_main.cpp index cdd11370..47f0db1b 100644 --- a/src/evaltune_main.cpp +++ b/src/evaltune_main.cpp @@ -510,6 +510,10 @@ void print_params() { std::cout << "inline const PParam HANGING_PAWN = " << HANGING_PAWN << ";" << std::endl; std::cout << "inline const PParam HANGING_NON_PAWN = " << HANGING_NON_PAWN << ";" << std::endl << std::endl; + print_table("KNIGHT_ON_QUEEN", KNIGHT_ON_QUEEN); + print_table("BISHOP_ON_QUEEN", BISHOP_ON_QUEEN); + print_table("ROOK_ON_QUEEN", ROOK_ON_QUEEN); + std::cout << std::endl; print_table("BISHOP_PAWNS", BISHOP_PAWNS); std::cout << std::endl; diff --git a/src/evaluation.cpp b/src/evaluation.cpp index 85b40476..d5466d3d 100644 --- a/src/evaluation.cpp +++ b/src/evaluation.cpp @@ -17,10 +17,12 @@ struct EvalData { Bitboard any_attacks_by[2]; Bitboard any2_attacks_by[2]; Bitboard attacks_by_pt[2][7]; - Bitboard m_pawn_files[2]; - i32 m_piece_count[2][6]; - i32 wcount = 0; - i32 bcount = 0; + + Bitboard mobility_area[2]; + + i32 m_piece_count[2][6]; + i32 wcount = 0; + i32 bcount = 0; void init(const Position& pos) { any_attacks_by[0] = pos.attack_table(Color::White).get_attacked_bitboard(); @@ -48,9 +50,6 @@ struct EvalData { pos.attacked_by(Color::White, PieceType::King); attacks_by_pt[static_cast(Color::Black)][static_cast(PieceType::King)] = pos.attacked_by(Color::Black, PieceType::King); - - m_pawn_files[0] = Bitboard::fill_verticals(pos.bitboard_for(Color::White, PieceType::Pawn)); - m_pawn_files[1] = Bitboard::fill_verticals(pos.bitboard_for(Color::Black, PieceType::Pawn)); } inline i32 piece_count(const Color color, const PieceType pt) const { @@ -72,10 +71,6 @@ struct EvalData { inline Bitboard attacked_by_2(const Color color) const { return any2_attacks_by[static_cast(color)]; } - - inline Bitboard pawn_files(const Color color) const { - return m_pawn_files[static_cast(color)]; - } }; static i32 chebyshev_distance(Square a, Square b) { @@ -156,6 +151,16 @@ std::array extended_ring_table = []() { }(); +std::array orthogonal_squares_table = []() { + std::array orthogonal_squares_table{}; + for (u8 sq_idx = 0; sq_idx < 64; sq_idx++) { + Square sq = Square{sq_idx}; + orthogonal_squares_table[sq_idx] = + Bitboard::file_mask(sq.file()) | Bitboard::rank_mask(sq.rank()); + } + return orthogonal_squares_table; +}(); + std::array diagonal_squares_table = []() { std::array diagonal_squares_table{}; for (u8 sq_idx = 0; sq_idx < 64; sq_idx++) { @@ -173,6 +178,23 @@ std::array diagonal_squares_table = []() { return diagonal_squares_table; }(); +std::array knight_squares_table = []() { + std::array knight_squares_table{}; + for (u8 sq_idx = 0; sq_idx < 64; sq_idx++) { + Square sq = Square{sq_idx}; + Bitboard sqb = Bitboard::from_square(sq); + knight_squares_table[sq_idx] = sqb.shift(Direction::North).shift(Direction::NorthEast) + | sqb.shift(Direction::North).shift(Direction::NorthWest) + | sqb.shift(Direction::South).shift(Direction::SouthEast) + | sqb.shift(Direction::South).shift(Direction::SouthWest) + | sqb.shift(Direction::West).shift(Direction::NorthWest) + | sqb.shift(Direction::West).shift(Direction::SouthWest) + | sqb.shift(Direction::East).shift(Direction::NorthEast) + | sqb.shift(Direction::East).shift(Direction::SouthEast); + } + return knight_squares_table; +}(); + std::array, 2> passed_pawn_spans = []() { std::array, 2> passed_pawn_masks{}; for (Color color : {Color::White, Color::Black}) { @@ -244,7 +266,7 @@ std::tuple evaluate_pawns(const Position& pos, const EvalData& data Bitboard pawns = pos.board().bitboard_for(color, PieceType::Pawn); Bitboard opp_pawns = pos.board().bitboard_for(~color, PieceType::Pawn); - Bitboard pawn_files = data.pawn_files(color); + Bitboard pawn_files = Bitboard::fill_verticals(pawns); Bitboard doubled = pawns & pawns.shift(Direction::North); Bitboard isolated = pawns & ~(pawn_files.shift(Direction::East) | pawn_files.shift(Direction::West)); @@ -317,7 +339,7 @@ PScore evaluate_pawn_push_threats(const Position& pos) { } template -PScore evaluate_pieces(const Position& pos, const EvalData& data) { +PScore evaluate_pieces(const Position& pos, EvalData& data) { constexpr Color opp = ~color; PScore eval = PSCORE_ZERO; Bitboard own_pawns = pos.bitboard_for(color, PieceType::Pawn); @@ -327,8 +349,9 @@ PScore evaluate_pieces(const Position& pos, const EvalData& data) { ? Bitboard::rank_mask(1) | Bitboard::rank_mask(2) : Bitboard::rank_mask(5) | Bitboard::rank_mask(6); Bitboard own_early_pawns = own_pawns & early_ranks; - Bitboard bb = (blocked_pawns | own_early_pawns) | data.attacked_by(opp, PieceType::Pawn); - Bitboard bb2 = bb; + Bitboard bb = (blocked_pawns | own_early_pawns) | data.attacked_by(opp, PieceType::Pawn); + data.mobility_area[static_cast(color)] = ~bb; + Bitboard bb2 = bb; for (PieceId id : pos.get_piece_mask(color, PieceType::Knight)) { eval += KNIGHT_MOBILITY[pos.mobility_of(color, id, ~bb)]; } @@ -519,6 +542,38 @@ PScore evaluate_threats(const Position& pos, const EvalData& data) { eval += PAWN_THREAT_QUEEN * (pos.bitboard_for(opp, PieceType::Queen) & pawn_attacks).ipopcount(); + // Our attacks on enemy queen + if (data.piece_count(opp, PieceType::Queen) == 1) { + + Bitboard opp_queens = pos.bitboard_for(opp, PieceType::Queen); + + bool queen_imbalance = data.piece_count(color, PieceType::Queen) == 0; + + Square sq = opp_queens.lsb(); + Bitboard safe = data.mobility_area[static_cast(color)] + & ~pos.bitboard_for(color, PieceType::Pawn) & ~strongly_protected; + + + b = knight_squares_table[sq.raw] & data.attacked_by(color, PieceType::Knight) & safe; + eval += KNIGHT_ON_QUEEN[queen_imbalance] * b.ipopcount(); + + safe &= data.attacked_by_2(color); + + Bitboard attacks = data.attacked_by(opp, PieceType::Queen); + + Bitboard a = attacks & diagonal_squares_table[sq.raw]; + + b = a & data.attacked_by(color, PieceType::Bishop) + & safe; + eval += BISHOP_ON_QUEEN[queen_imbalance] * b.ipopcount(); + + a = attacks ^ a; + + b = a & data.attacked_by(color, PieceType::Rook) + & safe; + eval += ROOK_ON_QUEEN[queen_imbalance] * b.ipopcount(); + } + return eval; } @@ -526,8 +581,8 @@ template PScore evaluate_space(const Position& pos, const EvalData& data) { PScore eval = PSCORE_ZERO; constexpr Color them = color == Color::White ? Color::Black : Color::White; - Bitboard ourfiles = data.pawn_files(color); - Bitboard theirfiles = data.pawn_files(them); + Bitboard ourfiles = Bitboard::fill_verticals(pos.bitboard_for(color, PieceType::Pawn)); + Bitboard theirfiles = Bitboard::fill_verticals(pos.bitboard_for(them, PieceType::Pawn)); Bitboard openfiles = ~(ourfiles | theirfiles); Bitboard half_open_files = (~ourfiles) & theirfiles; Bitboard ourminors = @@ -558,7 +613,7 @@ PScore king_safety_activation(PScore& king_safety_score) { return activated; } -PScore apply_winnable(const Position& pos, PScore& score, i32 phase, EvalData& eval_data) { +PScore apply_winnable(const Position& pos, PScore& score, i32 phase) { bool pawn_endgame = phase == 0; @@ -567,8 +622,8 @@ PScore apply_winnable(const Position& pos, PScore& score, i32 phase, EvalData& e i32 pawn_count = (white_pawns | black_pawns).ipopcount(); - Bitboard white_files = eval_data.pawn_files(Color::White); - Bitboard black_files = eval_data.pawn_files(Color::Black); + Bitboard white_files = Bitboard::fill_verticals(white_pawns); + Bitboard black_files = Bitboard::fill_verticals(black_pawns); i32 sym_files = (white_files & black_files).ipopcount() / 8; i32 asym_files = (white_files ^ black_files).ipopcount() / 8; @@ -678,7 +733,7 @@ Score evaluate_white_pov(const Position& pos, const PsqtState& psqt_state) { eval += (us == Color::White) ? TEMPO_VAL : -TEMPO_VAL; // Winnable - eval = apply_winnable(pos, eval, phase, eval_data); + eval = apply_winnable(pos, eval, phase); // Eg scaling eval = diff --git a/src/square.hpp b/src/square.hpp index 3f4df0a2..b97674b2 100644 --- a/src/square.hpp +++ b/src/square.hpp @@ -50,11 +50,11 @@ struct Square { return ((file() + rank()) & 1) ? Color::White : Color::Black; } - [[nodiscard]] constexpr Square relative_sq(Color c) const { + [[nodiscard]] constexpr Square relative_sq(const Color c) const { return c == Color::White ? *this : flip_vertical(); } - [[nodiscard]] constexpr i32 relative_rank(Color c) const { + [[nodiscard]] constexpr i32 relative_rank(const Color c) const { return c == Color::White ? rank() : rank() ^ 7; } From d2c0661d42229b23516b0334de86e61c28d8d91c Mon Sep 17 00:00:00 2001 From: TheRealGioviok <425gioviok@gmail.com> Date: Thu, 11 Jun 2026 00:39:51 +0200 Subject: [PATCH 3/3] Format Bench: 15632420 --- src/evaluation.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/evaluation.cpp b/src/evaluation.cpp index d5466d3d..013caab6 100644 --- a/src/evaluation.cpp +++ b/src/evaluation.cpp @@ -563,14 +563,12 @@ PScore evaluate_threats(const Position& pos, const EvalData& data) { Bitboard a = attacks & diagonal_squares_table[sq.raw]; - b = a & data.attacked_by(color, PieceType::Bishop) - & safe; + b = a & data.attacked_by(color, PieceType::Bishop) & safe; eval += BISHOP_ON_QUEEN[queen_imbalance] * b.ipopcount(); - a = attacks ^ a; + a = attacks ^ a; - b = a & data.attacked_by(color, PieceType::Rook) - & safe; + b = a & data.attacked_by(color, PieceType::Rook) & safe; eval += ROOK_ON_QUEEN[queen_imbalance] * b.ipopcount(); } @@ -579,11 +577,11 @@ PScore evaluate_threats(const Position& pos, const EvalData& data) { template PScore evaluate_space(const Position& pos, const EvalData& data) { - PScore eval = PSCORE_ZERO; - constexpr Color them = color == Color::White ? Color::Black : Color::White; + PScore eval = PSCORE_ZERO; + constexpr Color them = color == Color::White ? Color::Black : Color::White; Bitboard ourfiles = Bitboard::fill_verticals(pos.bitboard_for(color, PieceType::Pawn)); Bitboard theirfiles = Bitboard::fill_verticals(pos.bitboard_for(them, PieceType::Pawn)); - Bitboard openfiles = ~(ourfiles | theirfiles); + Bitboard openfiles = ~(ourfiles | theirfiles); Bitboard half_open_files = (~ourfiles) & theirfiles; Bitboard ourminors = pos.bitboard_for(color, PieceType::Knight) | pos.bitboard_for(color, PieceType::Bishop);