mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
Use Use templetized operations for Score and Value
Note that in value we leave two specialized functions to allow adding an integer, we don't want to add this as a template becasue we want to control implicit conversions to integer of an enum. No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
13bd0cff0d
commit
0e800c527a
2 changed files with 5 additions and 23 deletions
|
@ -137,6 +137,9 @@ inline void operator-- (T& d, int) { d = T(int(d) - 1); }
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void operator+= (T& d1, const T d2) { d1 = d1 + d2; }
|
inline void operator+= (T& d1, const T d2) { d1 = d1 + d2; }
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline void operator-= (T& d1, const T d2) { d1 = d1 - d2; }
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void operator*= (T& d, int i) { d = T(int(d) * i); }
|
inline void operator*= (T& d, int i) { d = T(int(d) * i); }
|
||||||
|
|
||||||
|
|
25
src/value.h
25
src/value.h
|
@ -81,13 +81,6 @@ inline Value eg_value(Score s) { return Value((int)(unsigned(s) & 0x7fffu) - (in
|
||||||
|
|
||||||
inline Score make_score(int mg, int eg) { return Score((mg << 16) + eg); }
|
inline Score make_score(int mg, int eg) { return Score((mg << 16) + eg); }
|
||||||
|
|
||||||
inline Score operator-(Score s) { return Score(-int(s)); }
|
|
||||||
inline Score operator+(Score s1, Score s2) { return Score(int(s1) + int(s2)); }
|
|
||||||
inline Score operator-(Score s1, Score s2) { return Score(int(s1) - int(s2)); }
|
|
||||||
inline void operator+=(Score& s1, Score s2) { s1 = Score(int(s1) + int(s2)); }
|
|
||||||
inline void operator-=(Score& s1, Score s2) { s1 = Score(int(s1) - int(s2)); }
|
|
||||||
inline Score operator*(int i, Score s) { return Score(i * int(s)); }
|
|
||||||
|
|
||||||
// Division must be handled separately for each term
|
// Division must be handled separately for each term
|
||||||
inline Score operator/(Score s, int i) { return make_score(mg_value(s) / i, eg_value(s) / i); }
|
inline Score operator/(Score s, int i) { return make_score(mg_value(s) / i, eg_value(s) / i); }
|
||||||
|
|
||||||
|
@ -149,29 +142,15 @@ const Score TempoValue = make_score(48, 22);
|
||||||
////
|
////
|
||||||
|
|
||||||
inline Value operator+ (Value v, int i) { return Value(int(v) + i); }
|
inline Value operator+ (Value v, int i) { return Value(int(v) + i); }
|
||||||
inline Value operator+ (Value v1, Value v2) { return Value(int(v1) + int(v2)); }
|
|
||||||
inline void operator+= (Value &v1, Value v2) {
|
|
||||||
v1 = Value(int(v1) + int(v2));
|
|
||||||
}
|
|
||||||
inline Value operator- (Value v, int i) { return Value(int(v) - i); }
|
inline Value operator- (Value v, int i) { return Value(int(v) - i); }
|
||||||
inline Value operator- (Value v) { return Value(-int(v)); }
|
|
||||||
inline Value operator- (Value v1, Value v2) { return Value(int(v1) - int(v2)); }
|
|
||||||
inline void operator-= (Value &v1, Value v2) {
|
|
||||||
v1 = Value(int(v1) - int(v2));
|
|
||||||
}
|
|
||||||
inline Value operator* (Value v, int i) { return Value(int(v) * i); }
|
|
||||||
inline void operator*= (Value &v, int i) { v = Value(int(v) * i); }
|
|
||||||
inline Value operator* (int i, Value v) { return Value(int(v) * i); }
|
|
||||||
inline Value operator/ (Value v, int i) { return Value(int(v) / i); }
|
|
||||||
inline void operator/= (Value &v, int i) { v = Value(int(v) / i); }
|
|
||||||
|
|
||||||
|
|
||||||
inline Value value_mate_in(int ply) {
|
inline Value value_mate_in(int ply) {
|
||||||
return Value(VALUE_MATE - Value(ply));
|
return VALUE_MATE - ply;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value value_mated_in(int ply) {
|
inline Value value_mated_in(int ply) {
|
||||||
return Value(-VALUE_MATE + Value(ply));
|
return -VALUE_MATE + ply;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool is_upper_bound(ValueType vt) {
|
inline bool is_upper_bound(ValueType vt) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue