1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 09:13:08 +00:00

Rename piece_of_color_and_type() to make_piece()

To be aligned with make_square()

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2011-02-23 14:25:46 +01:00
parent 5b2ac7590c
commit 2ff2b59727
6 changed files with 38 additions and 38 deletions

View file

@ -570,11 +570,11 @@ namespace {
if (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1)) if (s == relative_square(Us, SQ_A1) || s == relative_square(Us, SQ_H1))
{ {
Square 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.piece_on(s + d) == make_piece(Us, PAWN))
{ {
if (!pos.square_is_empty(s + d + pawn_push(Us))) if (!pos.square_is_empty(s + d + pawn_push(Us)))
bonus -= 2*TrappedBishopA1H1Penalty; bonus -= 2*TrappedBishopA1H1Penalty;
else if (pos.piece_on(s + 2*d) == piece_of_color_and_type(Us, PAWN)) else if (pos.piece_on(s + 2*d) == make_piece(Us, PAWN))
bonus -= TrappedBishopA1H1Penalty; bonus -= TrappedBishopA1H1Penalty;
else else
bonus -= TrappedBishopA1H1Penalty / 2; bonus -= TrappedBishopA1H1Penalty / 2;

View file

@ -223,7 +223,7 @@ MoveStack* generate<MV_NON_CAPTURE_CHECK>(const Position& pos, MoveStack* mlist)
Color us = pos.side_to_move(); Color us = pos.side_to_move();
Square ksq = pos.king_square(opposite_color(us)); Square ksq = pos.king_square(opposite_color(us));
assert(pos.piece_on(ksq) == piece_of_color_and_type(opposite_color(us), KING)); assert(pos.piece_on(ksq) == make_piece(opposite_color(us), KING));
// Discovered non-capture checks // Discovered non-capture checks
b = dc = pos.discovered_check_candidates(us); b = dc = pos.discovered_check_candidates(us);
@ -267,7 +267,7 @@ MoveStack* generate<MV_EVASION>(const Position& pos, MoveStack* mlist) {
Bitboard checkers = pos.checkers(); Bitboard checkers = pos.checkers();
Bitboard sliderAttacks = EmptyBoardBB; Bitboard sliderAttacks = EmptyBoardBB;
assert(pos.piece_on(ksq) == piece_of_color_and_type(us, KING)); assert(pos.piece_on(ksq) == make_piece(us, KING));
assert(checkers); assert(checkers);
// Find squares attacked by slider checkers, we will remove // Find squares attacked by slider checkers, we will remove
@ -631,7 +631,7 @@ namespace {
Color them = opposite_color(us); Color them = opposite_color(us);
Square ksq = pos.king_square(us); Square ksq = pos.king_square(us);
assert(pos.piece_on(ksq) == piece_of_color_and_type(us, KING)); assert(pos.piece_on(ksq) == make_piece(us, KING));
Square rsq = (Side == KING_SIDE ? pos.initial_kr_square(us) : pos.initial_qr_square(us)); Square rsq = (Side == KING_SIDE ? pos.initial_kr_square(us) : pos.initial_qr_square(us));
Square s1 = relative_square(us, Side == KING_SIDE ? SQ_G1 : SQ_C1); Square s1 = relative_square(us, Side == KING_SIDE ? SQ_G1 : SQ_C1);
@ -639,7 +639,7 @@ namespace {
Square s; Square s;
bool illegal = false; bool illegal = false;
assert(pos.piece_on(rsq) == piece_of_color_and_type(us, ROOK)); assert(pos.piece_on(rsq) == make_piece(us, ROOK));
// It is a bit complicated to correctly handle Chess960 // It is a bit complicated to correctly handle Chess960
for (s = Min(ksq, s1); s <= Max(ksq, s1); s++) for (s = Min(ksq, s1); s <= Max(ksq, s1); s++)
@ -653,8 +653,8 @@ namespace {
if ( Side == QUEEN_SIDE if ( Side == QUEEN_SIDE
&& square_file(rsq) == FILE_B && square_file(rsq) == FILE_B
&& ( pos.piece_on(relative_square(us, SQ_A1)) == piece_of_color_and_type(them, ROOK) && ( pos.piece_on(relative_square(us, SQ_A1)) == make_piece(them, ROOK)
|| pos.piece_on(relative_square(us, SQ_A1)) == piece_of_color_and_type(them, QUEEN))) || pos.piece_on(relative_square(us, SQ_A1)) == make_piece(them, QUEEN)))
illegal = true; illegal = true;
if (!illegal) if (!illegal)

View file

@ -136,7 +136,7 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns,
// Loop through all pawns of the current color and score each pawn // Loop through all pawns of the current color and score each pawn
while ((s = *ptr++) != SQ_NONE) while ((s = *ptr++) != SQ_NONE)
{ {
assert(pos.piece_on(s) == piece_of_color_and_type(Us, PAWN)); assert(pos.piece_on(s) == make_piece(Us, PAWN));
f = square_file(s); f = square_file(s);
r = square_rank(s); r = square_rank(s);

View file

@ -53,6 +53,10 @@ const Value RookValueEndgame = Value(0x4FE);
const Value QueenValueMidgame = Value(0x9D9); const Value QueenValueMidgame = Value(0x9D9);
const Value QueenValueEndgame = Value(0x9FE); const Value QueenValueEndgame = Value(0x9FE);
inline Piece make_piece(Color c, PieceType pt) {
return Piece((int(c) << 3) | int(pt));
}
inline PieceType type_of_piece(Piece p) { inline PieceType type_of_piece(Piece p) {
return PieceType(int(p) & 7); return PieceType(int(p) & 7);
} }
@ -61,10 +65,6 @@ inline Color color_of_piece(Piece p) {
return Color(int(p) >> 3); return Color(int(p) >> 3);
} }
inline Piece piece_of_color_and_type(Color c, PieceType pt) {
return Piece((int(c) << 3) | int(pt));
}
inline bool piece_type_is_ok(PieceType pt) { inline bool piece_type_is_ok(PieceType pt) {
return pt >= PAWN && pt <= KING; return pt >= PAWN && pt <= KING;
} }

View file

@ -587,8 +587,8 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
Bitboard b = occupied_squares(); Bitboard b = occupied_squares();
assert(to == ep_square()); assert(to == ep_square());
assert(piece_on(from) == piece_of_color_and_type(us, PAWN)); assert(piece_on(from) == make_piece(us, PAWN));
assert(piece_on(capsq) == piece_of_color_and_type(them, PAWN)); assert(piece_on(capsq) == make_piece(them, PAWN));
assert(piece_on(to) == PIECE_NONE); assert(piece_on(to) == PIECE_NONE);
clear_bit(&b, from); clear_bit(&b, from);
@ -603,7 +603,7 @@ bool Position::pl_move_is_legal(Move m, Bitboard pinned) const {
Square from = move_from(m); Square from = move_from(m);
assert(color_of_piece_on(from) == us); assert(color_of_piece_on(from) == us);
assert(piece_on(king_square(us)) == piece_of_color_and_type(us, KING)); assert(piece_on(king_square(us)) == make_piece(us, KING));
// If the moving piece is a king, check whether the destination // If the moving piece is a king, check whether the destination
// square is attacked by the opponent. // square is attacked by the opponent.
@ -657,7 +657,7 @@ bool Position::move_is_check(Move m, const CheckInfo& ci) const {
assert(move_is_ok(m)); assert(move_is_ok(m));
assert(ci.dcCandidates == discovered_check_candidates(side_to_move())); assert(ci.dcCandidates == discovered_check_candidates(side_to_move()));
assert(color_of_piece_on(move_from(m)) == side_to_move()); assert(color_of_piece_on(move_from(m)) == side_to_move());
assert(piece_on(ci.ksq) == piece_of_color_and_type(opposite_color(side_to_move()), KING)); assert(piece_on(ci.ksq) == make_piece(opposite_color(side_to_move()), KING));
Square from = move_from(m); Square from = move_from(m);
Square to = move_to(m); Square to = move_to(m);
@ -833,7 +833,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
assert(color_of_piece_on(from) == us); assert(color_of_piece_on(from) == us);
assert(color_of_piece_on(to) == them || square_is_empty(to)); assert(color_of_piece_on(to) == them || square_is_empty(to));
assert(!(ep || pm) || piece == piece_of_color_and_type(us, PAWN)); assert(!(ep || pm) || piece == make_piece(us, PAWN));
assert(!pm || relative_rank(us, to) == RANK_8); assert(!pm || relative_rank(us, to) == RANK_8);
if (capture) if (capture)
@ -906,7 +906,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
// Insert promoted piece instead of pawn // Insert promoted piece instead of pawn
clear_bit(&(byTypeBB[PAWN]), to); clear_bit(&(byTypeBB[PAWN]), to);
set_bit(&(byTypeBB[promotion]), to); set_bit(&(byTypeBB[promotion]), to);
board[to] = piece_of_color_and_type(us, promotion); board[to] = make_piece(us, promotion);
// Update piece counts // Update piece counts
pieceCount[us][promotion]++; pieceCount[us][promotion]++;
@ -1000,7 +1000,7 @@ void Position::do_capture_move(Key& key, PieceType capture, Color them, Square t
assert(to == st->epSquare); assert(to == st->epSquare);
assert(relative_rank(opposite_color(them), to) == RANK_6); assert(relative_rank(opposite_color(them), to) == RANK_6);
assert(piece_on(to) == PIECE_NONE); assert(piece_on(to) == PIECE_NONE);
assert(piece_on(capsq) == piece_of_color_and_type(them, PAWN)); assert(piece_on(capsq) == make_piece(them, PAWN));
board[capsq] = PIECE_NONE; board[capsq] = PIECE_NONE;
} }
@ -1064,8 +1064,8 @@ void Position::do_castle_move(Move m) {
Square rfrom = move_to(m); // HACK: See comment at beginning of function Square rfrom = move_to(m); // HACK: See comment at beginning of function
Square kto, rto; Square kto, rto;
assert(piece_on(kfrom) == piece_of_color_and_type(us, KING)); assert(piece_on(kfrom) == make_piece(us, KING));
assert(piece_on(rfrom) == piece_of_color_and_type(us, ROOK)); assert(piece_on(rfrom) == make_piece(us, ROOK));
// Find destination squares for king and rook // Find destination squares for king and rook
if (rfrom > kfrom) // O-O if (rfrom > kfrom) // O-O
@ -1094,8 +1094,8 @@ void Position::do_castle_move(Move m) {
set_bit(&(byTypeBB[0]), rto); // HACK: byTypeBB[0] == occupied squares set_bit(&(byTypeBB[0]), rto); // HACK: byTypeBB[0] == occupied squares
// Update board array // Update board array
Piece king = piece_of_color_and_type(us, KING); Piece king = make_piece(us, KING);
Piece rook = piece_of_color_and_type(us, ROOK); Piece rook = make_piece(us, ROOK);
board[kfrom] = board[rfrom] = PIECE_NONE; board[kfrom] = board[rfrom] = PIECE_NONE;
board[kto] = king; board[kto] = king;
board[rto] = rook; board[rto] = rook;
@ -1171,7 +1171,7 @@ void Position::undo_move(Move m) {
assert(!pm || relative_rank(us, to) == RANK_8); assert(!pm || relative_rank(us, to) == RANK_8);
assert(!ep || to == st->previous->epSquare); assert(!ep || to == st->previous->epSquare);
assert(!ep || relative_rank(us, to) == RANK_6); assert(!ep || relative_rank(us, to) == RANK_6);
assert(!ep || piece_on(to) == piece_of_color_and_type(us, PAWN)); assert(!ep || piece_on(to) == make_piece(us, PAWN));
if (pm) // promotion ? if (pm) // promotion ?
{ {
@ -1179,7 +1179,7 @@ void Position::undo_move(Move m) {
pt = PAWN; pt = PAWN;
assert(promotion >= KNIGHT && promotion <= QUEEN); assert(promotion >= KNIGHT && promotion <= QUEEN);
assert(piece_on(to) == piece_of_color_and_type(us, promotion)); assert(piece_on(to) == make_piece(us, promotion));
// Replace promoted piece with a pawn // Replace promoted piece with a pawn
clear_bit(&(byTypeBB[promotion]), to); clear_bit(&(byTypeBB[promotion]), to);
@ -1204,7 +1204,7 @@ void Position::undo_move(Move m) {
do_move_bb(&(byTypeBB[pt]), move_bb); do_move_bb(&(byTypeBB[pt]), move_bb);
do_move_bb(&(byTypeBB[0]), move_bb); // HACK: byTypeBB[0] == occupied squares do_move_bb(&(byTypeBB[0]), move_bb); // HACK: byTypeBB[0] == occupied squares
board[from] = piece_of_color_and_type(us, pt); board[from] = make_piece(us, pt);
board[to] = PIECE_NONE; board[to] = PIECE_NONE;
// Update piece list // Update piece list
@ -1226,7 +1226,7 @@ void Position::undo_move(Move m) {
set_bit(&(byTypeBB[st->capturedType]), capsq); set_bit(&(byTypeBB[st->capturedType]), capsq);
set_bit(&(byTypeBB[0]), capsq); set_bit(&(byTypeBB[0]), capsq);
board[capsq] = piece_of_color_and_type(them, st->capturedType); board[capsq] = make_piece(them, st->capturedType);
// Update piece count // Update piece count
pieceCount[them][st->capturedType]++; pieceCount[them][st->capturedType]++;
@ -1273,8 +1273,8 @@ void Position::undo_castle_move(Move m) {
rto = relative_square(us, SQ_D1); rto = relative_square(us, SQ_D1);
} }
assert(piece_on(kto) == piece_of_color_and_type(us, KING)); assert(piece_on(kto) == make_piece(us, KING));
assert(piece_on(rto) == piece_of_color_and_type(us, ROOK)); assert(piece_on(rto) == make_piece(us, ROOK));
// Remove pieces from destination squares: // Remove pieces from destination squares:
clear_bit(&(byColorBB[us]), kto); clear_bit(&(byColorBB[us]), kto);
@ -1294,8 +1294,8 @@ void Position::undo_castle_move(Move m) {
// Update board // Update board
board[rto] = board[kto] = PIECE_NONE; board[rto] = board[kto] = PIECE_NONE;
board[rfrom] = piece_of_color_and_type(us, ROOK); board[rfrom] = make_piece(us, ROOK);
board[kfrom] = piece_of_color_and_type(us, KING); board[kfrom] = make_piece(us, KING);
// Update piece lists // Update piece lists
pieceList[us][KING][index[kto]] = kfrom; pieceList[us][KING][index[kto]] = kfrom;
@ -1980,7 +1980,7 @@ bool Position::is_ok(int* failedStep) const {
for (PieceType pt = PAWN; pt <= KING; pt++) for (PieceType pt = PAWN; pt <= KING; pt++)
for (int i = 0; i < pieceCount[c][pt]; i++) for (int i = 0; i < pieceCount[c][pt]; i++)
{ {
if (piece_on(piece_list(c, pt, i)) != piece_of_color_and_type(c, pt)) if (piece_on(piece_list(c, pt, i)) != make_piece(c, pt))
return false; return false;
if (index[piece_list(c, pt, i)] != i) if (index[piece_list(c, pt, i)] != i)
@ -1991,9 +1991,9 @@ bool Position::is_ok(int* failedStep) const {
if (failedStep) (*failedStep)++; if (failedStep) (*failedStep)++;
if (debugCastleSquares) { if (debugCastleSquares) {
for (Color c = WHITE; c <= BLACK; c++) { for (Color c = WHITE; c <= BLACK; c++) {
if (can_castle_kingside(c) && piece_on(initial_kr_square(c)) != piece_of_color_and_type(c, ROOK)) if (can_castle_kingside(c) && piece_on(initial_kr_square(c)) != make_piece(c, ROOK))
return false; return false;
if (can_castle_queenside(c) && piece_on(initial_qr_square(c)) != piece_of_color_and_type(c, ROOK)) if (can_castle_queenside(c) && piece_on(initial_qr_square(c)) != make_piece(c, ROOK))
return false; return false;
} }
if (castleRightsMask[initial_kr_square(WHITE)] != (ALL_CASTLES ^ WHITE_OO)) if (castleRightsMask[initial_kr_square(WHITE)] != (ALL_CASTLES ^ WHITE_OO))

View file

@ -434,7 +434,7 @@ inline Square Position::initial_qr_square(Color c) const {
template<> template<>
inline Bitboard Position::attacks_from<PAWN>(Square s, Color c) const { inline Bitboard Position::attacks_from<PAWN>(Square s, Color c) const {
return NonSlidingAttacksBB[piece_of_color_and_type(c, PAWN)][s]; return NonSlidingAttacksBB[make_piece(c, PAWN)][s];
} }
template<PieceType Piece> // Knight and King and white pawns template<PieceType Piece> // Knight and King and white pawns
@ -490,7 +490,7 @@ inline Key Position::get_material_key() const {
} }
inline Score Position::pst(Color c, PieceType pt, Square s) { inline Score Position::pst(Color c, PieceType pt, Square s) {
return PieceSquareTable[piece_of_color_and_type(c, pt)][s]; return PieceSquareTable[make_piece(c, pt)][s];
} }
inline Score Position::pst_delta(Piece piece, Square from, Square to) { inline Score Position::pst_delta(Piece piece, Square from, Square to) {
@ -508,7 +508,7 @@ inline Value Position::non_pawn_material(Color c) const {
inline bool Position::move_is_passed_pawn_push(Move m) const { inline bool Position::move_is_passed_pawn_push(Move m) const {
Color c = side_to_move(); Color c = side_to_move();
return piece_on(move_from(m)) == piece_of_color_and_type(c, PAWN) return piece_on(move_from(m)) == make_piece(c, PAWN)
&& pawn_is_passed(c, move_to(m)); && pawn_is_passed(c, move_to(m));
} }