Rev 154 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 154 | Rev 169 | ||
|---|---|---|---|
| Line 4... | Line 4... | ||
| 4 |   Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad | 
            4 |   Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad | 
          
| 5 |   Copyright (C) 2015- | 
            5 |   Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad | 
          
| 6 | 6 | ||
| 7 |   Stockfish is free software: you can redistribute it and/or modify | 
            7 |   Stockfish is free software: you can redistribute it and/or modify | 
          
| 8 |   it under the terms of the GNU General Public License as published by | 
            8 |   it under the terms of the GNU General Public License as published by | 
          
| 9 |   the Free Software Foundation, either version 3 of the License, or | 
            9 |   the Free Software Foundation, either version 3 of the License, or | 
          
| 10 |   (at your option) any later version. | 
            10 |   (at your option) any later version. | 
          
| Line 33... | Line 33... | ||
| 33 | 33 | ||
| 34 | const int QuadraticOurs[][PIECE_TYPE_NB] = {  | 
            34 | const int QuadraticOurs[][PIECE_TYPE_NB] = {  | 
          
| 35 |     //            OUR PIECES | 
            35 |     //            OUR PIECES | 
          
| 36 |     // pair pawn knight bishop rook queen | 
            36 |     // pair pawn knight bishop rook queen | 
          
| 37 | {1667 }, // Bishop pair  | 
            37 | {1667 }, // Bishop pair  | 
          
| 38 | { 40,  | 
            38 | { 40, 0 }, // Pawn  | 
          
| 39 | { 32, 255, -3 }, // Knight OUR PIECES  | 
            39 | { 32, 255, -3 }, // Knight OUR PIECES  | 
          
| 40 | { 0, 104, 4, 0 }, // Bishop  | 
            40 | { 0, 104, 4, 0 }, // Bishop  | 
          
| 41 | { -26, -2, 47, 105, -149 }, // Rook  | 
            41 | { -26, -2, 47, 105, -149 }, // Rook  | 
          
| 42 | {-  | 
            42 | {-189, 24, 117, 133, -134, -10 } // Queen  | 
          
| 43 | };  | 
            43 | };  | 
          
| 44 | 44 | ||
| 45 | const int QuadraticTheirs[][PIECE_TYPE_NB] = {  | 
            45 | const int QuadraticTheirs[][PIECE_TYPE_NB] = {  | 
          
| 46 |     //           THEIR PIECES | 
            46 |     //           THEIR PIECES | 
          
| 47 |     // pair pawn knight bishop rook queen | 
            47 |     // pair pawn knight bishop rook queen | 
          
| 48 | { 0 }, // Bishop pair  | 
            48 | { 0 }, // Bishop pair  | 
          
| 49 | { 36, 0 }, // Pawn  | 
            49 | { 36, 0 }, // Pawn  | 
          
| 50 | { 9, 63, 0 }, // Knight OUR PIECES  | 
            50 | { 9, 63, 0 }, // Knight OUR PIECES  | 
          
| 51 | { 59, 65, 42, 0 }, // Bishop  | 
            51 | { 59, 65, 42, 0 }, // Bishop  | 
          
| 52 | { 46, 39, 24, -24, 0 }, // Rook  | 
            52 | { 46, 39, 24, -24, 0 }, // Rook  | 
          
| 53 | {  | 
            53 | { 97, 100, -42, 137, 268, 0 } // Queen  | 
          
| 54 | };  | 
            54 | };  | 
          
| 55 | 55 | ||
| 56 |   // Endgame evaluation and scaling functions are accessed directly and not through | 
            56 |   // Endgame evaluation and scaling functions are accessed directly and not through | 
          
| 57 |   // the function maps because they correspond to more than one material hash key. | 
            57 |   // the function maps because they correspond to more than one material hash key. | 
          
| 58 | Endgame<KXK> EvaluateKXK[] = { Endgame<KXK>(WHITE), Endgame<KXK>(BLACK) };  | 
            58 | Endgame<KXK> EvaluateKXK[] = { Endgame<KXK>(WHITE), Endgame<KXK>(BLACK) };  | 
          
| Line 89... | Line 89... | ||
| 89 | 89 | ||
| 90 | const Color Them = (Us == WHITE ? BLACK : WHITE);  | 
            90 | const Color Them = (Us == WHITE ? BLACK : WHITE);  | 
          
| 91 | 91 | ||
| 92 | int bonus = 0;  | 
            92 | int bonus = 0;  | 
          
| 93 | 93 | ||
| 94 |     // Second-degree polynomial material  | 
            94 |     // Second-degree polynomial material imbalance, by Tord Romstad | 
          
| 95 | for (int pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; ++pt1)  | 
            95 | for (int pt1 = NO_PIECE_TYPE; pt1 <= QUEEN; ++pt1)  | 
          
| 96 |     { | 
            96 |     { | 
          
| 97 | if (!pieceCount[Us][pt1])  | 
            97 | if (!pieceCount[Us][pt1])  | 
          
| 98 | continue;  | 
            98 | continue;  | 
          
| 99 | 99 | ||
| Line 127... | Line 127... | ||
| 127 | return e;  | 
            127 | return e;  | 
          
| 128 | 128 | ||
| 129 | std::memset(e, 0, sizeof(Entry));  | 
            129 | std::memset(e, 0, sizeof(Entry));  | 
          
| 130 | e->key = key;  | 
            130 | e->key = key;  | 
          
| 131 | e->factor[WHITE] = e->factor[BLACK] = (uint8_t)SCALE_FACTOR_NORMAL;  | 
            131 | e->factor[WHITE] = e->factor[BLACK] = (uint8_t)SCALE_FACTOR_NORMAL;  | 
          
| - | 132 | ||
| - | 133 | Value npm_w = pos.non_pawn_material(WHITE);  | 
          |
| 132 | 
  | 
            134 | Value npm_b = pos.non_pawn_material(BLACK);  | 
          
| - | 135 | Value npm = std::max(EndgameLimit, std::min(npm_w + npm_b, MidgameLimit));  | 
          |
| - | 136 | ||
| - | 137 |   // Map total non-pawn material into [PHASE_ENDGAME, PHASE_MIDGAME] | 
          |
| - | 138 | e->gamePhase = Phase(((npm - EndgameLimit) * PHASE_MIDGAME) / (MidgameLimit - EndgameLimit));  | 
          |
| 133 | 139 | ||
| 134 |   // Let's look if we have a specialized evaluation function for this particular | 
            140 |   // Let's look if we have a specialized evaluation function for this particular | 
          
| 135 |   // material configuration. Firstly we look for a fixed configuration one, then | 
            141 |   // material configuration. Firstly we look for a fixed configuration one, then | 
          
| 136 |   // for a generic one if the previous search failed. | 
            142 |   // for a generic one if the previous search failed. | 
          
| 137 | if ((e->evaluationFunction = pos.this_thread()->endgames.probe<Value>(key)) != nullptr)  | 
            143 | if ((e->evaluationFunction = pos.this_thread()->endgames.probe<Value>(key)) != nullptr)  | 
          
| Line 148... | Line 154... | ||
| 148 |   // configuration. Is there a suitable specialized scaling function? | 
            154 |   // configuration. Is there a suitable specialized scaling function? | 
          
| 149 | EndgameBase<ScaleFactor>* sf;  | 
            155 | EndgameBase<ScaleFactor>* sf;  | 
          
| 150 | 156 | ||
| 151 | if ((sf = pos.this_thread()->endgames.probe<ScaleFactor>(key)) != nullptr)  | 
            157 | if ((sf = pos.this_thread()->endgames.probe<ScaleFactor>(key)) != nullptr)  | 
          
| 152 |   { | 
            158 |   { | 
          
| 153 | e->scalingFunction[sf->  | 
            159 | e->scalingFunction[sf->strongSide] = sf; // Only strong color assigned  | 
          
| 154 | return e;  | 
            160 | return e;  | 
          
| 155 |   } | 
            161 |   } | 
          
| 156 | 162 | ||
| 157 |   // We didn't find any specialized scaling function, so fall back on generic | 
            163 |   // We didn't find any specialized scaling function, so fall back on generic | 
          
| 158 |   // ones that refer to more than one material distribution. Note that in this | 
            164 |   // ones that refer to more than one material distribution. Note that in this | 
          
| Line 163... | Line 169... | ||
| 163 | e->scalingFunction[c] = &ScaleKBPsK[c];  | 
            169 | e->scalingFunction[c] = &ScaleKBPsK[c];  | 
          
| 164 | 170 | ||
| 165 | else if (is_KQKRPs(pos, c))  | 
            171 | else if (is_KQKRPs(pos, c))  | 
          
| 166 | e->scalingFunction[c] = &ScaleKQKRPs[c];  | 
            172 | e->scalingFunction[c] = &ScaleKQKRPs[c];  | 
          
| 167 |   } | 
            173 |   } | 
          
| 168 | - | ||
| 169 | Value npm_w = pos.non_pawn_material(WHITE);  | 
            - | |
| 170 | Value npm_b = pos.non_pawn_material(BLACK);  | 
            - | |
| 171 | 174 | ||
| 172 | if (npm_w + npm_b == VALUE_ZERO && pos.pieces(PAWN)) // Only pawns on the board  | 
            175 | if (npm_w + npm_b == VALUE_ZERO && pos.pieces(PAWN)) // Only pawns on the board  | 
          
| 173 |   { | 
            176 |   { | 
          
| 174 | if (!pos.count<PAWN>(BLACK))  | 
            177 | if (!pos.count<PAWN>(BLACK))  | 
          
| 175 |       { | 
            178 |       { |