1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-29 16:23:09 +00:00

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 <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2009-02-17 10:54:47 +01:00
parent f32992f88c
commit 2c955f25de
6 changed files with 23 additions and 47 deletions

View file

@ -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);

View file

@ -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.

View file

@ -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)

View file

@ -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)];
}

View file

@ -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;

View file

@ -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<PAWN>(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));
}