From: Marco Costalba Date: Tue, 17 Feb 2009 09:54:47 +0000 (+0100) Subject: Remove xxx_of_color() helpers X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=2c955f25de9d4c263b6e6d37fef06b378eec49a0 Remove xxx_of_color() helpers They hide the underlying uniform function call with no benefit. A little bit more verbose but now is clear what happens. No functional change. Signed-off-by: Marco Costalba --- diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 04e4dded..ee626433 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -1074,7 +1074,7 @@ namespace { Square b6 = relative_square(us, (square_file(s) == FILE_A) ? SQ_B6 : SQ_G6); Square b8 = relative_square(us, (square_file(s) == FILE_A) ? SQ_B8 : SQ_G8); - if ( pos.piece_on(b6) == pawn_of_color(opposite_color(us)) + if ( pos.piece_on(b6) == piece_of_color_and_type(opposite_color(us), PAWN) && pos.see(s, b6) < 0 && pos.see(s, b8) < 0) { @@ -1091,7 +1091,7 @@ namespace { void evaluate_trapped_bishop_a1h1(const Position &pos, Square s, Color us, EvalInfo &ei) { - Piece pawn = pawn_of_color(us); + Piece pawn = piece_of_color_and_type(us, PAWN); Square b2, b3, c3; assert(Chess960); diff --git a/src/move.cpp b/src/move.cpp index 63800d7f..ad282dfb 100644 --- a/src/move.cpp +++ b/src/move.cpp @@ -72,13 +72,13 @@ Move move_from_string(const Position& pos, const std::string& str) { } } - if (piece == king_of_color(us)) + if (piece == piece_of_color_and_type(us, KING)) { // Is this a castling move? A king move is assumed to be a castling // move if the destination square is occupied by a friendly rook, or // if the distance between the source and destination squares is more // than 1. - if (pos.piece_on(to) == rook_of_color(us)) + if (pos.piece_on(to) == piece_of_color_and_type(us, ROOK)) return make_castle_move(from, to); else if (square_distance(from, to) > 1) @@ -87,13 +87,13 @@ Move move_from_string(const Position& pos, const std::string& str) { // internal "king captures rook" representation. SquareDelta delta = (to > from ? DELTA_E : DELTA_W); Square s = from + delta; - while (relative_rank(us, s) == RANK_1 && pos.piece_on(s) != rook_of_color(us)) + while (relative_rank(us, s) == RANK_1 && pos.piece_on(s) != piece_of_color_and_type(us, ROOK)) s += delta; return (relative_rank(us, s) == RANK_1 ? make_castle_move(from, s) : MOVE_NONE); } } - else if (piece == pawn_of_color(us)) + else if (piece == piece_of_color_and_type(us, PAWN)) { // En passant move? We assume that a pawn move is an en passant move // without further testing if the destination square is epSquare. diff --git a/src/movegen.cpp b/src/movegen.cpp index bc56548d..817b4f98 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -467,8 +467,8 @@ bool move_is_legal(const Position& pos, const Move m, Bitboard pinned) { illegal = true; if ( square_file(to) == FILE_B - && ( pos.piece_on(to + DELTA_W) == rook_of_color(them) - || pos.piece_on(to + DELTA_W) == queen_of_color(them))) + && ( pos.piece_on(to + DELTA_W) == piece_of_color_and_type(them, ROOK) + || pos.piece_on(to + DELTA_W) == piece_of_color_and_type(them, QUEEN))) illegal = true; return !illegal; @@ -888,8 +888,8 @@ namespace { if ( Side == QUEEN_SIDE && square_file(rsq) == FILE_B - && ( pos.piece_on(relative_square(us, SQ_A1)) == rook_of_color(them) - || pos.piece_on(relative_square(us, SQ_A1)) == queen_of_color(them))) + && ( pos.piece_on(relative_square(us, SQ_A1)) == piece_of_color_and_type(them, ROOK) + || pos.piece_on(relative_square(us, SQ_A1)) == piece_of_color_and_type(them, QUEEN))) illegal = true; if (!illegal) diff --git a/src/piece.h b/src/piece.h index d7f11b6c..be75a433 100644 --- a/src/piece.h +++ b/src/piece.h @@ -111,30 +111,6 @@ inline Piece piece_of_color_and_type(Color c, PieceType pt) { return Piece((int(c) << 3) | int(pt)); } -inline Piece pawn_of_color(Color c) { - return piece_of_color_and_type(c, PAWN); -} - -inline Piece knight_of_color(Color c) { - return piece_of_color_and_type(c, KNIGHT); -} - -inline Piece bishop_of_color(Color c) { - return piece_of_color_and_type(c, BISHOP); -} - -inline Piece rook_of_color(Color c) { - return piece_of_color_and_type(c, ROOK); -} - -inline Piece queen_of_color(Color c) { - return piece_of_color_and_type(c, QUEEN); -} - -inline Piece king_of_color(Color c) { - return piece_of_color_and_type(c, KING); -} - inline int piece_is_slider(Piece p) { return SlidingArray[int(p)]; } diff --git a/src/position.cpp b/src/position.cpp index 2585ef3c..501674d6 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -984,8 +984,8 @@ void Position::do_castle_move(Move m) { // Update board array board[kfrom] = board[rfrom] = EMPTY; - board[kto] = king_of_color(us); - board[rto] = rook_of_color(us); + board[kto] = piece_of_color_and_type(us, KING); + board[rto] = piece_of_color_and_type(us, ROOK); // Update king square kingSquare[us] = kto; @@ -1348,8 +1348,8 @@ void Position::undo_castle_move(Move m) { // Update board board[rto] = board[kto] = EMPTY; - board[rfrom] = rook_of_color(us); - board[kfrom] = king_of_color(us); + board[rfrom] = piece_of_color_and_type(us, ROOK); + board[kfrom] = piece_of_color_and_type(us, KING); // Update king square kingSquare[us] = kfrom; @@ -1400,7 +1400,7 @@ void Position::undo_promotion_move(Move m, const UndoInfo &u) { set_bit(&(byColorBB[us]), from); set_bit(&(byTypeBB[PAWN]), from); set_bit(&(byTypeBB[0]), from); // HACK: byTypeBB[0] == occupied squares - board[from] = pawn_of_color(us); + board[from] = piece_of_color_and_type(us, PAWN); // Update material npMaterial[us] -= piece_value_midgame(promotion); @@ -1473,7 +1473,7 @@ void Position::undo_ep_move(Move m) { set_bit(&(byColorBB[them]), capsq); set_bit(&(byTypeBB[PAWN]), capsq); set_bit(&(byTypeBB[0]), capsq); - board[capsq] = pawn_of_color(them); + board[capsq] = piece_of_color_and_type(them, PAWN); // Remove moving piece from destination square clear_bit(&(byColorBB[us]), to); @@ -1485,7 +1485,7 @@ void Position::undo_ep_move(Move m) { set_bit(&(byColorBB[us]), from); set_bit(&(byTypeBB[PAWN]), from); set_bit(&(byTypeBB[0]), from); - board[from] = pawn_of_color(us); + board[from] = piece_of_color_and_type(us, PAWN); // Update piece list: pieceList[us][PAWN][index[to]] = from; diff --git a/src/position.h b/src/position.h index 3822e3bc..8e2ecf60 100644 --- a/src/position.h +++ b/src/position.h @@ -529,12 +529,12 @@ inline Square Position::initial_qr_square(Color c) const { } inline Bitboard Position::pawn_attacks(Color c, Square s) const { - return StepAttackBB[pawn_of_color(c)][s]; + return StepAttackBB[piece_of_color_and_type(c, PAWN)][s]; } template<> inline Bitboard Position::piece_attacks(Square s) const { - return StepAttackBB[pawn_of_color(opposite_color(sideToMove))][s]; + return StepAttackBB[piece_of_color_and_type(opposite_color(sideToMove), PAWN)][s]; } template<> @@ -675,28 +675,28 @@ inline Phase Position::game_phase() const { inline bool Position::move_is_deep_pawn_push(Move m) const { Color c = side_to_move(); - return piece_on(move_from(m)) == pawn_of_color(c) + return piece_on(move_from(m)) == piece_of_color_and_type(c, PAWN) && relative_rank(c, move_to(m)) > RANK_4; } inline bool Position::move_is_pawn_push_to_7th(Move m) const { Color c = side_to_move(); - return piece_on(move_from(m)) == pawn_of_color(c) + return piece_on(move_from(m)) == piece_of_color_and_type(c, PAWN) && relative_rank(c, move_to(m)) == RANK_7; } inline bool Position::move_is_passed_pawn_push(Move m) const { Color c = side_to_move(); - return piece_on(move_from(m)) == pawn_of_color(c) + return piece_on(move_from(m)) == piece_of_color_and_type(c, PAWN) && pawn_is_passed(c, move_to(m)); } inline bool Position::move_was_passed_pawn_push(Move m) const { Color c = opposite_color(side_to_move()); - return piece_on(move_to(m)) == pawn_of_color(c) + return piece_on(move_to(m)) == piece_of_color_and_type(c, PAWN) && pawn_is_passed(c, move_to(m)); }