Skip to content
Newer
Older
100644 121 lines (91 sloc) 3.68 KB
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
1 /*
5dc2312 @mcostalba Update copyright info
authored Oct 19, 2008
2 Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3 Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
8307da0 @mcostalba Update copyright year to 2012
authored Dec 30, 2011
4 Copyright (C) 2008-2012 Marco Costalba, Joona Kiiski, Tord Romstad
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
5
5dc2312 @mcostalba Update copyright info
authored Oct 19, 2008
6 Stockfish is free software: you can redistribute it and/or modify
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
539051b @mcostalba Big trailing whitespace cleanup part 2
authored Jan 7, 2009
10
5dc2312 @mcostalba Update copyright info
authored Oct 19, 2008
11 Stockfish is distributed in the hope that it will be useful,
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
539051b @mcostalba Big trailing whitespace cleanup part 2
authored Jan 7, 2009
15
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #if !defined(MATERIAL_H_INCLUDED)
21 #define MATERIAL_H_INCLUDED
22
23 #include "endgame.h"
32c5040 @mcostalba Use std::vector to implement HashTable
authored Mar 31, 2012
24 #include "misc.h"
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
25 #include "position.h"
7a84b8c @mcostalba Sync material.h with pawns.h
authored Apr 11, 2011
26 #include "types.h"
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
27
08c464c @mcostalba Increase MaterialTableSize 8 times
authored Apr 11, 2011
28 const int MaterialTableSize = 8192;
7b721b3 @mcostalba Prefetch pawn hash key
authored Aug 21, 2010
29
f25582d @mcostalba Remove duplicated enum Phase definition
authored Jun 29, 2011
30 /// Game phase
31 enum Phase {
32 PHASE_ENDGAME = 0,
33 PHASE_MIDGAME = 128
34 };
35
36
304deb5 @mcostalba Rename Materials and Pawns hash stuff
authored Mar 31, 2012
37 /// MaterialEntry is a class which contains various information about a
6e8bd8b @mcostalba Final touches to material.cpp
authored Nov 1, 2008
38 /// material configuration. It contains a material balance evaluation,
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
39 /// a function pointer to a special endgame evaluation function (which in
40 /// most cases is NULL, meaning that the standard evaluation function will
41 /// be used), and "scale factors" for black and white.
42 ///
43 /// The scale factors are used to scale the evaluation score up or down.
44 /// For instance, in KRB vs KR endgames, the score is scaled down by a factor
45 /// of 4, which will result in scores of absolute value less than one pawn.
46
304deb5 @mcostalba Rename Materials and Pawns hash stuff
authored Mar 31, 2012
47 class MaterialEntry {
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
48
32c5040 @mcostalba Use std::vector to implement HashTable
authored Mar 31, 2012
49 friend struct MaterialTable;
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
50
51 public:
4626ec2 @mcostalba Convert MaterialInfo and PawnInfo to use Score
authored Nov 7, 2009
52 Score material_value() const;
6e8bd8b @mcostalba Final touches to material.cpp
authored Nov 1, 2008
53 ScaleFactor scale_factor(const Position& pos, Color c) const;
31d4f0b @mcostalba Merge space weigth evaluation fromGlaurung 2.2
authored Dec 21, 2008
54 int space_weight() const;
71e852e @mcostalba Move game phase computation to MaterialInfo
authored Nov 13, 2009
55 Phase game_phase() const;
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
56 bool specialized_eval_exists() const;
6e8bd8b @mcostalba Final touches to material.cpp
authored Nov 1, 2008
57 Value evaluate(const Position& pos) const;
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
58
59 private:
60 Key key;
044ad59 @mcostalba Add Tord's polynomial material balance
authored Jul 20, 2009
61 int16_t value;
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
62 uint8_t factor[2];
b5d5646 @mcostalba Move EndgameFunctions to endgame.cpp
authored Apr 11, 2011
63 EndgameBase<Value>* evaluationFunction;
64 EndgameBase<ScaleFactor>* scalingFunction[2];
b870f5a @mcostalba Silence a good bunch of Intel warnings
authored Mar 15, 2009
65 int spaceWeight;
71e852e @mcostalba Move game phase computation to MaterialInfo
authored Nov 13, 2009
66 Phase gamePhase;
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
67 };
68
7a84b8c @mcostalba Sync material.h with pawns.h
authored Apr 11, 2011
69
304deb5 @mcostalba Rename Materials and Pawns hash stuff
authored Mar 31, 2012
70 /// The MaterialTable class represents a material hash table. The most important
71 /// method is probe(), which returns a pointer to a MaterialEntry object.
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
72
32c5040 @mcostalba Use std::vector to implement HashTable
authored Mar 31, 2012
73 struct MaterialTable {
553655e @mcostalba Refactor Thread class
authored Mar 24, 2012
74
32c5040 @mcostalba Use std::vector to implement HashTable
authored Mar 31, 2012
75 MaterialEntry* probe(const Position& pos);
71e852e @mcostalba Move game phase computation to MaterialInfo
authored Nov 13, 2009
76 static Phase game_phase(const Position& pos);
32c5040 @mcostalba Use std::vector to implement HashTable
authored Mar 31, 2012
77 template<Color Us> static int imbalance(const int pieceCount[][8]);
7a84b8c @mcostalba Sync material.h with pawns.h
authored Apr 11, 2011
78
32c5040 @mcostalba Use std::vector to implement HashTable
authored Mar 31, 2012
79 HashTable<MaterialEntry, MaterialTableSize> entries;
80 Endgames endgames;
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
81 };
82
83
304deb5 @mcostalba Rename Materials and Pawns hash stuff
authored Mar 31, 2012
84 /// MaterialEntry::scale_factor takes a position and a color as input, and
d3c4618 @mcostalba Small code style in headers
authored May 20, 2009
85 /// returns a scale factor for the given color. We have to provide the
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
86 /// position in addition to the color, because the scale factor need not
6e8bd8b @mcostalba Final touches to material.cpp
authored Nov 1, 2008
87 /// to be a constant: It can also be a function which should be applied to
88 /// the position. For instance, in KBP vs K endgames, a scaling function
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
89 /// which checks for draws with rook pawns and wrong-colored bishops.
90
304deb5 @mcostalba Rename Materials and Pawns hash stuff
authored Mar 31, 2012
91 inline ScaleFactor MaterialEntry::scale_factor(const Position& pos, Color c) const {
6e8bd8b @mcostalba Final touches to material.cpp
authored Nov 1, 2008
92
7a84b8c @mcostalba Sync material.h with pawns.h
authored Apr 11, 2011
93 if (!scalingFunction[c])
94 return ScaleFactor(factor[c]);
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
95
98352a5 @mcostalba Use operator() instead of apply() in endgames
authored Dec 5, 2011
96 ScaleFactor sf = (*scalingFunction[c])(pos);
7a84b8c @mcostalba Sync material.h with pawns.h
authored Apr 11, 2011
97 return sf == SCALE_FACTOR_NONE ? ScaleFactor(factor[c]) : sf;
98 }
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
99
304deb5 @mcostalba Rename Materials and Pawns hash stuff
authored Mar 31, 2012
100 inline Value MaterialEntry::evaluate(const Position& pos) const {
98352a5 @mcostalba Use operator() instead of apply() in endgames
authored Dec 5, 2011
101 return (*evaluationFunction)(pos);
b5d5646 @mcostalba Move EndgameFunctions to endgame.cpp
authored Apr 11, 2011
102 }
103
304deb5 @mcostalba Rename Materials and Pawns hash stuff
authored Mar 31, 2012
104 inline Score MaterialEntry::material_value() const {
7a84b8c @mcostalba Sync material.h with pawns.h
authored Apr 11, 2011
105 return make_score(value, value);
106 }
31d4f0b @mcostalba Merge space weigth evaluation fromGlaurung 2.2
authored Dec 21, 2008
107
304deb5 @mcostalba Rename Materials and Pawns hash stuff
authored Mar 31, 2012
108 inline int MaterialEntry::space_weight() const {
31d4f0b @mcostalba Merge space weigth evaluation fromGlaurung 2.2
authored Dec 21, 2008
109 return spaceWeight;
110 }
111
304deb5 @mcostalba Rename Materials and Pawns hash stuff
authored Mar 31, 2012
112 inline Phase MaterialEntry::game_phase() const {
71e852e @mcostalba Move game phase computation to MaterialInfo
authored Nov 13, 2009
113 return gamePhase;
114 }
115
304deb5 @mcostalba Rename Materials and Pawns hash stuff
authored Mar 31, 2012
116 inline bool MaterialEntry::specialized_eval_exists() const {
bb751d6 @mcostalba Initial import of Glaurung 2.1
authored Sep 1, 2008
117 return evaluationFunction != NULL;
118 }
119
120 #endif // !defined(MATERIAL_H_INCLUDED)
Something went wrong with that request. Please try again.