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

Introduce piece_moved() to simplify common code

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2012-01-09 22:34:00 +01:00
parent b05fbb3733
commit bede30e7a6
4 changed files with 13 additions and 8 deletions

View file

@ -255,7 +255,7 @@ void MovePicker::score_captures() {
{ {
m = cur->move; m = cur->move;
cur->score = PieceValueMidgame[pos.piece_on(to_sq(m))] cur->score = PieceValueMidgame[pos.piece_on(to_sq(m))]
- type_of(pos.piece_on(from_sq(m))); - type_of(pos.piece_moved(m));
if (is_promotion(m)) if (is_promotion(m))
cur->score += PieceValueMidgame[Piece(promotion_piece_type(m))]; cur->score += PieceValueMidgame[Piece(promotion_piece_type(m))];
@ -294,9 +294,9 @@ void MovePicker::score_evasions() {
cur->score = seeScore - History::MaxValue; // Be sure we are at the bottom cur->score = seeScore - History::MaxValue; // Be sure we are at the bottom
else if (pos.is_capture(m)) else if (pos.is_capture(m))
cur->score = PieceValueMidgame[pos.piece_on(to_sq(m))] cur->score = PieceValueMidgame[pos.piece_on(to_sq(m))]
- type_of(pos.piece_on(from_sq(m))) + History::MaxValue; - type_of(pos.piece_moved(m)) + History::MaxValue;
else else
cur->score = H.value(pos.piece_on(from_sq(m)), to_sq(m)); cur->score = H.value(pos.piece_moved(m), to_sq(m));
} }
} }

View file

@ -641,7 +641,7 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
assert(is_ok(m)); assert(is_ok(m));
assert(ci.dcCandidates == discovered_check_candidates()); assert(ci.dcCandidates == discovered_check_candidates());
assert(color_of(piece_on(from_sq(m))) == side_to_move()); assert(color_of(piece_moved(m)) == side_to_move());
Square from = from_sq(m); Square from = from_sq(m);
Square to = to_sq(m); Square to = to_sq(m);

View file

@ -101,6 +101,7 @@ public:
// The piece on a given square // The piece on a given square
Piece piece_on(Square s) const; Piece piece_on(Square s) const;
Piece piece_moved(Move m) const;
bool square_is_empty(Square s) const; bool square_is_empty(Square s) const;
// Side to move // Side to move
@ -278,6 +279,10 @@ inline Piece Position::piece_on(Square s) const {
return board[s]; return board[s];
} }
inline Piece Position::piece_moved(Move m) const {
return board[from_sq(m)];
}
inline bool Position::square_is_empty(Square s) const { inline bool Position::square_is_empty(Square s) const {
return board[s] == NO_PIECE; return board[s] == NO_PIECE;
} }

View file

@ -200,7 +200,7 @@ namespace {
FORCE_INLINE bool is_dangerous(const Position& pos, Move m, bool captureOrPromotion) { FORCE_INLINE bool is_dangerous(const Position& pos, Move m, bool captureOrPromotion) {
// Test for a pawn pushed to 7th or a passed pawn move // Test for a pawn pushed to 7th or a passed pawn move
if (type_of(pos.piece_on(from_sq(m))) == PAWN) if (type_of(pos.piece_moved(m)) == PAWN)
{ {
Color c = pos.side_to_move(); Color c = pos.side_to_move();
if ( relative_rank(c, to_sq(m)) == RANK_7 if ( relative_rank(c, to_sq(m)) == RANK_7
@ -970,7 +970,7 @@ split_point_start: // At split points actual search starts from here
// but fixing this made program slightly weaker. // but fixing this made program slightly weaker.
Depth predictedDepth = newDepth - reduction<PvNode>(depth, moveCount); Depth predictedDepth = newDepth - reduction<PvNode>(depth, moveCount);
futilityValue = futilityBase + futility_margin(predictedDepth, moveCount) futilityValue = futilityBase + futility_margin(predictedDepth, moveCount)
+ H.gain(pos.piece_on(from_sq(move)), to_sq(move)); + H.gain(pos.piece_moved(move), to_sq(move));
if (futilityValue < beta) if (futilityValue < beta)
{ {
@ -1154,13 +1154,13 @@ split_point_start: // At split points actual search starts from here
// Increase history value of the cut-off move // Increase history value of the cut-off move
Value bonus = Value(int(depth) * int(depth)); Value bonus = Value(int(depth) * int(depth));
H.add(pos.piece_on(from_sq(move)), to_sq(move), bonus); H.add(pos.piece_moved(move), to_sq(move), bonus);
// Decrease history of all the other played non-capture moves // Decrease history of all the other played non-capture moves
for (int i = 0; i < playedMoveCount - 1; i++) for (int i = 0; i < playedMoveCount - 1; i++)
{ {
Move m = movesSearched[i]; Move m = movesSearched[i];
H.add(pos.piece_on(from_sq(m)), to_sq(m), -bonus); H.add(pos.piece_moved(m), to_sq(m), -bonus);
} }
} }
} }