]> git.sesse.net Git - stockfish/blob - src/value.h
Cleanup read_weights() in evaluate.cpp
[stockfish] / src / value.h
1 /*
2   Glaurung, a UCI chess playing engine.
3   Copyright (C) 2004-2008 Tord Romstad
4
5   Glaurung is free software: you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation, either version 3 of the License, or
8   (at your option) any later version.
9   
10   Glaurung is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14   
15   You should have received a copy of the GNU General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19
20 #if !defined(VALUE_H_INCLUDED)
21 #define VALUE_H_INCLUDED
22
23 ////
24 //// Includes
25 ////
26
27 #include "piece.h"
28
29
30 ////
31 //// Types
32 ////
33
34 enum ValueType {
35   VALUE_TYPE_NONE = 0,
36   VALUE_TYPE_UPPER = 1,  // Upper bound
37   VALUE_TYPE_LOWER = 2,  // Lower bound
38   VALUE_TYPE_EXACT = 3   // Exact score
39 };
40
41
42 enum Value {
43   VALUE_DRAW = 0,
44   VALUE_KNOWN_WIN = 15000,
45   VALUE_MATE = 30000,
46   VALUE_INFINITE = 30001,
47   VALUE_NONE = 30002
48 };
49
50
51 ////
52 //// Constants and variables
53 ////
54
55 /// Piece values, middle game and endgame
56
57 /// Important: If the material values are changed, one must also
58 /// adjust the piece square tables, and the method game_phase() in the
59 /// Position class!
60
61 const Value PawnValueMidgame = Value(0xCC);
62 const Value PawnValueEndgame = Value(0x100);
63 const Value KnightValueMidgame = Value(0x340);
64 const Value KnightValueEndgame = Value(0x340);
65 const Value BishopValueMidgame = Value(0x340);
66 const Value BishopValueEndgame = Value(0x340);
67 const Value RookValueMidgame = Value(0x505);
68 const Value RookValueEndgame = Value(0x505);
69 const Value QueenValueMidgame = Value(0xA00);
70 const Value QueenValueEndgame = Value(0xA00);
71
72 const Value PieceValueMidgame[17] = {
73   Value(0),
74   PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
75   RookValueMidgame, QueenValueMidgame,
76   Value(0), Value(0), Value(0),
77   PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
78   RookValueMidgame, QueenValueMidgame,
79   Value(0), Value(0), Value(0)
80 };
81
82 const Value PieceValueEndgame[17] = {
83   Value(0),
84   PawnValueEndgame, KnightValueEndgame, BishopValueEndgame,
85   RookValueEndgame, QueenValueEndgame,
86   Value(0), Value(0), Value(0),
87   PawnValueEndgame, KnightValueEndgame, BishopValueEndgame,
88   RookValueEndgame, QueenValueEndgame,
89   Value(0), Value(0), Value(0)
90 };
91
92 /// Bonus for having the side to move
93
94 const Value TempoValueMidgame = Value(50);
95 const Value TempoValueEndgame = Value(20);
96
97
98 ////
99 //// Inline functions
100 ////
101
102 inline Value operator+ (Value v, int i) { return Value(int(v) + i); }
103 inline Value operator+ (Value v1, Value v2) { return Value(int(v1) + int(v2)); }
104 inline void operator+= (Value &v1, Value v2) {
105   v1 = Value(int(v1) + int(v2));
106 }
107 inline Value operator- (Value v, int i) { return Value(int(v) - i); }
108 inline Value operator- (Value v) { return Value(-int(v)); }
109 inline Value operator- (Value v1, Value v2) { return Value(int(v1) - int(v2)); }
110 inline void operator-= (Value &v1, Value v2) {
111   v1 = Value(int(v1) - int(v2));
112 }
113 inline Value operator* (Value v, int i) { return Value(int(v) * i); }
114 inline void operator*= (Value &v, int i) { v = Value(int(v) * i); }
115 inline Value operator* (int i, Value v) { return Value(int(v) * i); }
116 inline Value operator/ (Value v, int i) { return Value(int(v) / i); }
117 inline void operator/= (Value &v, int i) { v = Value(int(v) / i); }
118
119
120 inline Value value_mate_in(int ply) {
121   return Value(VALUE_MATE - Value(ply));
122 }
123                
124 inline Value value_mated_in(int ply) {
125   return Value(-VALUE_MATE + Value(ply));
126 }
127
128 inline bool is_upper_bound(ValueType vt) {
129   return (int(vt) & int(VALUE_TYPE_UPPER)) != 0;
130 }
131
132 inline bool is_lower_bound(ValueType vt) {
133   return (int(vt) & int(VALUE_TYPE_LOWER)) != 0;
134 }
135
136 inline Value piece_value_midgame(PieceType pt) {
137   return PieceValueMidgame[pt];
138 }
139
140 inline Value piece_value_endgame(PieceType pt) {
141   return PieceValueEndgame[pt];
142 }
143
144 inline Value piece_value_midgame(Piece p) {
145   return PieceValueMidgame[p];
146 }
147
148 inline Value piece_value_endgame(Piece p) {
149   return PieceValueEndgame[p];
150 }
151
152
153 ////
154 //// Prototypes
155 ////
156
157 extern Value value_to_tt(Value v, int ply);
158 extern Value value_from_tt(Value v, int ply);
159 extern int value_to_centipawns(Value v);
160 extern Value value_from_centipawns(int cp);
161 extern const std::string value_to_string(Value v);
162
163
164 #endif // !defined(VALUE_H_INCLUDED)