From 2f465927363e3e753dfb65d67f9b126afc34f4fa Mon Sep 17 00:00:00 2001 From: snicolet Date: Fri, 20 Feb 2015 19:56:57 +0000 Subject: [PATCH 1/3] Mobile phalanxes Try to create mobile phalanxes STC: LLR: 2.97 (-2.94,2.94) [-1.50,4.50] Total: 52393 W: 10912 L: 10656 D: 30825 LTC: LLR: 2.96 (-2.94,2.94) [0.00,6.00] Total: 30398 W: 5315 L: 5063 D: 20020 Bench: 8253813 Resolves #261 --- src/evaluate.cpp | 2 +- src/pawns.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 7ff7dfc1..8c5ecc36 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -163,7 +163,7 @@ namespace { const Score Unstoppable = S( 0, 20); const Score Hanging = S(31, 26); const Score PawnAttackThreat = S(20, 20); - const Score PawnSafePush = S( 5 , 5); + const Score PawnSafePush = S( 5, 5); // Penalty for a bishop on a1/h1 (a8/h8 for black) which is trapped by // a friendly pawn on b2/g2 (b7/g7 for black). This can obviously only diff --git a/src/pawns.cpp b/src/pawns.cpp index d66233ca..41c9e15d 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -227,7 +227,8 @@ void init() for (Rank r = RANK_2; r < RANK_8; ++r) { int bonus = Seed[r] + (phalanx ? (Seed[r + 1] - Seed[r]) / 2 : 0); - Connected[opposed][phalanx][r] = make_score(bonus / 2, bonus >> opposed); + bonus >>= opposed; + Connected[opposed][phalanx][r] = make_score( 3 * bonus / 2, bonus); } } From 41ccc885ece3f49139eee113493c3a0fdc51e4bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicolet?= Date: Thu, 19 Feb 2015 21:33:07 +0100 Subject: [PATCH 2/3] Fix comment for kingAdjacentZoneAttacksCount The comment for kingAdjacentZoneAttacksCount[] was bogus, using reversed semantics for color. No functional change Resolves #262 --- src/evaluate.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 8c5ecc36..77096c9b 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -61,11 +61,11 @@ namespace { // KingAttackWeights array. int kingAttackersWeight[COLOR_NB]; - // kingAdjacentZoneAttacksCount[color] is the number of attacks to squares - // directly adjacent to the king of the given color. Pieces which attack - // more than one square are counted multiple times. For instance, if black's - // king is on g8 and there's a white knight on g5, this knight adds - // 2 to kingAdjacentZoneAttacksCount[BLACK]. + // kingAdjacentZoneAttacksCount[color] is the number of attacks by the given + // color to squares directly adjacent to the enemy king. Pieces which attack + // more than one square are counted multiple times. For instance, if there is + // a white knight on g5 and black's king is on g8, this white knight adds 2 + // to kingAdjacentZoneAttacksCount[WHITE]. int kingAdjacentZoneAttacksCount[COLOR_NB]; Bitboard pinnedPieces[COLOR_NB]; From 5fd5453e594ee6cadf4a3c502bc53d28cfe5aa8b Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 21 Feb 2015 11:33:03 +0100 Subject: [PATCH 3/3] Further refine SMP code Backported from C++11 branch: https://github.com/official-stockfish/Stockfish/commit/7ff965eebfbc17d2b https://github.com/official-stockfish/Stockfish/commit/e74c2df907d5336d3d2b Fully verified it is equivalent to master (see log msg of individual commits for details). No functional change. --- src/search.cpp | 19 +++++++++---------- src/thread.cpp | 2 +- src/thread.h | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 15b93a72..6e0552be 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -1524,9 +1524,9 @@ void Thread::idle_loop() { // Pointer 'this_sp' is not null only if we are called from split(), and not // at the thread creation. This means we are the split point's master. - SplitPoint* this_sp = splitPointsSize ? activeSplitPoint : NULL; + SplitPoint* this_sp = activeSplitPoint; - assert(!this_sp || (this_sp->masterThread == this && searching)); + assert(!this_sp || (this_sp->master == this && searching)); while (!exit) { @@ -1536,6 +1536,7 @@ void Thread::idle_loop() { Threads.mutex.lock(); assert(activeSplitPoint); + SplitPoint* sp = activeSplitPoint; Threads.mutex.unlock(); @@ -1574,11 +1575,11 @@ void Thread::idle_loop() { // Wake up the master thread so to allow it to return from the idle // loop in case we are the last slave of the split point. - if ( this != sp->masterThread - && sp->slavesMask.none()) + if (this != sp->master && sp->slavesMask.none()) { - assert(!sp->masterThread->searching); - sp->masterThread->notify_one(); + assert(!sp->master->searching); + + sp->master->notify_one(); } // After releasing the lock we can't access any SplitPoint related data @@ -1589,7 +1590,6 @@ void Thread::idle_loop() { // Try to late join to another split point if none of its slaves has // already finished. SplitPoint* bestSp = NULL; - Thread* bestThread = NULL; int bestScore = INT_MAX; for (size_t i = 0; i < Threads.size(); ++i) @@ -1617,7 +1617,6 @@ void Thread::idle_loop() { if (score < bestScore) { bestSp = sp; - bestThread = Threads[i]; bestScore = score; } } @@ -1633,7 +1632,7 @@ void Thread::idle_loop() { if ( sp->allSlavesSearching && sp->slavesMask.count() < MAX_SLAVES_PER_SPLITPOINT - && available_to(bestThread)) + && available_to(sp->master)) { sp->slavesMask.set(idx); activeSplitPoint = sp; @@ -1645,7 +1644,7 @@ void Thread::idle_loop() { } } - // Grab the lock to avoid races with Thread::notify_one() + // Avoid races with notify_one() fired from last slave of the split point mutex.lock(); // If we are master and all slaves have finished then exit idle_loop diff --git a/src/thread.cpp b/src/thread.cpp index 18870021..786258a2 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -153,7 +153,7 @@ void Thread::split(Position& pos, Stack* ss, Value alpha, Value beta, Value* bes // Pick and init the next available split point SplitPoint& sp = splitPoints[splitPointsSize]; - sp.masterThread = this; + sp.master = this; sp.parentSplitPoint = activeSplitPoint; sp.slavesMask = 0, sp.slavesMask.set(idx); sp.depth = depth; diff --git a/src/thread.h b/src/thread.h index 04e9a370..f530913c 100644 --- a/src/thread.h +++ b/src/thread.h @@ -72,7 +72,7 @@ struct SplitPoint { // Const data after split point has been setup const Position* pos; Search::Stack* ss; - Thread* masterThread; + Thread* master; Depth depth; Value beta; int nodeType;