From deb212cb052b50caa68542cde8e14ef6c6a0a01c Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Wed, 23 Feb 2011 10:03:30 +0100 Subject: [PATCH] Retire enum SquareDelta Use Square instead. At the end is the same because we were anyway foreseen operators on mixed terms (Square, SquareDelta). No functional change. Signed-off-by: Marco Costalba --- src/bitboard.cpp | 5 ++--- src/evaluate.cpp | 3 +-- src/movegen.cpp | 18 +++++++++--------- src/piece.h | 2 +- src/square.h | 32 +++++++++++++------------------- 5 files changed, 26 insertions(+), 34 deletions(-) diff --git a/src/bitboard.cpp b/src/bitboard.cpp index bc8d5c3d..bc05bfa0 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -482,8 +482,7 @@ namespace { void init_between_bitboards() { - Square s1, s2, s3; - SquareDelta d; + Square s1, s2, s3, d; int f, r; for (s1 = SQ_A1; s1 <= SQ_H8; s1++) @@ -493,7 +492,7 @@ namespace { f = file_distance(s1, s2); r = rank_distance(s1, s2); - d = SquareDelta(s2 - s1) / Max(f, r); + d = (s2 - s1) / Max(f, r); for (s3 = s1 + d; s3 != s2; s3 += d) set_bit(&(BetweenBB[s1][s2]), s3); diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 680b8e0f..657b0f49 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -569,8 +569,7 @@ namespace { // problem, especially when that pawn is also blocked. if (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1)) { - SquareDelta d = pawn_push(Us) - + (square_file(s) == FILE_A ? DELTA_E : DELTA_W); + Square d = pawn_push(Us) + (square_file(s) == FILE_A ? DELTA_E : DELTA_W); if (pos.piece_on(s + d) == piece_of_color_and_type(Us, PAWN)) { if (!pos.square_is_empty(s + d + pawn_push(Us))) diff --git a/src/movegen.cpp b/src/movegen.cpp index 6f932cd0..5107d105 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -462,7 +462,7 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) { namespace { - template + template inline Bitboard move_pawns(Bitboard p) { return Delta == DELTA_N ? p << 8 : Delta == DELTA_S ? p >> 8 : @@ -470,7 +470,7 @@ namespace { Delta == DELTA_NW ? p << 7 : Delta == DELTA_SW ? p >> 9 : p; } - template + template inline MoveStack* generate_pawn_captures(MoveStack* mlist, Bitboard pawns, Bitboard target) { const Bitboard TFileABB = (Delta == DELTA_NE || Delta == DELTA_SE ? FileABB : FileHBB); @@ -484,7 +484,7 @@ namespace { return mlist; } - template + template inline MoveStack* generate_promotions(const Position& pos, MoveStack* mlist, Bitboard pawnsOn7, Bitboard target) { const Bitboard TFileABB = (Delta == DELTA_NE || Delta == DELTA_SE ? FileABB : FileHBB); @@ -527,12 +527,12 @@ namespace { // Calculate our parametrized parameters at compile time, named // according to the point of view of white side. - const Color Them = (Us == WHITE ? BLACK : WHITE); - const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB); - const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB); - const SquareDelta TDELTA_N = (Us == WHITE ? DELTA_N : DELTA_S); - const SquareDelta TDELTA_NE = (Us == WHITE ? DELTA_NE : DELTA_SE); - const SquareDelta TDELTA_NW = (Us == WHITE ? DELTA_NW : DELTA_SW); + const Color Them = (Us == WHITE ? BLACK : WHITE); + const Bitboard TRank7BB = (Us == WHITE ? Rank7BB : Rank2BB); + const Bitboard TRank3BB = (Us == WHITE ? Rank3BB : Rank6BB); + const Square TDELTA_N = (Us == WHITE ? DELTA_N : DELTA_S); + const Square TDELTA_NE = (Us == WHITE ? DELTA_NE : DELTA_SE); + const Square TDELTA_NW = (Us == WHITE ? DELTA_NW : DELTA_SW); Square to; Bitboard b1, b2, dc1, dc2, pawnPushes, emptySquares; diff --git a/src/piece.h b/src/piece.h index be77079a..64c94082 100644 --- a/src/piece.h +++ b/src/piece.h @@ -88,7 +88,7 @@ inline Piece piece_of_color_and_type(Color c, PieceType pt) { return Piece((int(c) << 3) | int(pt)); } -inline SquareDelta pawn_push(Color c) { +inline Square pawn_push(Color c) { return (c == WHITE ? DELTA_N : DELTA_S); } diff --git a/src/square.h b/src/square.h index fe0cc968..bc5221b6 100644 --- a/src/square.h +++ b/src/square.h @@ -35,20 +35,12 @@ enum Square { SQ_A6, SQ_B6, SQ_C6, SQ_D6, SQ_E6, SQ_F6, SQ_G6, SQ_H6, SQ_A7, SQ_B7, SQ_C7, SQ_D7, SQ_E7, SQ_F7, SQ_G7, SQ_H7, SQ_A8, SQ_B8, SQ_C8, SQ_D8, SQ_E8, SQ_F8, SQ_G8, SQ_H8, - SQ_NONE -}; - -enum File { - FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H -}; - -enum Rank { - RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8 -}; - -enum SquareDelta { + SQ_NONE, - DELTA_N = 8, DELTA_E = 1, DELTA_S = -8, DELTA_W = -1, DELTA_NONE = 0, + DELTA_N = 8, + DELTA_E = 1, + DELTA_S = -8, + DELTA_W = -1, DELTA_NN = DELTA_N + DELTA_N, DELTA_NE = DELTA_N + DELTA_E, @@ -58,19 +50,21 @@ enum SquareDelta { DELTA_NW = DELTA_N + DELTA_W }; +enum File { + FILE_A, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H +}; + +enum Rank { + RANK_1, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8 +}; + ENABLE_OPERATORS_ON(Square) ENABLE_OPERATORS_ON(File) ENABLE_OPERATORS_ON(Rank) -ENABLE_OPERATORS_ON(SquareDelta) const int FlipMask = 56; const int FlopMask = 7; -inline Square operator+ (Square x, SquareDelta i) { return x + Square(i); } -inline void operator+= (Square& x, SquareDelta i) { x = x + Square(i); } -inline Square operator- (Square x, SquareDelta i) { return x - Square(i); } -inline void operator-= (Square& x, SquareDelta i) { x = x - Square(i); } - inline Square make_square(File f, Rank r) { return Square((int(r) << 3) | int(f)); } -- 2.39.2