diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 27463022..1e22ed00 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -271,19 +271,19 @@ namespace { #endif #ifdef THREECHECK { - { S(-75,-76), S(-56,-54), S( -9,-26), S( -2,-10), S( 6, 5), S( 15, 11), // Knights - S( 22, 26), S( 30, 28), S( 36, 29) }, - { S(-48,-58), S(-21,-19), S( 16, -2), S( 26, 12), S( 37, 22), S( 51, 42), // Bishops - S( 54, 54), S( 63, 58), S( 65, 63), S( 71, 70), S( 79, 74), S( 81, 86), - S( 92, 90), S( 97, 94) }, - { S(-56,-78), S(-25,-18), S(-11, 26), S( -5, 55), S( -4, 70), S( -1, 81), // Rooks - S( 8,109), S( 14,120), S( 21,128), S( 23,143), S( 31,154), S( 32,160), - S( 43,165), S( 49,168), S( 59,169) }, - { S(-40,-35), S(-25,-12), S( 2, 7), S( 4, 19), S( 14, 37), S( 24, 55), // Queens - S( 25, 62), S( 40, 76), S( 43, 79), S( 47, 87), S( 54, 94), S( 56,102), - S( 60,111), S( 70,116), S( 72,118), S( 73,122), S( 75,128), S( 77,130), - S( 85,133), S( 94,136), S( 99,140), S(108,157), S(112,158), S(113,161), - S(118,174), S(119,177), S(123,191), S(128,199) } + { S(-74,-76), S(-55,-54), S( -9,-26), S( -2,-10), S( 6, 5), S( 15, 11), // Knights + S( 22, 26), S( 31, 27), S( 37, 29) }, + { S(-49,-56), S(-23,-18), S( 15, -2), S( 25, 12), S( 36, 22), S( 50, 42), // Bishops + S( 53, 54), S( 64, 57), S( 67, 63), S( 71, 68), S( 84, 76), S( 79, 87), + S( 95, 91), S( 98, 93) }, + { S(-57,-76), S(-25,-18), S(-11, 25), S( -5, 53), S( -4, 70), S( -1, 78), // Rooks + S( 8,111), S( 14,116), S( 22,125), S( 24,148), S( 31,159), S( 31,173), + S( 44,163), S( 50,162), S( 56,168) }, + { S(-42,-35), S(-25,-12), S( 2, 7), S( 4, 19), S( 14, 37), S( 24, 53), // Queens + S( 26, 63), S( 39, 80), S( 42, 77), S( 48, 88), S( 53, 96), S( 57, 96), + S( 61,108), S( 71,116), S( 70,116), S( 74,125), S( 75,133), S( 78,133), + S( 85,137), S( 97,135), S(103,141), S(107,165), S(109,153), S(115,162), + S(119,164), S(121,184), S(121,192), S(131,203) } }, #endif }; @@ -331,8 +331,8 @@ namespace { #endif #ifdef ATOMIC { - { V(85), V(120), V(85), V(138), V(184), V(207) }, - { V(80), V( 49), V(55), V( 77), V(156), V(241) } + { V(95), V(118), V(94), V(142), V(196), V(204) }, + { V(86), V( 43), V(61), V( 62), V(150), V(256) } }, #endif #ifdef CRAZYHOUSE @@ -382,17 +382,17 @@ namespace { #ifdef THREECHECK const Score ChecksGivenBonus[CHECKS_NB] = { S(0, 0), - S(472, 369), - S(1980, 1159), + S(489, 373), + S(1998, 1102), S(0, 0) }; #endif #ifdef KOTH const Score KothDistanceBonus[6] = { - S(1634, 1553), S(400, 384), S(165, 174), S(83, 87), S(49, 50), S(0, 0) + S(1991, 1658), S(448, 364), S(163, 176), S(80, 89), S(50, 50), S(0, 0) }; - const Score KothSafeCenter = S(159, 211); + const Score KothSafeCenter = S(157, 202); #endif #ifdef ANTI @@ -427,7 +427,7 @@ namespace { #ifdef CRAZYHOUSE const int KingDangerInHand[PIECE_TYPE_NB] = { - 0, 128, 128, 28, 69, 75 + 0, 134, 199, 37, 100, 110 }; #endif @@ -488,7 +488,7 @@ namespace { S( 7, 0), #endif #ifdef THREECHECK - S(15, 10), + S(16, 9), #endif }; const Score PawnlessFlank = S( 20, 80); @@ -749,7 +749,7 @@ namespace { 2 * int(BishopValueMg), #endif #ifdef THREECHECK - 4 * int(BishopValueMg), + 3264, #endif }; diff --git a/src/material.cpp b/src/material.cpp index ae3b23b2..bdc40459 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -83,13 +83,13 @@ namespace { { // OUR PIECES // pair pawn knight bishop rook queen king - { 0 }, // Bishop pair - { 0, 0 }, // Pawn - { 0, 0, 0 }, // Knight OUR PIECES - { 0, 0, 0, 0 }, // Bishop - { 0, 0, 0, 0, 0 }, // Rook - { 0, 0, 0, 0, 0, 0 }, // Queen - { 0, 0, 0, 0, 0, 0, 0 } // King + { 13 }, // Bishop pair + { -2, 0 }, // Pawn + { -65, 66, 15 }, // Knight OUR PIECES + { 0, 81, -2, 0 }, // Bishop + { 26, 21, -38, 80, -70 }, // Rook + { 24, -27, 75, 32, 2, -70 }, // Queen + { 0, 0, 0, 0, 0, 0, 0 } // King }, #endif #ifdef KOTH @@ -153,6 +153,18 @@ namespace { }, #endif }; +#ifdef CRAZYHOUSE + const int QuadraticOursInHand[PIECE_TYPE_NB][PIECE_TYPE_NB] = { + // OUR PIECES + //empty pawn knight bishop rook queen + { -88 }, // Empty hand + { 0, -44 }, // Pawn + { 0, 33, 21 }, // Knight OUR PIECES + { 0, -52, -16, -6 }, // Bishop + { 0, 14, 44, -54, 19 }, // Rook + { 0, -5, 5, -19, 2, -29 } // Queen + }; +#endif const int QuadraticTheirs[VARIANT_NB][PIECE_TYPE_NB][PIECE_TYPE_NB] = { { @@ -212,7 +224,7 @@ namespace { { 0, 0, 0, 0 }, // Bishop { 0, 0, 0, 0, 0 }, // Rook { 0, 0, 0, 0, 0, 0 }, // Queen - { 0, -789, -872, -19, -416, -594, 0 } // King + { 0, -557, -711, -86, -386, -655, 0 } // King }, #endif #ifdef KOTH @@ -276,6 +288,18 @@ namespace { }, #endif }; +#ifdef CRAZYHOUSE + const int QuadraticTheirsInHand[PIECE_TYPE_NB][PIECE_TYPE_NB] = { + // THEIR PIECES + //empty pawn knight bishop rook queen + { 0 }, // Empty hand + { -6, 0 }, // Pawn + { 7, 13, 0 }, // Knight OUR PIECES + { -19, 34, -17, 0 }, // Bishop + { -37, -8, -7, 7, 0 }, // Rook + { 1, 16, -25, 32, -3, 0 } // Queen + }; +#endif // PawnsSet[count] contains a bonus/malus indexed by number of pawns const int PawnsSet[FILE_NB + 1] = { @@ -324,7 +348,12 @@ namespace { /// imbalance() calculates the imbalance by comparing the piece count of each /// piece type for both colors. template +#ifdef CRAZYHOUSE + int imbalance(const Position& pos, const int pieceCount[][PIECE_TYPE_NB], + const int pieceCountInHand[][PIECE_TYPE_NB]) { +#else int imbalance(const Position& pos, const int pieceCount[][PIECE_TYPE_NB]) { +#endif const Color Them = (Us == WHITE ? BLACK : WHITE); @@ -353,6 +382,21 @@ namespace { bonus += pieceCount[Us][pt1] * v; } +#ifdef CRAZYHOUSE + for (int pt1 = NO_PIECE_TYPE; pt1 <= pt_max; ++pt1) + { + if (!pieceCountInHand[Us][pt1]) + continue; + + int v = 0; + + for (int pt2 = NO_PIECE_TYPE; pt2 <= pt1; ++pt2) + v += QuadraticOursInHand[pt1][pt2] * pieceCountInHand[Us][pt2] + + QuadraticTheirsInHand[pt1][pt2] * pieceCountInHand[Them][pt2]; + + bonus += pieceCountInHand[Us][pt1] * v; + } +#endif return bonus; } @@ -491,8 +535,17 @@ Entry* probe(const Position& pos) { pos.count(WHITE) , pos.count(WHITE), pos.count(WHITE), pos.count(WHITE) }, { pos.count(BLACK) > 1, pos.count(BLACK), pos.count(BLACK), pos.count(BLACK) , pos.count(BLACK), pos.count(BLACK), pos.count(BLACK) } }; - +#ifdef CRAZYHOUSE + const int PieceCountInHand[COLOR_NB][PIECE_TYPE_NB] = { + { pos.count_in_hand(WHITE) == 0, pos.count_in_hand(WHITE), pos.count_in_hand(WHITE), + pos.count_in_hand(WHITE) , pos.count_in_hand(WHITE), pos.count_in_hand(WHITE), pos.count_in_hand(WHITE) }, + { pos.count_in_hand(BLACK) == 0, pos.count_in_hand(BLACK), pos.count_in_hand(BLACK), + pos.count_in_hand(BLACK) , pos.count_in_hand(BLACK), pos.count_in_hand(BLACK), pos.count_in_hand(BLACK) } }; + + e->value = int16_t((imbalance(pos, PieceCount, PieceCountInHand) - imbalance(pos, PieceCount, PieceCountInHand)) / 16); +#else e->value = int16_t((imbalance(pos, PieceCount) - imbalance(pos, PieceCount)) / 16); +#endif return e; } diff --git a/src/movegen.cpp b/src/movegen.cpp index 5614cff2..e23eb01c 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -605,6 +605,10 @@ ExtMove* generate(const Position& pos, ExtMove* moveList) { if (pos.is_anti()) return moveList; #endif +#ifdef RACE + if (pos.is_race()) + return moveList; +#endif assert(pos.checkers()); diff --git a/src/pawns.cpp b/src/pawns.cpp index 8b6b6574..6ce951c4 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -38,7 +38,7 @@ namespace { { S(50, 80), S(54, 69) }, #endif #ifdef ATOMIC - { S(25, 27), S(27, 18) }, + { S(27, 28), S(24, 14) }, #endif #ifdef CRAZYHOUSE { S(45, 40), S(30, 27) }, @@ -70,7 +70,7 @@ namespace { { S(64, 25), S(26, 50) }, #endif #ifdef ATOMIC - { S(41, 25), S(41, 13) }, + { S(48, 21), S(35, 15) }, #endif #ifdef CRAZYHOUSE { S(56, 33), S(41, 19) }, @@ -102,7 +102,7 @@ namespace { S(-45, -48), #endif #ifdef ATOMIC - S( 45, 0), + S( 39, 0), #endif #ifdef CRAZYHOUSE S( 17, 8), @@ -182,10 +182,10 @@ namespace { #endif #ifdef ATOMIC { - { V(100), V(50), V(10), V(46), V(82), V( 86), V( 98) }, - { V(116), V(50), V(10), V(87), V(94), V(108), V(104) }, - { V(109), V(50), V(10), V(87), V(62), V( 91), V(116) }, - { V( 75), V(50), V(10), V(59), V(90), V( 84), V(112) } + { V( 88), V(34), V( 5), V(44), V( 89), V( 90), V( 94) }, + { V(116), V(61), V(-4), V(80), V( 95), V(101), V(104) }, + { V( 97), V(68), V(34), V(82), V( 62), V(104), V(110) }, + { V(103), V(44), V(44), V(77), V(103), V( 66), V(118) } }, #endif #ifdef CRAZYHOUSE @@ -233,10 +233,10 @@ namespace { #endif #ifdef THREECHECK { - { V(103), V( 0), V(21), V( 54), V(87), V( 89), V(100) }, - { V(112), V( 3), V(54), V(105), V(85), V(105), V(100) }, - { V(118), V(22), V(68), V( 93), V(60), V( 88), V(119) }, - { V( 92), V(11), V(51), V( 66), V(93), V( 86), V(118) } + { V(105), V( 1), V(22), V( 52), V(86), V( 89), V( 98) }, + { V(116), V( 3), V(55), V(109), V(81), V( 97), V( 99) }, + { V(121), V(23), V(69), V( 93), V(58), V( 88), V(112) }, + { V( 94), V(11), V(52), V( 67), V(90), V( 85), V(112) } }, #endif }; @@ -244,7 +244,170 @@ namespace { // Danger of enemy pawns moving toward our king by [type][distance from edge][rank]. // For the unopposed and unblocked cases, RANK_1 = 0 is used when opponent has no pawn // on the given file, or their pawn is behind our king. - const Value StormDanger[][4][RANK_NB] = { + const Value StormDanger[VARIANT_NB][4][4][RANK_NB] = { + { + { { V( 0), V(-290), V(-274), V(57), V(41) }, //BlockedByKing + { V( 0), V( 60), V( 144), V(39), V(13) }, + { V( 0), V( 65), V( 141), V(41), V(34) }, + { V( 0), V( 53), V( 127), V(56), V(14) } }, + { { V( 4), V( 73), V( 132), V(46), V(31) }, //Unopposed + { V( 1), V( 64), V( 143), V(26), V(13) }, + { V( 1), V( 47), V( 110), V(44), V(24) }, + { V( 0), V( 72), V( 127), V(50), V(31) } }, + { { V( 0), V( 0), V( 79), V(23), V( 1) }, //BlockedByPawn + { V( 0), V( 0), V( 148), V(27), V( 2) }, + { V( 0), V( 0), V( 161), V(16), V( 1) }, + { V( 0), V( 0), V( 171), V(22), V(15) } }, + { { V(22), V( 45), V( 104), V(62), V( 6) }, //Unblocked + { V(31), V( 30), V( 99), V(39), V(19) }, + { V(23), V( 29), V( 96), V(41), V(15) }, + { V(21), V( 23), V( 116), V(41), V(15) } } + }, +#ifdef ANTI + { + { { V( 0), V(-290), V(-274), V(57), V(41) }, //BlockedByKing + { V( 0), V( 60), V( 144), V(39), V(13) }, + { V( 0), V( 65), V( 141), V(41), V(34) }, + { V( 0), V( 53), V( 127), V(56), V(14) } }, + { { V( 4), V( 73), V( 132), V(46), V(31) }, //Unopposed + { V( 1), V( 64), V( 143), V(26), V(13) }, + { V( 1), V( 47), V( 110), V(44), V(24) }, + { V( 0), V( 72), V( 127), V(50), V(31) } }, + { { V( 0), V( 0), V( 79), V(23), V( 1) }, //BlockedByPawn + { V( 0), V( 0), V( 148), V(27), V( 2) }, + { V( 0), V( 0), V( 161), V(16), V( 1) }, + { V( 0), V( 0), V( 171), V(22), V(15) } }, + { { V(22), V( 45), V( 104), V(62), V( 6) }, //Unblocked + { V(31), V( 30), V( 99), V(39), V(19) }, + { V(23), V( 29), V( 96), V(41), V(15) }, + { V(21), V( 23), V( 116), V(41), V(15) } } + }, +#endif +#ifdef ATOMIC + { + { { V( 0), V(-290), V(-274), V(57), V(41) }, //BlockedByKing + { V( 0), V( 60), V( 144), V(39), V(13) }, + { V( 0), V( 65), V( 141), V(41), V(34) }, + { V( 0), V( 53), V( 127), V(56), V(14) } }, + { { V( 4), V( 73), V( 132), V(46), V(31) }, //Unopposed + { V( 1), V( 64), V( 143), V(26), V(13) }, + { V( 1), V( 47), V( 110), V(44), V(24) }, + { V( 0), V( 72), V( 127), V(50), V(31) } }, + { { V( 0), V( 0), V( 79), V(23), V( 1) }, //BlockedByPawn + { V( 0), V( 0), V( 148), V(27), V( 2) }, + { V( 0), V( 0), V( 161), V(16), V( 1) }, + { V( 0), V( 0), V( 171), V(22), V(15) } }, + { { V(22), V( 45), V( 104), V(62), V( 6) }, //Unblocked + { V(31), V( 30), V( 99), V(39), V(19) }, + { V(23), V( 29), V( 96), V(41), V(15) }, + { V(21), V( 23), V( 116), V(41), V(15) } } + }, +#endif +#ifdef CRAZYHOUSE + { + { { V(-34), V(-366), V(-249), V( 12), V( 80) }, //BlockedByKing + { V( -6), V( 122), V( 158), V( 90), V( 3) }, + { V( 35), V( 89), V( 174), V( 87), V( 86) }, + { V(-77), V( 17), V( 154), V( 82), V( 99) } }, + { { V( 71), V( 67), V( 177), V( 49), V( 28) }, //Unopposed + { V(-86), V( 108), V( 104), V( 86), V( 26) }, + { V( 8), V( 20), V( 107), V(137), V( 35) }, + { V(-95), V( 69), V( 101), V(-10), V(-43) } }, + { { V( -8), V( 75), V( 276), V( 14), V(-71) }, //BlockedByPawn + { V(-28), V( -10), V( 231), V( 8), V( -6) }, + { V( 59), V( -14), V( 300), V( 26), V( -3) }, + { V(-81), V( 2), V( 104), V( 79), V(-19) } }, + { { V( 73), V( 78), V( 88), V( 46), V( 75) }, //Unblocked + { V( 35), V( 48), V( -21), V( 22), V(-52) }, + { V( 37), V( 67), V( 122), V( 6), V( 64) }, + { V( -5), V( 55), V( 101), V( 61), V( 33) } } + }, +#endif +#ifdef HORDE + { + { { V( 0), V(-290), V(-274), V(57), V(41) }, //BlockedByKing + { V( 0), V( 60), V( 144), V(39), V(13) }, + { V( 0), V( 65), V( 141), V(41), V(34) }, + { V( 0), V( 53), V( 127), V(56), V(14) } }, + { { V( 4), V( 73), V( 132), V(46), V(31) }, //Unopposed + { V( 1), V( 64), V( 143), V(26), V(13) }, + { V( 1), V( 47), V( 110), V(44), V(24) }, + { V( 0), V( 72), V( 127), V(50), V(31) } }, + { { V( 0), V( 0), V( 79), V(23), V( 1) }, //BlockedByPawn + { V( 0), V( 0), V( 148), V(27), V( 2) }, + { V( 0), V( 0), V( 161), V(16), V( 1) }, + { V( 0), V( 0), V( 171), V(22), V(15) } }, + { { V(22), V( 45), V( 104), V(62), V( 6) }, //Unblocked + { V(31), V( 30), V( 99), V(39), V(19) }, + { V(23), V( 29), V( 96), V(41), V(15) }, + { V(21), V( 23), V( 116), V(41), V(15) } } + }, +#endif +#ifdef KOTH + { + { { V( 0), V(-290), V(-274), V(57), V(41) }, //BlockedByKing + { V( 0), V( 60), V( 144), V(39), V(13) }, + { V( 0), V( 65), V( 141), V(41), V(34) }, + { V( 0), V( 53), V( 127), V(56), V(14) } }, + { { V( 4), V( 73), V( 132), V(46), V(31) }, //Unopposed + { V( 1), V( 64), V( 143), V(26), V(13) }, + { V( 1), V( 47), V( 110), V(44), V(24) }, + { V( 0), V( 72), V( 127), V(50), V(31) } }, + { { V( 0), V( 0), V( 79), V(23), V( 1) }, //BlockedByPawn + { V( 0), V( 0), V( 148), V(27), V( 2) }, + { V( 0), V( 0), V( 161), V(16), V( 1) }, + { V( 0), V( 0), V( 171), V(22), V(15) } }, + { { V(22), V( 45), V( 104), V(62), V( 6) }, //Unblocked + { V(31), V( 30), V( 99), V(39), V(19) }, + { V(23), V( 29), V( 96), V(41), V(15) }, + { V(21), V( 23), V( 116), V(41), V(15) } } + }, +#endif +#ifdef LOSERS + { + { { V( 0), V(-290), V(-274), V(57), V(41) }, //BlockedByKing + { V( 0), V( 60), V( 144), V(39), V(13) }, + { V( 0), V( 65), V( 141), V(41), V(34) }, + { V( 0), V( 53), V( 127), V(56), V(14) } }, + { { V( 4), V( 73), V( 132), V(46), V(31) }, //Unopposed + { V( 1), V( 64), V( 143), V(26), V(13) }, + { V( 1), V( 47), V( 110), V(44), V(24) }, + { V( 0), V( 72), V( 127), V(50), V(31) } }, + { { V( 0), V( 0), V( 79), V(23), V( 1) }, //BlockedByPawn + { V( 0), V( 0), V( 148), V(27), V( 2) }, + { V( 0), V( 0), V( 161), V(16), V( 1) }, + { V( 0), V( 0), V( 171), V(22), V(15) } }, + { { V(22), V( 45), V( 104), V(62), V( 6) }, //Unblocked + { V(31), V( 30), V( 99), V(39), V(19) }, + { V(23), V( 29), V( 96), V(41), V(15) }, + { V(21), V( 23), V( 116), V(41), V(15) } } + }, +#endif +#ifdef RACE + {}, +#endif +#ifdef RELAY + { + { { V( 0), V(-290), V(-274), V(57), V(41) }, //BlockedByKing + { V( 0), V( 60), V( 144), V(39), V(13) }, + { V( 0), V( 65), V( 141), V(41), V(34) }, + { V( 0), V( 53), V( 127), V(56), V(14) } }, + { { V( 4), V( 73), V( 132), V(46), V(31) }, //Unopposed + { V( 1), V( 64), V( 143), V(26), V(13) }, + { V( 1), V( 47), V( 110), V(44), V(24) }, + { V( 0), V( 72), V( 127), V(50), V(31) } }, + { { V( 0), V( 0), V( 79), V(23), V( 1) }, //BlockedByPawn + { V( 0), V( 0), V( 148), V(27), V( 2) }, + { V( 0), V( 0), V( 161), V(16), V( 1) }, + { V( 0), V( 0), V( 171), V(22), V(15) } }, + { { V(22), V( 45), V( 104), V(62), V( 6) }, //Unblocked + { V(31), V( 30), V( 99), V(39), V(19) }, + { V(23), V( 29), V( 96), V(41), V(15) }, + { V(21), V( 23), V( 116), V(41), V(15) } } + }, +#endif +#ifdef THREECHECK + { { { V( 0), V(-290), V(-274), V(57), V(41) }, //BlockedByKing { V( 0), V( 60), V( 144), V(39), V(13) }, { V( 0), V( 65), V( 141), V(41), V(34) }, @@ -261,12 +424,18 @@ namespace { { V(31), V( 30), V( 99), V(39), V(19) }, { V(23), V( 29), V( 96), V(41), V(15) }, { V(21), V( 23), V( 116), V(41), V(15) } } + }, +#endif }; // Max bonus for king safety. Corresponds to start position with all the pawns // in front of the king and no enemy pawn on the horizon. const Value MaxSafetyBonus = V(258); +#ifdef HORDE + const Score ImbalancedHorde = S(30, 30); +#endif + #undef S #undef V @@ -296,6 +465,18 @@ namespace { e->pawnsOnSquares[Us][BLACK] = popcount(ourPawns & DarkSquares); e->pawnsOnSquares[Us][WHITE] = pos.count(Us) - e->pawnsOnSquares[Us][BLACK]; +#ifdef HORDE + if (pos.is_horde() && pos.is_horde_color(Us)) + { + int l = 0, m = 0, r = popcount(ourPawns & FileBB[FILE_A]); + for (File f1 = FILE_A; f1 <= FILE_H; ++f1) + { + l = m; m = r; r = f1 < FILE_H ? popcount(ourPawns & FileBB[f1 + 1]) : 0; + score -= ImbalancedHorde * m / (1 + l * r); + } + } +#endif + // Loop through all pawns of the current color and score each pawn while ((s = *pl++) != SQ_NONE) { @@ -391,7 +572,7 @@ void init() { { 0, 8, 19, 13, 71, 94, 169, 324 }, #endif #ifdef ATOMIC - { 0, 8, 19, 13, 71, 94, 169, 324 }, + { 0,18, 11, 14, 82,109, 170, 315 }, #endif #ifdef CRAZYHOUSE { 0, 8, 19, 13, 71, 94, 169, 324 }, @@ -476,7 +657,7 @@ Value Entry::shelter_storm(const Position& pos, Square ksq) { int d = std::min(f, FILE_H - f); safety -= ShelterWeakness[pos.variant()][d][rkUs] - + StormDanger + + StormDanger[pos.variant()] [f == file_of(ksq) && rkThem == relative_rank(Us, ksq) + 1 ? BlockedByKing : rkUs == RANK_1 ? Unopposed : rkThem == rkUs + 1 ? BlockedByPawn : Unblocked] diff --git a/src/position.cpp b/src/position.cpp index 96ecfc92..65366168 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -516,14 +516,6 @@ void Position::set_state(StateInfo* si) const { si->nonPawnMaterial[WHITE] = si->nonPawnMaterial[BLACK] = VALUE_ZERO; si->psq = SCORE_ZERO; set_check_info(si); -#ifdef RACE - if (is_race()) - { - Rank r = rank_of(square(sideToMove)); - si->checkersBB = r == RANK_8 ? 0 : Rank8BB & square(~sideToMove); - } - else -#endif #ifdef HORDE if (is_horde() && is_horde_color(sideToMove)) si->checkersBB = 0; @@ -1349,7 +1341,10 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) { // Move the piece. The tricky Chess960 castling is handled earlier #ifdef CRAZYHOUSE if (type_of(m) == DROP) + { drop_piece(pc, to); + st->materialKey ^= Zobrist::psq[pc][pieceCount[pc]-1]; + } else #endif if (type_of(m) != CASTLING) @@ -1442,11 +1437,6 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) { // Update the key with the final value st->key = k; -#ifdef RACE - if (is_race()) - st->checkersBB = Rank8BB & square(us); - else -#endif // Calculate checkers bitboard (if move gives check) st->checkersBB = givesCheck ? attackers_to(square(them)) & pieces(us) : 0; @@ -1740,7 +1730,7 @@ bool Position::see_ge(Move m, Value v) const { #endif #ifdef THREECHECK - if (is_three_check() && gives_check(m)) + if (is_three_check() && color_of(moved_piece(m)) == sideToMove && gives_check(m)) return true; #endif diff --git a/src/position.h b/src/position.h index 9edd68bc..194d7a7a 100644 --- a/src/position.h +++ b/src/position.h @@ -186,6 +186,7 @@ class Position { #endif #ifdef CRAZYHOUSE bool is_house() const; + template int count_in_hand(Color c) const; int count_in_hand(Color c, PieceType pt) const; void add_to_hand(Color c, PieceType pt); void remove_from_hand(Color c, PieceType pt); @@ -443,9 +444,6 @@ inline Bitboard Position::attackers_to(Square s) const { inline Bitboard Position::checkers() const { #ifdef ANTI assert(!is_anti() || !st->checkersBB); -#endif -#ifdef RACE - assert(!is_race() || !(st->checkersBB - square(~sideToMove))); #endif return st->checkersBB; } @@ -640,6 +638,9 @@ inline bool Position::is_house() const { return var == CRAZYHOUSE_VARIANT; } +template inline int Position::count_in_hand(Color c) const { + return pieceCountInHand[c][Pt]; +} inline int Position::count_in_hand(Color c, PieceType pt) const { return pieceCountInHand[c][pt]; } diff --git a/src/psqt.cpp b/src/psqt.cpp index d195e0e4..6a7166c5 100644 --- a/src/psqt.cpp +++ b/src/psqt.cpp @@ -252,13 +252,13 @@ const Score Bonus[VARIANT_NB][PIECE_TYPE_NB][RANK_NB][int(FILE_NB) / 2] = { { { }, { // Pawn - { S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0) }, - { S(-11, 7), S( 6,-4), S( 7, 8), S( 3,-2) }, - { S(-18,-4), S( -2,-5), S( 19, 5), S(24, 4) }, - { S(-17, 3), S( -9, 3), S( 20,-8), S(35,-3) }, - { S( -6, 8), S( 5, 9), S( 3, 7), S(21,-6) }, - { S( -6, 8), S( -8,-5), S( -6, 2), S(-2, 4) }, - { S( -4, 3), S( 20,-9), S( -8, 1), S(-4,18) } + { S( 0, 0), S( 0, 0), S( 0, 0), S( 0, 0) }, + { S( -9,12), S( 7, -4), S( 12, 6), S( 6,-3) }, + { S(-18,-6), S( 0,-10), S( 18, 4), S(23, 6) }, + { S(-15,-1), S( -7, 1), S( 21,-7), S(36,-4) }, + { S(-10, 7), S( 4, 7), S( 8, 9), S(26,-4) }, + { S(-13,10), S( -5, -3), S( -3, 2), S( 1, 7) }, + { S( -2,-1), S( 16, -5), S( -6, 2), S(-3,28) } }, { // Knight { S(-143, -97), S(-96,-82), S(-80,-46), S(-73,-14) }, @@ -325,14 +325,14 @@ const Score Bonus[VARIANT_NB][PIECE_TYPE_NB][RANK_NB][int(FILE_NB) / 2] = { { S( -4, 3), S( 20,-9), S( -8, 1), S(-4,18) } }, { // Knight - { S(-143, -97), S(-96,-82), S(-80,-46), S(-73,-14) }, - { S( -83, -69), S(-43,-55), S(-21,-17), S(-10, 9) }, - { S( -71, -50), S(-22,-39), S( 0, -8), S( 9, 28) }, - { S( -25, -41), S( 18,-25), S( 43, 7), S( 47, 38) }, - { S( -26, -46), S( 16,-25), S( 38, 2), S( 50, 41) }, - { S( -11, -55), S( 37,-38), S( 56, -8), S( 71, 27) }, - { S( -62, -64), S(-17,-50), S( 5,-24), S( 14, 13) }, - { S(-195,-110), S(-66,-90), S(-42,-50), S(-29,-13) } + { S(-132,-159), S(-309, -68), S(-117, -37), S( -79,-20) }, + { S( -91,-153), S( -24, -78), S( -80, -4), S(-129, 62) }, + { S( -28, -18), S( -59, -11), S( -17, 39), S( -10,-50) }, + { S( -17, -56), S( 85, -20), S( 75, 28), S( 95, 20) }, + { S( 91, -53), S( 38, -60), S( -7, 60), S( 115, 90) }, + { S( 20, -3), S( 88,-102), S( 33, -71), S( 57, 2) }, + { S(-119, -48), S( -17, -13), S( -15, -56), S( 24,-60) }, + { S(-222,-103), S( -84, -68), S(-126,-112), S( 73, 38) } }, { // Bishop { S(-54,-68), S(-23,-40), S(-35,-46), S(-44,-28) }, @@ -429,14 +429,14 @@ const Score Bonus[VARIANT_NB][PIECE_TYPE_NB][RANK_NB][int(FILE_NB) / 2] = { { S(-1,-75), S(-4,-54), S(-1,-44), S( 0,-30) } }, { // King - { S(230, 28), S(390,-35), S(397,146), S(352, 83) }, - { S(243, 37), S(274, 74), S(348,229), S(296,393) }, - { S(236, 25), S(305,105), S(255, 95), S(254,188) }, - { S(246,175), S(267,245), S(180,249), S( 0, 0) }, - { S(151,120), S(199,207), S(156,231), S( 0, 0) }, - { S(177,107), S(189,230), S(141,172), S(211,251) }, - { S( 26, 36), S(164,145), S(102,139), S(-42,133) }, - { S(147, 2), S(186, 7), S( 49, 79), S( 48, 50) } + { S(205, 67), S(403, -6), S(394,115), S(518,102) }, + { S(214, 63), S(308,116), S(333,169), S(245,255) }, + { S(277, -2), S(261,141), S(286, 69), S(189,207) }, + { S(280,164), S(298,233), S(126,266), S(-45, 55) }, + { S(134, 89), S(255,225), S(152,245), S( 28,-67) }, + { S(212,156), S(191,171), S( 59,160), S(153,248) }, + { S( 75,-25), S(203,134), S(168,141), S(-76,133) }, + { S(137, 49), S(187, 1), S( 60, 26), S(-25, 56) } } }, #endif diff --git a/src/search.cpp b/src/search.cpp index 1d11b2fe..da8302b5 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -1337,10 +1337,11 @@ namespace { && cm_ok) update_cm_stats(ss-1, pos.piece_on(prevSq), prevSq, stat_bonus(depth)); - tte->save(posKey, value_to_tt(bestValue, ss->ply), - bestValue >= beta ? BOUND_LOWER : - PvNode && bestMove ? BOUND_EXACT : BOUND_UPPER, - depth, bestMove, ss->staticEval, TT.generation()); + if(!excludedMove) + tte->save(posKey, value_to_tt(bestValue, ss->ply), + bestValue >= beta ? BOUND_LOWER : + PvNode && bestMove ? BOUND_EXACT : BOUND_UPPER, + depth, bestMove, ss->staticEval, TT.generation()); assert(bestValue > -VALUE_INFINITE && bestValue < VALUE_INFINITE); @@ -1466,11 +1467,6 @@ namespace { { assert(is_ok(move)); -#ifdef RACE - if (pos.is_race()) - givesCheck = type_of(pos.piece_on(from_sq(move))) == KING && rank_of(to_sq(move)) == RANK_8; - else -#endif givesCheck = type_of(move) == NORMAL && !pos.discovered_check_candidates() #ifdef ATOMIC && !pos.is_atomic() @@ -1484,6 +1480,9 @@ namespace { // Futility pruning if ( !InCheck && !givesCheck +#ifdef RACE + && !(pos.is_race() && type_of(pos.piece_on(from_sq(move))) == KING && rank_of(to_sq(move)) == RANK_8) +#endif && futilityBase > -VALUE_KNOWN_WIN && !pos.advanced_pawn_push(move)) { diff --git a/src/types.h b/src/types.h index 02b552f0..361105db 100644 --- a/src/types.h +++ b/src/types.h @@ -309,7 +309,7 @@ enum Value : int { KingValueMgAnti = -23, KingValueEgAnti = 231, #endif #ifdef ATOMIC - PawnValueMgAtomic = 314, PawnValueEgAtomic = 447, + PawnValueMgAtomic = 300, PawnValueEgAtomic = 437, KnightValueMgAtomic = 474, KnightValueEgAtomic = 755, BishopValueMgAtomic = 652, BishopValueEgAtomic = 762, RookValueMgAtomic = 899, RookValueEgAtomic = 1199, @@ -351,11 +351,11 @@ enum Value : int { QueenValueMgRace = 1848, QueenValueEgRace = 2141, #endif #ifdef THREECHECK - PawnValueMgThreeCheck = 181, PawnValueEgThreeCheck = 245, - KnightValueMgThreeCheck = 691, KnightValueEgThreeCheck = 850, - BishopValueMgThreeCheck = 829, BishopValueEgThreeCheck = 845, - RookValueMgThreeCheck = 1222, RookValueEgThreeCheck = 1386, - QueenValueMgThreeCheck = 2274, QueenValueEgThreeCheck = 2573, + PawnValueMgThreeCheck = 153, PawnValueEgThreeCheck = 220, + KnightValueMgThreeCheck = 638, KnightValueEgThreeCheck = 811, + BishopValueMgThreeCheck = 690, BishopValueEgThreeCheck = 849, + RookValueMgThreeCheck = 1121, RookValueEgThreeCheck = 1438, + QueenValueMgThreeCheck = 2214, QueenValueEgThreeCheck = 2342, #endif MidgameLimit = 15258, EndgameLimit = 3915