From: Fabian Fichter Date: Sun, 28 Jun 2020 13:40:37 +0000 (+0200) Subject: Merge official-stockfish/master X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=f38d3fb87f525a40e97080544704571152c81c39;p=fairystockfish.git Merge official-stockfish/master No functional change. --- f38d3fb87f525a40e97080544704571152c81c39 diff --cc src/endgame.cpp index f29292e,16c072b..4cc1340 --- a/src/endgame.cpp +++ b/src/endgame.cpp @@@ -86,17 -73,10 +86,17 @@@ namespace assert(pos.count(strongSide) == 1); - if (file_of(pos.square(strongSide)) >= FILE_E) - sq = flip_file(sq); + if (file_of(pos.square(strongSide)) > pos.max_file() / 2) - sq = Square(sq + pos.max_file() - 2 * file_of(sq)); // Mirror SQ_H1 -> SQ_A1 ++ sq = flip_file(sq, pos.max_file()); + - return relative_square(strongSide, sq, pos.max_rank()); ++ return strongSide == WHITE ? sq : flip_rank(sq, pos.max_rank()); + } - return strongSide == WHITE ? sq : flip_rank(sq); + // Map the square to an 8x8 board + Square map_to_standard_board(const Position& pos, Square s) { + File f = file_of(s) > pos.max_file() / 2 ? File(FILE_H - pos.max_file() + file_of(s)) : file_of(s); + Rank r = rank_of(s) > pos.max_rank() / 2 ? Rank(RANK_8 - pos.max_rank() + rank_of(s)) : rank_of(s); + return Square(r * 8 + f); } } // namespace diff --cc src/psqt.cpp index 9c44cd1,f6f5933..7797261 --- a/src/psqt.cpp +++ b/src/psqt.cpp @@@ -106,94 -103,19 +106,94 @@@ Score psq[PIECE_NB][SQUARE_NB + 1] // init() initializes piece-square tables: the white halves of the tables are // copied from Bonus[] adding the piece value, then the black halves of the // tables are initialized by flipping and changing the sign of the white scores. -void init() { +void init(const Variant* v) { - for (Piece pc = W_PAWN; pc <= W_KING; ++pc) + PieceType strongestPiece = NO_PIECE_TYPE; + for (PieceType pt : v->pieceTypes) + if (PieceValue[MG][pt] > PieceValue[MG][strongestPiece]) + strongestPiece = pt; + + Value maxPromotion = VALUE_ZERO; + for (PieceType pt : v->promotionPieceTypes) + maxPromotion = std::max(maxPromotion, PieceValue[EG][pt]); + + for (PieceType pt = PAWN; pt <= KING; ++pt) { + Piece pc = make_piece(WHITE, pt); + Score score = make_score(PieceValue[MG][pc], PieceValue[EG][pc]); - for (Square s = SQ_A1; s <= SQ_H8; ++s) + // Consider promotion types in pawn score + if (pt == PAWN) + score -= make_score(0, (QueenValueEg - maxPromotion) / 100); + + // Scale slider piece values with board size + const PieceInfo* pi = pieceMap.find(pt)->second; + bool isSlider = pi->sliderQuiet.size() || pi->sliderCapture.size() || pi->hopperQuiet.size() || pi->hopperCapture.size(); + bool isPawn = !isSlider && pi->stepsQuiet.size() && !std::any_of(pi->stepsQuiet.begin(), pi->stepsQuiet.end(), [](Direction d) { return d < SOUTH / 2; }); + bool isSlowLeaper = !isSlider && !std::any_of(pi->stepsQuiet.begin(), pi->stepsQuiet.end(), [](Direction d) { return dist(d) > 1; }); + + if (isSlider) + { + constexpr int lc = 5; + constexpr int rm = 5; + constexpr int r0 = rm + RANK_8; + int r1 = rm + (v->maxRank + v->maxFile) / 2; + int leaper = pi->stepsQuiet.size() + pi->stepsCapture.size(); + int slider = pi->sliderQuiet.size() + pi->sliderCapture.size() + pi->hopperQuiet.size() + pi->hopperCapture.size(); + score = make_score(mg_value(score) * (lc * leaper + r1 * slider) / (lc * leaper + r0 * slider), + eg_value(score) * (lc * leaper + r1 * slider) / (lc * leaper + r0 * slider)); + } + + // Increase leapers' value in makpong + if (v->makpongRule) + { + if (std::any_of(pi->stepsCapture.begin(), pi->stepsCapture.end(), [](Direction d) { return dist(d) > 1; }) + && !pi->lameLeaper) + score = make_score(mg_value(score) * 4200 / (3500 + mg_value(score)), + eg_value(score) * 4700 / (3500 + mg_value(score))); + } + + // For drop variants, halve the piece values + if (v->capturesToHand) + score = make_score(mg_value(score) * 3500 / (7000 + mg_value(score)), + eg_value(score) * 3500 / (7000 + eg_value(score))); + else if (!v->checking) + score = make_score(mg_value(score) * 2000 / (3500 + mg_value(score)), + eg_value(score) * 2200 / (3500 + eg_value(score))); + else if (v->twoBoards) + score = make_score(mg_value(score) * 7000 / (7000 + mg_value(score)), + eg_value(score) * 7000 / (7000 + eg_value(score))); + else if (v->checkCounting) + score = make_score(mg_value(score) * (40000 + mg_value(score)) / 41000, + eg_value(score) * (30000 + eg_value(score)) / 31000); + else if (pt == strongestPiece) + score += make_score(std::max(QueenValueMg - PieceValue[MG][pt], VALUE_ZERO) / 20, + std::max(QueenValueEg - PieceValue[EG][pt], VALUE_ZERO) / 20); + + // For antichess variants, use negative piece values + if ( v->extinctionValue == VALUE_MATE + && v->extinctionPieceTypes.find(ALL_PIECES) != v->extinctionPieceTypes.end()) + score = -make_score(mg_value(score) / 8, eg_value(score) / 8 / (1 + !pi->sliderCapture.size())); + + for (Square s = SQ_A1; s <= SQ_MAX; ++s) { - File f = map_to_queenside(file_of(s)); - psq[ pc][ s] = score + (type_of(pc) == PAWN ? PBonus[rank_of(s)][file_of(s)] - : Bonus[pc][rank_of(s)][f]); - psq[~pc][flip_rank(s)] = -psq[pc][s]; + File f = std::max(std::min(file_of(s), File(v->maxFile - file_of(s))), FILE_A); + Rank r = rank_of(s); + psq[ pc][ s] = score + ( pt == PAWN ? PBonus[std::min(r, RANK_8)][std::min(file_of(s), FILE_H)] + : pt == KING ? KingBonus[std::min(r, RANK_8)][std::min(f, FILE_D)] * (1 + v->capturesToHand) + : pt <= QUEEN ? Bonus[pc][std::min(r, RANK_8)][std::min(f, FILE_D)] + : pt == HORSE ? Bonus[KNIGHT][std::min(r, RANK_8)][std::min(f, FILE_D)] + : isSlider ? make_score(5, 5) * (2 * f + std::max(std::min(r, Rank(v->maxRank - r)), RANK_1) - v->maxFile - 1) + : isPawn ? make_score(5, 5) * (2 * f - v->maxFile) + : make_score(10, 10) * (1 + isSlowLeaper) * (f + std::max(std::min(r, Rank(v->maxRank - r)), RANK_1) - v->maxFile / 2)); + if (pt == SOLDIER && r < v->soldierPromotionRank) + psq[pc][s] -= score * (v->soldierPromotionRank - r) / (4 + f); - psq[~pc][rank_of(s) <= v->maxRank ? relative_square(BLACK, s, v->maxRank) : s] = -psq[pc][s]; ++ psq[~pc][rank_of(s) <= v->maxRank ? flip_rank(s, v->maxRank) : s] = -psq[pc][s]; } + // pieces in pocket + psq[ pc][SQ_NONE] = score + make_score(45, 10); + psq[~pc][SQ_NONE] = -psq[pc][SQ_NONE]; } } diff --cc src/syzygy/tbprobe.cpp index 90c53aa,6f36945..c20beb1 --- a/src/syzygy/tbprobe.cpp +++ b/src/syzygy/tbprobe.cpp @@@ -66,11 -66,9 +66,10 @@@ enum TBType { KEY, WDL, DTZ }; // Used enum TBFlag { STM = 1, Mapped = 2, WinPlies = 4, LossPlies = 8, Wide = 16, SingleValue = 128 }; inline WDLScore operator-(WDLScore d) { return WDLScore(-int(d)); } - inline Square operator^=(Square& s, int i) { return s = Square(int(s) ^ i); } inline Square operator^(Square s, int i) { return Square(int(s) ^ i); } -const std::string PieceToChar = " PNBRQK pnbrqk"; +const std::string PieceToChar( " PNBRQ" + std::string(KING - QUEEN - 1, ' ') + "K" + std::string(PIECE_TYPE_NB - KING - 1, ' ') + + " pnbrq" + std::string(KING - QUEEN - 1, ' ') + "k" + std::string(PIECE_TYPE_NB - KING - 1, ' ')); int MapPawns[SQUARE_NB]; int MapB1H1H7[SQUARE_NB]; diff --cc src/types.h index 3d8dd05,d4937fd..6b52fc0 --- a/src/types.h +++ b/src/types.h @@@ -647,12 -358,12 +647,12 @@@ constexpr Color operator~(Color c) return Color(c ^ BLACK); // Toggle color } - constexpr Square operator~(Square s) { - #ifdef LARGEBOARDS - return Square(s - FILE_NB * (s / FILE_NB * 2 - RANK_MAX)); // Vertical flip SQ_A1 -> SQ_A10 - #else - return Square(s ^ SQ_A8); // Vertical flip SQ_A1 -> SQ_A8 - #endif -constexpr Square flip_rank(Square s) { - return Square(s ^ SQ_A8); ++constexpr Square flip_rank(Square s, Rank maxRank = RANK_8) { ++ return Square(s + NORTH * (maxRank - 2 * (s / NORTH))); + } + -constexpr Square flip_file(Square s) { - return Square(s ^ SQ_H1); ++constexpr Square flip_file(Square s, File maxFile = FILE_H) { ++ return Square(s + maxFile - 2 * (s % NORTH)); } constexpr Piece operator~(Piece pc) {