Skip to content

Commit 3322349

Browse files
peregrineshahinDisservin
authored andcommitted
Simplify pieceValue to one phase.
Simplifies the usage of pieceValues to mg values with the exception of pawnValues, After the removal of PSQT. passed STC: https://tests.stockfishchess.org/tests/view/64d147845b17f7c21c0dd86c LLR: 2.94 (-2.94,2.94) <-1.75,0.25> Total: 197248 W: 50168 L: 50125 D: 96955 Ptnml(0-2): 651, 23029, 51222, 23070, 652 passed LTC: https://tests.stockfishchess.org/tests/view/64d212de5b17f7c21c0debbb LLR: 2.94 (-2.94,2.94) <-1.75,0.25> Total: 181170 W: 45949 L: 45893 D: 89328 Ptnml(0-2): 84, 19656, 51052, 19706, 87 closes #4734 Bench: 1494401
1 parent 495852f commit 3322349

File tree

5 files changed

+24
-32
lines changed

5 files changed

+24
-32
lines changed

src/movepick.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void MovePicker::score() {
122122

123123
for (auto& m : *this)
124124
if constexpr (Type == CAPTURES)
125-
m.value = (7 * int(PieceValue[MG][pos.piece_on(to_sq(m))])
125+
m.value = (7 * int(PieceValue[pos.piece_on(to_sq(m))])
126126
+ (*captureHistory)[pos.moved_piece(m)][to_sq(m)][type_of(pos.piece_on(to_sq(m)))]) / 16;
127127

128128
else if constexpr (Type == QUIETS)
@@ -165,7 +165,7 @@ void MovePicker::score() {
165165
else // Type == EVASIONS
166166
{
167167
if (pos.capture_stage(m))
168-
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
168+
m.value = PieceValue[pos.piece_on(to_sq(m))]
169169
- Value(type_of(pos.moved_piece(m)))
170170
+ (1 << 28);
171171
else

src/position.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ void Position::set_state() const {
347347
st->key ^= Zobrist::psq[pc][s];
348348

349349
if (type_of(pc) != KING && type_of(pc) != PAWN)
350-
st->nonPawnMaterial[color_of(pc)] += PieceValue[MG][pc];
350+
st->nonPawnMaterial[color_of(pc)] += PieceValue[pc];
351351
}
352352

353353
if (st->epSquare != SQ_NONE)
@@ -742,7 +742,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
742742
}
743743
}
744744
else
745-
st->nonPawnMaterial[them] -= PieceValue[MG][captured];
745+
st->nonPawnMaterial[them] -= PieceValue[captured];
746746

747747
dp.dirty_num = 2; // 1 piece moved, 1 piece captured
748748
dp.piece[1] = captured;
@@ -822,7 +822,7 @@ void Position::do_move(Move m, StateInfo& newSt, bool givesCheck) {
822822
^ Zobrist::psq[pc][pieceCount[pc]];
823823

824824
// Update material
825-
st->nonPawnMaterial[us] += PieceValue[MG][promotion];
825+
st->nonPawnMaterial[us] += PieceValue[promotion];
826826
}
827827

828828
// Reset rule 50 draw counter
@@ -1048,11 +1048,11 @@ bool Position::see_ge(Move m, Bitboard& occupied, Value threshold) const {
10481048

10491049
Square from = from_sq(m), to = to_sq(m);
10501050

1051-
int swap = PieceValue[MG][piece_on(to)] - threshold;
1051+
int swap = PieceValue[piece_on(to)] - threshold;
10521052
if (swap < 0)
10531053
return false;
10541054

1055-
swap = PieceValue[MG][piece_on(from)] - swap;
1055+
swap = PieceValue[piece_on(from)] - swap;
10561056
if (swap <= 0)
10571057
return true;
10581058

@@ -1089,7 +1089,7 @@ bool Position::see_ge(Move m, Bitboard& occupied, Value threshold) const {
10891089
if ((bb = stmAttackers & pieces(PAWN)))
10901090
{
10911091
occupied ^= least_significant_square_bb(bb);
1092-
if ((swap = PawnValueMg - swap) < res)
1092+
if ((swap = PawnValue - swap) < res)
10931093
break;
10941094

10951095
attackers |= attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN);
@@ -1098,14 +1098,14 @@ bool Position::see_ge(Move m, Bitboard& occupied, Value threshold) const {
10981098
else if ((bb = stmAttackers & pieces(KNIGHT)))
10991099
{
11001100
occupied ^= least_significant_square_bb(bb);
1101-
if ((swap = KnightValueMg - swap) < res)
1101+
if ((swap = KnightValue - swap) < res)
11021102
break;
11031103
}
11041104

11051105
else if ((bb = stmAttackers & pieces(BISHOP)))
11061106
{
11071107
occupied ^= least_significant_square_bb(bb);
1108-
if ((swap = BishopValueMg - swap) < res)
1108+
if ((swap = BishopValue - swap) < res)
11091109
break;
11101110

11111111
attackers |= attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN);
@@ -1114,7 +1114,7 @@ bool Position::see_ge(Move m, Bitboard& occupied, Value threshold) const {
11141114
else if ((bb = stmAttackers & pieces(ROOK)))
11151115
{
11161116
occupied ^= least_significant_square_bb(bb);
1117-
if ((swap = RookValueMg - swap) < res)
1117+
if ((swap = RookValue - swap) < res)
11181118
break;
11191119

11201120
attackers |= attacks_bb<ROOK>(to, occupied) & pieces(ROOK, QUEEN);
@@ -1123,7 +1123,7 @@ bool Position::see_ge(Move m, Bitboard& occupied, Value threshold) const {
11231123
else if ((bb = stmAttackers & pieces(QUEEN)))
11241124
{
11251125
occupied ^= least_significant_square_bb(bb);
1126-
if ((swap = QueenValueMg - swap) < res)
1126+
if ((swap = QueenValue - swap) < res)
11271127
break;
11281128

11291129
attackers |= (attacks_bb<BISHOP>(to, occupied) & pieces(BISHOP, QUEEN))

src/search.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ namespace {
985985
if ( !givesCheck
986986
&& lmrDepth < 7
987987
&& !ss->inCheck
988-
&& ss->staticEval + 197 + 248 * lmrDepth + PieceValue[EG][pos.piece_on(to_sq(move))]
988+
&& ss->staticEval + 197 + 248 * lmrDepth + PieceValue[pos.piece_on(to_sq(move))]
989989
+ captureHistory[movedPiece][to_sq(move)][type_of(pos.piece_on(to_sq(move)))] / 7 < alpha)
990990
continue;
991991

@@ -1535,7 +1535,7 @@ namespace {
15351535
if (moveCount > 2)
15361536
continue;
15371537

1538-
futilityValue = futilityBase + PieceValue[EG][pos.piece_on(to_sq(move))];
1538+
futilityValue = futilityBase + PieceValue[pos.piece_on(to_sq(move))];
15391539

15401540
if (futilityValue <= alpha)
15411541
{
@@ -1783,7 +1783,7 @@ namespace {
17831783

17841784
// RootMoves are already sorted by score in descending order
17851785
Value topScore = rootMoves[0].score;
1786-
int delta = std::min(topScore - rootMoves[multiPV - 1].score, PawnValueMg);
1786+
int delta = std::min(topScore - rootMoves[multiPV - 1].score, PawnValue);
17871787
int maxScore = -VALUE_INFINITE;
17881788
double weakness = 120 - 2 * level;
17891789

src/syzygy/tbprobe.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,9 +1573,9 @@ bool Tablebases::root_probe(Position& pos, Search::RootMoves& rootMoves) {
15731573
// 1 cp to cursed wins and let it grow to 49 cp as the positions gets
15741574
// closer to a real win.
15751575
m.tbScore = r >= bound ? VALUE_MATE - MAX_PLY - 1
1576-
: r > 0 ? Value((std::max( 3, r - (MAX_DTZ - 200)) * int(PawnValueEg)) / 200)
1576+
: r > 0 ? Value((std::max( 3, r - (MAX_DTZ - 200)) * int(PawnValue)) / 200)
15771577
: r == 0 ? VALUE_DRAW
1578-
: r > -bound ? Value((std::min(-3, r + (MAX_DTZ - 200)) * int(PawnValueEg)) / 200)
1578+
: r > -bound ? Value((std::min(-3, r + (MAX_DTZ - 200)) * int(PawnValue)) / 200)
15791579
: -VALUE_MATE + MAX_PLY + 1;
15801580
}
15811581

src/types.h

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,6 @@ enum CastlingRights {
153153
CASTLING_RIGHT_NB = 16
154154
};
155155

156-
enum Phase {
157-
MG = 0, EG = 1, PHASE_NB = 2
158-
};
159-
160156
enum Bound {
161157
BOUND_NONE,
162158
BOUND_UPPER,
@@ -180,11 +176,11 @@ enum Value : int {
180176
// In the code, we make the assumption that these values
181177
// are such that non_pawn_material() can be used to uniquely
182178
// identify the material on the board.
183-
PawnValueMg = 126, PawnValueEg = 208,
184-
KnightValueMg = 781, KnightValueEg = 854,
185-
BishopValueMg = 825, BishopValueEg = 915,
186-
RookValueMg = 1276, RookValueEg = 1380,
187-
QueenValueMg = 2538, QueenValueEg = 2682,
179+
PawnValue = 208,
180+
KnightValue = 781,
181+
BishopValue = 825,
182+
RookValue = 1276,
183+
QueenValue = 2538,
188184
};
189185

190186
enum PieceType {
@@ -200,12 +196,8 @@ enum Piece {
200196
PIECE_NB = 16
201197
};
202198

203-
constexpr Value PieceValue[PHASE_NB][PIECE_NB] = {
204-
{ VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg, VALUE_ZERO, VALUE_ZERO,
205-
VALUE_ZERO, PawnValueMg, KnightValueMg, BishopValueMg, RookValueMg, QueenValueMg, VALUE_ZERO, VALUE_ZERO },
206-
{ VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg, VALUE_ZERO, VALUE_ZERO,
207-
VALUE_ZERO, PawnValueEg, KnightValueEg, BishopValueEg, RookValueEg, QueenValueEg, VALUE_ZERO, VALUE_ZERO }
208-
};
199+
constexpr Value PieceValue[PIECE_NB] = { VALUE_ZERO, PawnValue, KnightValue, BishopValue, RookValue, QueenValue, VALUE_ZERO, VALUE_ZERO,
200+
VALUE_ZERO, PawnValue, KnightValue, BishopValue, RookValue, QueenValue, VALUE_ZERO, VALUE_ZERO };
209201

210202
using Depth = int;
211203

0 commit comments

Comments
 (0)