mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-16 23:26:23 +08:00
Retire seeValues[] and move PieceValue[] out of Position
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
@@ -118,13 +118,13 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const History& h, S
|
|||||||
go_next_phase();
|
go_next_phase();
|
||||||
}
|
}
|
||||||
|
|
||||||
MovePicker::MovePicker(const Position& p, Move ttm, const History& h, int parentCapture)
|
MovePicker::MovePicker(const Position& p, Move ttm, const History& h, PieceType parentCapture)
|
||||||
: pos(p), H(h) {
|
: pos(p), H(h) {
|
||||||
|
|
||||||
assert (!pos.in_check());
|
assert (!pos.in_check());
|
||||||
|
|
||||||
// In ProbCut we consider only captures better than parent's move
|
// In ProbCut we consider only captures better than parent's move
|
||||||
captureThreshold = parentCapture;
|
captureThreshold = piece_value_midgame(Piece(parentCapture));
|
||||||
phasePtr = ProbCutTable;
|
phasePtr = ProbCutTable;
|
||||||
|
|
||||||
if ( ttm != MOVE_NONE
|
if ( ttm != MOVE_NONE
|
||||||
@@ -236,7 +236,7 @@ void MovePicker::score_captures() {
|
|||||||
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
for (MoveStack* cur = moves; cur != lastMove; cur++)
|
||||||
{
|
{
|
||||||
m = cur->move;
|
m = cur->move;
|
||||||
cur->score = pos.midgame_value_of_piece_on(move_to(m))
|
cur->score = piece_value_midgame(pos.piece_on(move_to(m)))
|
||||||
- pos.type_of_piece_on(move_from(m));
|
- pos.type_of_piece_on(move_from(m));
|
||||||
|
|
||||||
if (move_is_promotion(m))
|
if (move_is_promotion(m))
|
||||||
@@ -275,7 +275,7 @@ void MovePicker::score_evasions() {
|
|||||||
if ((seeScore = pos.see_sign(m)) < 0)
|
if ((seeScore = pos.see_sign(m)) < 0)
|
||||||
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.move_is_capture(m))
|
else if (pos.move_is_capture(m))
|
||||||
cur->score = pos.midgame_value_of_piece_on(move_to(m))
|
cur->score = piece_value_midgame(pos.piece_on(move_to(m)))
|
||||||
- pos.type_of_piece_on(move_from(m)) + History::MaxValue;
|
- pos.type_of_piece_on(move_from(m)) + History::MaxValue;
|
||||||
else
|
else
|
||||||
cur->score = H.value(pos.piece_on(move_from(m)), move_to(m));
|
cur->score = H.value(pos.piece_on(move_from(m)), move_to(m));
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class MovePicker {
|
|||||||
public:
|
public:
|
||||||
MovePicker(const Position&, Move, Depth, const History&, SearchStack*, Value);
|
MovePicker(const Position&, Move, Depth, const History&, SearchStack*, Value);
|
||||||
MovePicker(const Position&, Move, Depth, const History&, Square recaptureSq);
|
MovePicker(const Position&, Move, Depth, const History&, Square recaptureSq);
|
||||||
MovePicker(const Position&, Move, const History&, int parentCapture);
|
MovePicker(const Position&, Move, const History&, PieceType parentCapture);
|
||||||
Move get_next_move();
|
Move get_next_move();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ Key Position::zobExclusion;
|
|||||||
Score Position::PieceSquareTable[16][64];
|
Score Position::PieceSquareTable[16][64];
|
||||||
|
|
||||||
// Material values arrays, indexed by Piece
|
// Material values arrays, indexed by Piece
|
||||||
const Value Position::PieceValueMidgame[17] = {
|
const Value PieceValueMidgame[17] = {
|
||||||
VALUE_ZERO,
|
VALUE_ZERO,
|
||||||
PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
|
PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
|
||||||
RookValueMidgame, QueenValueMidgame, VALUE_ZERO,
|
RookValueMidgame, QueenValueMidgame, VALUE_ZERO,
|
||||||
@@ -54,7 +54,7 @@ const Value Position::PieceValueMidgame[17] = {
|
|||||||
RookValueMidgame, QueenValueMidgame
|
RookValueMidgame, QueenValueMidgame
|
||||||
};
|
};
|
||||||
|
|
||||||
const Value Position::PieceValueEndgame[17] = {
|
const Value PieceValueEndgame[17] = {
|
||||||
VALUE_ZERO,
|
VALUE_ZERO,
|
||||||
PawnValueEndgame, KnightValueEndgame, BishopValueEndgame,
|
PawnValueEndgame, KnightValueEndgame, BishopValueEndgame,
|
||||||
RookValueEndgame, QueenValueEndgame, VALUE_ZERO,
|
RookValueEndgame, QueenValueEndgame, VALUE_ZERO,
|
||||||
@@ -63,13 +63,6 @@ const Value Position::PieceValueEndgame[17] = {
|
|||||||
RookValueEndgame, QueenValueEndgame
|
RookValueEndgame, QueenValueEndgame
|
||||||
};
|
};
|
||||||
|
|
||||||
// Material values array used by SEE, indexed by PieceType
|
|
||||||
const Value Position::seeValues[] = {
|
|
||||||
VALUE_ZERO,
|
|
||||||
PawnValueMidgame, KnightValueMidgame, BishopValueMidgame,
|
|
||||||
RookValueMidgame, QueenValueMidgame, QueenValueMidgame*10
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@@ -1485,7 +1478,7 @@ int Position::see_sign(Move m) const {
|
|||||||
// Early return if SEE cannot be negative because captured piece value
|
// Early return if SEE cannot be negative because captured piece value
|
||||||
// is not less then capturing one. Note that king moves always return
|
// is not less then capturing one. Note that king moves always return
|
||||||
// here because king midgame value is set to 0.
|
// here because king midgame value is set to 0.
|
||||||
if (midgame_value_of_piece_on(to) >= midgame_value_of_piece_on(from))
|
if (piece_value_midgame(piece_on(to)) >= piece_value_midgame(piece_on(from)))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return see(m);
|
return see(m);
|
||||||
@@ -1534,7 +1527,7 @@ int Position::see(Move m) const {
|
|||||||
stm = opposite_color(color_of_piece_on(from));
|
stm = opposite_color(color_of_piece_on(from));
|
||||||
stmAttackers = attackers & pieces_of_color(stm);
|
stmAttackers = attackers & pieces_of_color(stm);
|
||||||
if (!stmAttackers)
|
if (!stmAttackers)
|
||||||
return seeValues[capturedType];
|
return PieceValueMidgame[capturedType];
|
||||||
|
|
||||||
// The destination square is defended, which makes things rather more
|
// The destination square is defended, which makes things rather more
|
||||||
// difficult to compute. We proceed by building up a "swap list" containing
|
// difficult to compute. We proceed by building up a "swap list" containing
|
||||||
@@ -1542,7 +1535,7 @@ int Position::see(Move m) const {
|
|||||||
// destination square, where the sides alternately capture, and always
|
// destination square, where the sides alternately capture, and always
|
||||||
// capture with the least valuable piece. After each capture, we look for
|
// capture with the least valuable piece. After each capture, we look for
|
||||||
// new X-ray attacks from behind the capturing piece.
|
// new X-ray attacks from behind the capturing piece.
|
||||||
swapList[0] = seeValues[capturedType];
|
swapList[0] = PieceValueMidgame[capturedType];
|
||||||
capturedType = type_of_piece_on(from);
|
capturedType = type_of_piece_on(from);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -1563,7 +1556,7 @@ int Position::see(Move m) const {
|
|||||||
|
|
||||||
// Add the new entry to the swap list
|
// Add the new entry to the swap list
|
||||||
assert(slIndex < 32);
|
assert(slIndex < 32);
|
||||||
swapList[slIndex] = -swapList[slIndex - 1] + seeValues[capturedType];
|
swapList[slIndex] = -swapList[slIndex - 1] + PieceValueMidgame[capturedType];
|
||||||
slIndex++;
|
slIndex++;
|
||||||
|
|
||||||
// Remember the value of the capturing piece, and change the side to
|
// Remember the value of the capturing piece, and change the side to
|
||||||
|
|||||||
@@ -133,8 +133,6 @@ public:
|
|||||||
Color color_of_piece_on(Square s) const;
|
Color color_of_piece_on(Square s) const;
|
||||||
bool square_is_empty(Square s) const;
|
bool square_is_empty(Square s) const;
|
||||||
bool square_is_occupied(Square s) const;
|
bool square_is_occupied(Square s) const;
|
||||||
Value midgame_value_of_piece_on(Square s) const;
|
|
||||||
Value endgame_value_of_piece_on(Square s) const;
|
|
||||||
|
|
||||||
// Side to move
|
// Side to move
|
||||||
Color side_to_move() const;
|
Color side_to_move() const;
|
||||||
@@ -213,7 +211,6 @@ public:
|
|||||||
// Static exchange evaluation
|
// Static exchange evaluation
|
||||||
int see(Move m) const;
|
int see(Move m) const;
|
||||||
int see_sign(Move m) const;
|
int see_sign(Move m) const;
|
||||||
static int see_value(PieceType pt);
|
|
||||||
|
|
||||||
// Accessing hash keys
|
// Accessing hash keys
|
||||||
Key get_key() const;
|
Key get_key() const;
|
||||||
@@ -312,9 +309,6 @@ private:
|
|||||||
static Key zobSideToMove;
|
static Key zobSideToMove;
|
||||||
static Score PieceSquareTable[16][64];
|
static Score PieceSquareTable[16][64];
|
||||||
static Key zobExclusion;
|
static Key zobExclusion;
|
||||||
static const Value seeValues[8];
|
|
||||||
static const Value PieceValueMidgame[17];
|
|
||||||
static const Value PieceValueEndgame[17];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline int64_t Position::nodes_searched() const {
|
inline int64_t Position::nodes_searched() const {
|
||||||
@@ -345,14 +339,6 @@ inline bool Position::square_is_occupied(Square s) const {
|
|||||||
return !square_is_empty(s);
|
return !square_is_empty(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value Position::midgame_value_of_piece_on(Square s) const {
|
|
||||||
return PieceValueMidgame[piece_on(s)];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Value Position::endgame_value_of_piece_on(Square s) const {
|
|
||||||
return PieceValueEndgame[piece_on(s)];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Color Position::side_to_move() const {
|
inline Color Position::side_to_move() const {
|
||||||
return sideToMove;
|
return sideToMove;
|
||||||
}
|
}
|
||||||
@@ -474,10 +460,6 @@ inline bool Position::square_is_weak(Square s, Color c) const {
|
|||||||
return !(pieces(PAWN, opposite_color(c)) & attack_span_mask(c, s));
|
return !(pieces(PAWN, opposite_color(c)) & attack_span_mask(c, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int Position::see_value(PieceType pt) {
|
|
||||||
return seeValues[pt];
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Key Position::get_key() const {
|
inline Key Position::get_key() const {
|
||||||
return st->key;
|
return st->key;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -318,7 +318,7 @@ namespace {
|
|||||||
if ( captureOrPromotion
|
if ( captureOrPromotion
|
||||||
&& pos.type_of_piece_on(move_to(m)) != PAWN
|
&& pos.type_of_piece_on(move_to(m)) != PAWN
|
||||||
&& ( pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK)
|
&& ( pos.non_pawn_material(WHITE) + pos.non_pawn_material(BLACK)
|
||||||
- pos.midgame_value_of_piece_on(move_to(m)) == VALUE_ZERO)
|
- piece_value_midgame(pos.piece_on(move_to(m))) == VALUE_ZERO)
|
||||||
&& !move_is_special(m))
|
&& !move_is_special(m))
|
||||||
{
|
{
|
||||||
result += PawnEndgameExtension[PvNode];
|
result += PawnEndgameExtension[PvNode];
|
||||||
@@ -916,7 +916,7 @@ namespace {
|
|||||||
|
|
||||||
assert(rdepth >= ONE_PLY);
|
assert(rdepth >= ONE_PLY);
|
||||||
|
|
||||||
MovePicker mp(pos, ttMove, H, Position::see_value(pos.captured_piece_type()));
|
MovePicker mp(pos, ttMove, H, pos.captured_piece_type());
|
||||||
CheckInfo ci(pos);
|
CheckInfo ci(pos);
|
||||||
|
|
||||||
while ((move = mp.get_next_move()) != MOVE_NONE)
|
while ((move = mp.get_next_move()) != MOVE_NONE)
|
||||||
@@ -1412,7 +1412,7 @@ split_point_start: // At split points actual search starts from here
|
|||||||
&& !pos.move_is_passed_pawn_push(move))
|
&& !pos.move_is_passed_pawn_push(move))
|
||||||
{
|
{
|
||||||
futilityValue = futilityBase
|
futilityValue = futilityBase
|
||||||
+ pos.endgame_value_of_piece_on(move_to(move))
|
+ piece_value_endgame(pos.piece_on(move_to(move)))
|
||||||
+ (move_is_ep(move) ? PawnValueEndgame : VALUE_ZERO);
|
+ (move_is_ep(move) ? PawnValueEndgame : VALUE_ZERO);
|
||||||
|
|
||||||
if (futilityValue < alpha)
|
if (futilityValue < alpha)
|
||||||
@@ -1540,7 +1540,7 @@ split_point_start: // At split points actual search starts from here
|
|||||||
while (b)
|
while (b)
|
||||||
{
|
{
|
||||||
victimSq = pop_1st_bit(&b);
|
victimSq = pop_1st_bit(&b);
|
||||||
futilityValue = futilityBase + pos.endgame_value_of_piece_on(victimSq);
|
futilityValue = futilityBase + piece_value_endgame(pos.piece_on(victimSq));
|
||||||
|
|
||||||
// Note that here we generate illegal "double move"!
|
// Note that here we generate illegal "double move"!
|
||||||
if ( futilityValue >= beta
|
if ( futilityValue >= beta
|
||||||
@@ -1665,7 +1665,7 @@ split_point_start: // At split points actual search starts from here
|
|||||||
// Case 2: If the threatened piece has value less than or equal to the
|
// Case 2: If the threatened piece has value less than or equal to the
|
||||||
// value of the threatening piece, don't prune moves which defend it.
|
// value of the threatening piece, don't prune moves which defend it.
|
||||||
if ( pos.move_is_capture(threat)
|
if ( pos.move_is_capture(threat)
|
||||||
&& ( pos.midgame_value_of_piece_on(tfrom) >= pos.midgame_value_of_piece_on(tto)
|
&& ( piece_value_midgame(pos.piece_on(tfrom)) >= piece_value_midgame(pos.piece_on(tto))
|
||||||
|| pos.type_of_piece_on(tfrom) == KING)
|
|| pos.type_of_piece_on(tfrom) == KING)
|
||||||
&& pos.move_attacks_square(m, tto))
|
&& pos.move_attacks_square(m, tto))
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
11
src/types.h
11
src/types.h
@@ -337,6 +337,17 @@ 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);
|
||||||
|
|
||||||
|
extern const Value PieceValueMidgame[17];
|
||||||
|
extern const Value PieceValueEndgame[17];
|
||||||
|
|
||||||
|
inline Value piece_value_midgame(Piece p) {
|
||||||
|
return PieceValueMidgame[p];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Value piece_value_endgame(Piece p) {
|
||||||
|
return PieceValueEndgame[p];
|
||||||
|
}
|
||||||
|
|
||||||
inline Value value_mate_in(int ply) {
|
inline Value value_mate_in(int ply) {
|
||||||
return VALUE_MATE - ply;
|
return VALUE_MATE - ply;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user