From: Marco Costalba Date: Wed, 18 Aug 2010 15:17:20 +0000 (+0100) Subject: Use templetized operations for File and Rank X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=4ce08482c3b0685691162bfc9115ccc7656674b4;p=fairystockfish.git Use templetized operations for File and Rank Doing the conversion the compiler is now able to spot two possible ambiguity calls that now we can easily fix. No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/pawns.cpp b/src/pawns.cpp index b5c377e..5a789ef 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -214,7 +214,7 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns, pi->qsStormValue[Us] += QStormTable[relative_square(Us, s)] + bonus; // Our rank plus previous one. Used for chain detection. - b = rank_bb(r) | rank_bb(Us == WHITE ? r - 1 : r + 1); + b = rank_bb(r) | rank_bb(Us == WHITE ? r - Rank(1) : r + Rank(1)); // Passed, isolated, doubled or member of a pawn // chain (but not the backward one) ? diff --git a/src/position.cpp b/src/position.cpp index c8132d5..021113e 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -182,7 +182,7 @@ void Position::from_fen(const string& fen) { { if (isdigit(token)) { - file += token - '0'; // Skip the given number of files + file += File(token - '0'); // Skip the given number of files continue; } else if (token == '/') diff --git a/src/square.h b/src/square.h index e4eab2a..8de3f55 100644 --- a/src/square.h +++ b/src/square.h @@ -77,22 +77,6 @@ const int FlopMask = 07; //// Inline functions //// -inline File operator+ (File x, int i) { return File(int(x) + i); } -inline File operator+ (File x, File y) { return x + int(y); } -inline void operator++ (File &x, int) { x = File(int(x) + 1); } -inline void operator+= (File &x, int i) { x = File(int(x) + i); } -inline File operator- (File x, int i) { return File(int(x) - i); } -inline void operator-- (File &x, int) { x = File(int(x) - 1); } -inline void operator-= (File &x, int i) { x = File(int(x) - i); } - -inline Rank operator+ (Rank x, int i) { return Rank(int(x) + i); } -inline Rank operator+ (Rank x, Rank y) { return x + int(y); } -inline void operator++ (Rank &x, int) { x = Rank(int(x) + 1); } -inline void operator+= (Rank &x, int i) { x = Rank(int(x) + i); } -inline Rank operator- (Rank x, int i) { return Rank(int(x) - i); } -inline void operator-- (Rank &x, int) { x = Rank(int(x) - 1); } -inline void operator-= (Rank &x, int i) { x = Rank(int(x) - i); } - inline Square operator+ (Square x, int i) { return Square(int(x) + i); } inline void operator++ (Square &x, int) { x = Square(int(x) + 1); } inline void operator+= (Square &x, int i) { x = Square(int(x) + i); } @@ -103,6 +87,7 @@ inline Square operator+ (Square x, SquareDelta i) { return Square(int(x) + i); } inline void operator+= (Square &x, SquareDelta i) { x = Square(int(x) + i); } inline Square operator- (Square x, SquareDelta i) { return Square(int(x) - i); } inline void operator-= (Square &x, SquareDelta i) { x = Square(int(x) - i); } + inline SquareDelta operator- (Square x, Square y) { return SquareDelta(int(x) - int(y)); } diff --git a/src/types.h b/src/types.h index 4931531..f018311 100644 --- a/src/types.h +++ b/src/types.h @@ -126,6 +126,12 @@ template inline T operator/ (const T d, int i) { return T(int(d) / i); } template +inline void operator++ (T& d, int) { d = T(int(d) + 1); } + +template +inline void operator-- (T& d, int) { d = T(int(d) - 1); } + +template inline void operator+= (T& d1, const T d2) { d1 = d1 + d2; } template