Skip to content

Commit 0c9568c

Browse files
authored
Merge pull request official-stockfish#511 from IIvec/master
New master
2 parents 7ef2867 + 06cc341 commit 0c9568c

File tree

6 files changed

+30
-25
lines changed

6 files changed

+30
-25
lines changed

src/evaluate.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ namespace {
162162
// supported by a pawn. If the minor piece occupies an outpost square
163163
// then score is doubled.
164164
const Score Outpost[][2] = {
165-
{ S(22, 6), S(33, 9) }, // Knight
166-
{ S( 9, 2), S(14, 4) } // Bishop
165+
{ S(22, 6), S(36,12) }, // Knight
166+
{ S( 9, 2), S(15, 5) } // Bishop
167167
};
168168

169169
// RookOnFile[semiopen/open] contains bonuses for each rook when there is no
@@ -214,6 +214,7 @@ namespace {
214214
const Score ThreatBySafePawn = S(182,175);
215215
const Score ThreatByRank = S( 16, 3);
216216
const Score Hanging = S( 48, 27);
217+
const Score WeakUnopposedPawn = S( 5, 25);
217218
const Score ThreatByPawnPush = S( 38, 22);
218219
const Score HinderPassedPawn = S( 7, 0);
219220
const Score TrappedBishopA1H1 = S( 50, 50);
@@ -593,6 +594,10 @@ namespace {
593594
score += ThreatByKing[more_than_one(b)];
594595
}
595596

597+
// Bonus for opponent unopposed weak pawns
598+
if (pos.pieces(Us, ROOK, QUEEN))
599+
score += WeakUnopposedPawn * pe->weak_unopposed(Them);
600+
596601
// Find squares where our pawns can push on the next move
597602
b = shift<Up>(pos.pieces(Us, PAWN)) & ~pos.pieces();
598603
b |= shift<Up>(b & TRank3BB) & ~pos.pieces();

src/pawns.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ namespace {
3131
#define V Value
3232
#define S(mg, eg) make_score(mg, eg)
3333

34-
// Isolated pawn penalty by opposed flag
35-
const Score Isolated[] = { S(27, 30), S(13, 18) };
34+
// Isolated pawn penalty
35+
const Score Isolated = S(13, 18);
3636

37-
// Backward pawn penalty by opposed flag
38-
const Score Backward[] = { S(40, 26), S(24, 12) };
37+
// Backward pawn penalty
38+
const Score Backward = S(24, 12);
3939

4040
// Connected pawn bonus by opposed, phalanx, #support and rank
4141
Score Connected[2][2][3][RANK_NB];
@@ -109,7 +109,7 @@ namespace {
109109
Bitboard ourPawns = pos.pieces( Us, PAWN);
110110
Bitboard theirPawns = pos.pieces(Them, PAWN);
111111

112-
e->passedPawns[Us] = e->pawnAttacksSpan[Us] = 0;
112+
e->passedPawns[Us] = e->pawnAttacksSpan[Us] = e->weakUnopposed[Us] = 0;
113113
e->semiopenFiles[Us] = 0xFF;
114114
e->kingSquares[Us] = SQ_NONE;
115115
e->pawnAttacks[Us] = shift<Right>(ourPawns) | shift<Left>(ourPawns);
@@ -177,10 +177,10 @@ namespace {
177177
score += Connected[opposed][!!phalanx][popcount(supported)][relative_rank(Us, s)];
178178

179179
else if (!neighbours)
180-
score -= Isolated[opposed];
180+
score -= Isolated, e->weakUnopposed[Us] += !opposed;
181181

182182
else if (backward)
183-
score -= Backward[opposed];
183+
score -= Backward, e->weakUnopposed[Us] += !opposed;
184184

185185
if (doubled && !supported)
186186
score -= Doubled;

src/pawns.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct Entry {
3737
Bitboard pawn_attacks(Color c) const { return pawnAttacks[c]; }
3838
Bitboard passed_pawns(Color c) const { return passedPawns[c]; }
3939
Bitboard pawn_attacks_span(Color c) const { return pawnAttacksSpan[c]; }
40+
int weak_unopposed(Color c) const { return weakUnopposed[c]; }
4041
int pawn_asymmetry() const { return asymmetry; }
4142
int open_files() const { return openFiles; }
4243

@@ -71,6 +72,7 @@ struct Entry {
7172
Bitboard pawnAttacksSpan[COLOR_NB];
7273
Square kingSquares[COLOR_NB];
7374
Score kingSafety[COLOR_NB];
75+
int weakUnopposed[COLOR_NB];
7476
int castlingRights[COLOR_NB];
7577
int semiopenFiles[COLOR_NB];
7678
int pawnsOnSquares[COLOR_NB][COLOR_NB]; // [color][light/dark squares]

src/position.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ Position& Position::set(const string& fenStr, bool isChess960, StateInfo* si, Th
272272
// 5-6. Halfmove clock and fullmove number
273273
ss >> std::skipws >> st->rule50 >> gamePly;
274274

275-
// Convert from fullmove starting from 1 to ply starting from 0,
275+
// Convert from fullmove starting from 1 to gamePly starting from 0,
276276
// handle also common incorrect FEN with fullmove = 0.
277277
gamePly = std::max(2 * (gamePly - 1), 0) + (sideToMove == BLACK);
278278

@@ -1071,11 +1071,10 @@ bool Position::is_draw(int ply) const {
10711071
{
10721072
stp = stp->previous->previous;
10731073

1074-
// At root position ply is 1, so return a draw score if a position
1075-
// repeats once earlier but strictly after the root, or repeats twice
1076-
// before or at the root.
1074+
// Return a draw score if a position repeats once earlier but strictly
1075+
// after the root, or repeats twice before or at the root.
10771076
if ( stp->key == st->key
1078-
&& ++cnt + (ply - 1 > i) == 2)
1077+
&& ++cnt + (ply > i) == 2)
10791078
return true;
10801079
}
10811080

src/search.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void MainThread::search() {
325325

326326
void Thread::search() {
327327

328-
Stack stack[MAX_PLY+7], *ss = stack+4; // To allow referencing (ss-4) and (ss+2)
328+
Stack stack[MAX_PLY+7], *ss = stack+4; // To reference from (ss-4) to (ss+2)
329329
Value bestValue, alpha, beta, delta;
330330
Move easyMove = MOVE_NONE;
331331
MainThread* mainThread = (this == Threads.main() ? Threads.main() : nullptr);
@@ -528,7 +528,7 @@ namespace {
528528
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode, bool skipEarlyPruning) {
529529

530530
const bool PvNode = NT == PV;
531-
const bool rootNode = PvNode && (ss-1)->ply == 0;
531+
const bool rootNode = PvNode && ss->ply == 0;
532532

533533
assert(-VALUE_INFINITE <= alpha && alpha < beta && beta <= VALUE_INFINITE);
534534
assert(PvNode || (alpha == beta - 1));
@@ -554,15 +554,14 @@ namespace {
554554
moveCount = quietCount = ss->moveCount = 0;
555555
ss->statScore = 0;
556556
bestValue = -VALUE_INFINITE;
557-
ss->ply = (ss-1)->ply + 1;
558557

559558
// Check for the available remaining time
560559
if (thisThread == Threads.main())
561560
static_cast<MainThread*>(thisThread)->check_time();
562561

563-
// Used to send selDepth info to GUI
564-
if (PvNode && thisThread->selDepth < ss->ply)
565-
thisThread->selDepth = ss->ply;
562+
// Used to send selDepth info to GUI (selDepth counts from 1, ply from 0)
563+
if (PvNode && thisThread->selDepth < ss->ply + 1)
564+
thisThread->selDepth = ss->ply + 1;
566565

567566
if (!rootNode)
568567
{
@@ -585,6 +584,7 @@ namespace {
585584

586585
assert(0 <= ss->ply && ss->ply < MAX_PLY);
587586

587+
(ss+1)->ply = ss->ply + 1;
588588
ss->currentMove = (ss+1)->excludedMove = bestMove = MOVE_NONE;
589589
ss->contHistory = &thisThread->contHistory[NO_PIECE][0];
590590
(ss+2)->killers[0] = (ss+2)->killers[1] = MOVE_NONE;
@@ -655,8 +655,8 @@ namespace {
655655
|| (v < -drawScore && ttValue > -VALUE_KNOWN_WIN)
656656
|| (v > drawScore && ttValue < VALUE_KNOWN_WIN))
657657
{
658-
value = v < -drawScore ? -VALUE_MATE_IN_MAX_PLY + ss->ply + (pos.non_pawn_material(pos.side_to_move()) - pos.non_pawn_material(~pos.side_to_move())) / 256
659-
: v > drawScore ? VALUE_MATE_IN_MAX_PLY - ss->ply + (pos.non_pawn_material(pos.side_to_move()) - pos.non_pawn_material(~pos.side_to_move())) / 256
658+
value = v < -drawScore ? -VALUE_MATE_IN_MAX_PLY + ss->ply + 1 + (pos.non_pawn_material(pos.side_to_move()) - pos.non_pawn_material(~pos.side_to_move())) / 256
659+
: v > drawScore ? VALUE_MATE_IN_MAX_PLY - ss->ply - 1 + (pos.non_pawn_material(pos.side_to_move()) - pos.non_pawn_material(~pos.side_to_move())) / 256
660660
: VALUE_DRAW + v * drawScore;
661661

662662
tte->save(posKey, value_to_tt(value, ss->ply),
@@ -1185,7 +1185,7 @@ namespace {
11851185
}
11861186

11871187
ss->currentMove = bestMove = MOVE_NONE;
1188-
ss->ply = (ss-1)->ply + 1;
1188+
(ss+1)->ply = ss->ply + 1;
11891189
moveCount = 0;
11901190

11911191
// Check for an instant draw or if the maximum ply has been reached
@@ -1200,7 +1200,6 @@ namespace {
12001200
// only two types of depth in TT: DEPTH_QS_CHECKS or DEPTH_QS_NO_CHECKS.
12011201
ttDepth = InCheck || depth >= DEPTH_QS_CHECKS ? DEPTH_QS_CHECKS
12021202
: DEPTH_QS_NO_CHECKS;
1203-
12041203
// Transposition table lookup
12051204
posKey = pos.key();
12061205
tte = TT.probe(posKey, ttHit);

src/thread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void Thread::idle_loop() {
111111

112112

113113
/// ThreadPool::init() creates and launches the threads that will go
114-
/// immediately to sleep in idle_loop. We cannot use the c'tor because
114+
/// immediately to sleep in idle_loop. We cannot use the constructor because
115115
/// Threads is a static object and we need a fully initialized engine at
116116
/// this point due to allocation of Endgames in the Thread constructor.
117117

0 commit comments

Comments
 (0)