"Fossies" - the Fresh Open Source Software Archive

Member "stockfish-11-linux/src/material.h" (18 Jan 2020, 2984 Bytes) of package /linux/privat/stockfish-11-linux.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "material.h": 9-linux_vs_10-linux.

    1 /*
    2   Stockfish, a UCI chess playing engine derived from Glaurung 2.1
    3   Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
    4   Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
    5   Copyright (C) 2015-2020 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
    6 
    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
    9   the Free Software Foundation, either version 3 of the License, or
   10   (at your option) any later version.
   11 
   12   Stockfish is distributed in the hope that it will be useful,
   13   but WITHOUT ANY WARRANTY; without even the implied warranty of
   14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15   GNU General Public License for more details.
   16 
   17   You should have received a copy of the GNU General Public License
   18   along with this program.  If not, see <http://www.gnu.org/licenses/>.
   19 */
   20 
   21 #ifndef MATERIAL_H_INCLUDED
   22 #define MATERIAL_H_INCLUDED
   23 
   24 #include "endgame.h"
   25 #include "misc.h"
   26 #include "position.h"
   27 #include "types.h"
   28 
   29 namespace Material {
   30 
   31 /// Material::Entry contains various information about a material configuration.
   32 /// It contains a material imbalance evaluation, a function pointer to a special
   33 /// endgame evaluation function (which in most cases is NULL, meaning that the
   34 /// standard evaluation function will be used), and scale factors.
   35 ///
   36 /// The scale factors are used to scale the evaluation score up or down. For
   37 /// instance, in KRB vs KR endgames, the score is scaled down by a factor of 4,
   38 /// which will result in scores of absolute value less than one pawn.
   39 
   40 struct Entry {
   41 
   42   Score imbalance() const { return make_score(value, value); }
   43   Phase game_phase() const { return gamePhase; }
   44   bool specialized_eval_exists() const { return evaluationFunction != nullptr; }
   45   Value evaluate(const Position& pos) const { return (*evaluationFunction)(pos); }
   46 
   47   // scale_factor takes a position and a color as input and returns a scale factor
   48   // for the given color. We have to provide the position in addition to the color
   49   // because the scale factor may also be a function which should be applied to
   50   // the position. For instance, in KBP vs K endgames, the scaling function looks
   51   // for rook pawns and wrong-colored bishops.
   52   ScaleFactor scale_factor(const Position& pos, Color c) const {
   53     ScaleFactor sf = scalingFunction[c] ? (*scalingFunction[c])(pos)
   54                                         :  SCALE_FACTOR_NONE;
   55     return sf != SCALE_FACTOR_NONE ? sf : ScaleFactor(factor[c]);
   56   }
   57 
   58   Key key;
   59   const EndgameBase<Value>* evaluationFunction;
   60   const EndgameBase<ScaleFactor>* scalingFunction[COLOR_NB]; // Could be one for each
   61                                                              // side (e.g. KPKP, KBPsK)
   62   int16_t value;
   63   uint8_t factor[COLOR_NB];
   64   Phase gamePhase;
   65 };
   66 
   67 typedef HashTable<Entry, 8192> Table;
   68 
   69 Entry* probe(const Position& pos);
   70 
   71 } // namespace Material
   72 
   73 #endif // #ifndef MATERIAL_H_INCLUDED