Skip to content

Commit c0fd743

Browse files
committed
Formatting in previous patch
And further simplify MovePicker API. Revert 'cmh' to a reference because it is always set. bench: 7378965 (No functional change)
1 parent d42c2e0 commit c0fd743

File tree

4 files changed

+54
-54
lines changed

4 files changed

+54
-54
lines changed

src/movepick.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,21 @@ namespace {
6767
/// search captures, promotions, and some checks) and how important good move
6868
/// ordering is at the current node.
6969

70-
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h,
71-
Move cm, Search::Stack* s)
72-
: pos(p), history(h), ss(s), countermove(cm), depth(d) {
70+
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, Search::Stack* s)
71+
: pos(p), ss(s), depth(d) {
7372

7473
assert(d > DEPTH_ZERO);
7574

75+
Square prevSq = to_sq((ss-1)->currentMove);
76+
countermove = pos.this_thread()->counterMoves[pos.piece_on(prevSq)][prevSq];
77+
7678
stage = pos.checkers() ? EVASION : MAIN_SEARCH;
7779
ttMove = ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE;
7880
endMoves += (ttMove != MOVE_NONE);
7981
}
8082

81-
MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
82-
const HistoryStats& h, Square s)
83-
: pos(p), history(h) {
83+
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, Square s)
84+
: pos(p) {
8485

8586
assert(d <= DEPTH_ZERO);
8687

@@ -104,8 +105,8 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d,
104105
endMoves += (ttMove != MOVE_NONE);
105106
}
106107

107-
MovePicker::MovePicker(const Position& p, Move ttm, const HistoryStats& h, Value th)
108-
: pos(p), history(h), threshold(th) {
108+
MovePicker::MovePicker(const Position& p, Move ttm, Value th)
109+
: pos(p), threshold(th) {
109110

110111
assert(!pos.checkers());
111112

@@ -140,21 +141,25 @@ void MovePicker::score<CAPTURES>() {
140141
template<>
141142
void MovePicker::score<QUIETS>() {
142143

143-
const CounterMoveStats* cmh = (ss-1)->cms;
144-
const CounterMoveStats* fmh = (ss-2)->cms;
145-
const CounterMoveStats* fmh2 = (ss-4)->cms;
144+
const HistoryStats& history = pos.this_thread()->history;
145+
146+
const CounterMoveStats* cm = (ss-1)->counterMoves;
147+
const CounterMoveStats* fm = (ss-2)->counterMoves;
148+
const CounterMoveStats* f2 = (ss-4)->counterMoves;
149+
146150
for (auto& m : *this)
147-
m.value = history[pos.moved_piece(m)][to_sq(m)]
148-
+ (cmh ? (*cmh )[pos.moved_piece(m)][to_sq(m)] : VALUE_ZERO)
149-
+ (fmh ? (*fmh )[pos.moved_piece(m)][to_sq(m)] : VALUE_ZERO)
150-
+ (fmh2 ? (*fmh2)[pos.moved_piece(m)][to_sq(m)] : VALUE_ZERO);
151+
m.value = history[pos.moved_piece(m)][to_sq(m)]
152+
+ (cm ? (*cm)[pos.moved_piece(m)][to_sq(m)] : VALUE_ZERO)
153+
+ (fm ? (*fm)[pos.moved_piece(m)][to_sq(m)] : VALUE_ZERO)
154+
+ (f2 ? (*f2)[pos.moved_piece(m)][to_sq(m)] : VALUE_ZERO);
151155
}
152156

153157
template<>
154158
void MovePicker::score<EVASIONS>() {
155159
// Try winning and equal captures ordered by MVV/LVA, then non-captures ordered
156160
// by history value, then bad captures and quiet moves with a negative SEE ordered
157161
// by SEE value.
162+
const HistoryStats& history = pos.this_thread()->history;
158163
Value see;
159164

160165
for (auto& m : *this)

src/movepick.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ class MovePicker {
7979
MovePicker(const MovePicker&) = delete;
8080
MovePicker& operator=(const MovePicker&) = delete;
8181

82-
MovePicker(const Position&, Move, const HistoryStats&, Value);
83-
MovePicker(const Position&, Move, Depth, const HistoryStats&, Square);
84-
MovePicker(const Position&, Move, Depth, const HistoryStats&, Move, Search::Stack*);
82+
MovePicker(const Position&, Move, Value);
83+
MovePicker(const Position&, Move, Depth, Square);
84+
MovePicker(const Position&, Move, Depth, Search::Stack*);
8585

8686
Move next_move();
8787

@@ -92,8 +92,7 @@ class MovePicker {
9292
ExtMove* end() { return endMoves; }
9393

9494
const Position& pos;
95-
const HistoryStats& history;
96-
Search::Stack* ss;
95+
const Search::Stack* ss;
9796
Move countermove;
9897
Depth depth;
9998
Move ttMove;

src/search.cpp

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ namespace {
665665
assert(0 <= ss->ply && ss->ply < MAX_PLY);
666666

667667
ss->currentMove = (ss+1)->excludedMove = bestMove = MOVE_NONE;
668-
ss->cms = nullptr;
668+
ss->counterMoves = nullptr;
669669
(ss+1)->skipEarlyPruning = false;
670670
(ss+2)->killers[0] = (ss+2)->killers[1] = MOVE_NONE;
671671

@@ -789,7 +789,7 @@ namespace {
789789
&& pos.non_pawn_material(pos.side_to_move()))
790790
{
791791
ss->currentMove = MOVE_NULL;
792-
ss->cms = nullptr;
792+
ss->counterMoves = nullptr;
793793

794794
assert(eval - beta >= 0);
795795

@@ -838,14 +838,14 @@ namespace {
838838
assert((ss-1)->currentMove != MOVE_NONE);
839839
assert((ss-1)->currentMove != MOVE_NULL);
840840

841-
MovePicker mp(pos, ttMove, thisThread->history, PieceValue[MG][pos.captured_piece_type()]);
841+
MovePicker mp(pos, ttMove, PieceValue[MG][pos.captured_piece_type()]);
842842
CheckInfo ci(pos);
843843

844844
while ((move = mp.next_move()) != MOVE_NONE)
845845
if (pos.legal(move, ci.pinned))
846846
{
847847
ss->currentMove = move;
848-
ss->cms = &CounterMoveHistory[pos.moved_piece(move)][to_sq(move)];
848+
ss->counterMoves = &CounterMoveHistory[pos.moved_piece(move)][to_sq(move)];
849849
pos.do_move(move, st, pos.gives_check(move, ci));
850850
value = -search<NonPV>(pos, ss+1, -rbeta, -rbeta+1, rdepth, !cutNode);
851851
pos.undo_move(move);
@@ -871,10 +871,9 @@ namespace {
871871
moves_loop: // When in check search starts from here
872872

873873
Square prevSq = to_sq((ss-1)->currentMove);
874-
Move cm = thisThread->counterMoves[pos.piece_on(prevSq)][prevSq];
875-
const CounterMoveStats * cmh = &CounterMoveHistory[pos.piece_on(prevSq)][prevSq];
874+
const CounterMoveStats& cmh = CounterMoveHistory[pos.piece_on(prevSq)][prevSq];
876875

877-
MovePicker mp(pos, ttMove, depth, thisThread->history, cm, ss);
876+
MovePicker mp(pos, ttMove, depth, ss);
878877
CheckInfo ci(pos);
879878
value = bestValue; // Workaround a bogus 'uninitialized' warning under gcc
880879
improving = ss->staticEval >= (ss-2)->staticEval
@@ -968,8 +967,7 @@ namespace {
968967
if ( depth <= 4 * ONE_PLY
969968
&& move != ss->killers[0]
970969
&& thisThread->history[pos.moved_piece(move)][to_sq(move)] < VALUE_ZERO
971-
&& cmh
972-
&& (*cmh)[pos.moved_piece(move)][to_sq(move)] < VALUE_ZERO)
970+
&& cmh[pos.moved_piece(move)][to_sq(move)] < VALUE_ZERO)
973971
continue;
974972

975973
predictedDepth = std::max(newDepth - reduction<PvNode>(improving, depth, moveCount), DEPTH_ZERO);
@@ -1002,7 +1000,7 @@ namespace {
10021000
}
10031001

10041002
ss->currentMove = move;
1005-
ss->cms = &CounterMoveHistory[pos.moved_piece(move)][to_sq(move)];
1003+
ss->counterMoves = &CounterMoveHistory[pos.moved_piece(move)][to_sq(move)];
10061004

10071005
// Step 14. Make the move
10081006
pos.do_move(move, st, givesCheck);
@@ -1015,7 +1013,7 @@ namespace {
10151013
{
10161014
Depth r = reduction<PvNode>(improving, depth, moveCount);
10171015
Value hValue = thisThread->history[pos.piece_on(to_sq(move))][to_sq(move)];
1018-
Value cmhValue = cmh ? (*cmh)[pos.piece_on(to_sq(move))][to_sq(move)] : VALUE_ZERO;
1016+
Value cmhValue = cmh[pos.piece_on(to_sq(move))][to_sq(move)];
10191017

10201018
// Increase reduction for cut nodes and moves with a bad history
10211019
if ( (!PvNode && cutNode)
@@ -1164,17 +1162,17 @@ namespace {
11641162
&& !bestMove
11651163
&& !inCheck
11661164
&& !pos.captured_piece_type()
1167-
&& is_ok((ss - 1)->currentMove))
1165+
&& is_ok((ss-1)->currentMove))
11681166
{
11691167
Value bonus = Value((depth / ONE_PLY) * (depth / ONE_PLY) + depth / ONE_PLY - 1);
1170-
if ((ss-2)->cms) // prevCmh
1171-
(ss-2)->cms->update(pos.piece_on(prevSq), prevSq, bonus);
1168+
if ((ss-2)->counterMoves)
1169+
(ss-2)->counterMoves->update(pos.piece_on(prevSq), prevSq, bonus);
11721170

1173-
if ((ss-3)->cms) // prevFmh
1174-
(ss-3)->cms->update(pos.piece_on(prevSq), prevSq, bonus);
1171+
if ((ss-3)->counterMoves)
1172+
(ss-3)->counterMoves->update(pos.piece_on(prevSq), prevSq, bonus);
11751173

1176-
if ((ss-5)->cms) // prevFmh2
1177-
(ss-5)->cms->update(pos.piece_on(prevSq), prevSq, bonus);
1174+
if ((ss-5)->counterMoves)
1175+
(ss-5)->counterMoves->update(pos.piece_on(prevSq), prevSq, bonus);
11781176
}
11791177

11801178
tte->save(posKey, value_to_tt(bestValue, ss->ply),
@@ -1295,7 +1293,7 @@ namespace {
12951293
// to search the moves. Because the depth is <= 0 here, only captures,
12961294
// queen promotions and checks (only if depth >= DEPTH_QS_CHECKS) will
12971295
// be generated.
1298-
MovePicker mp(pos, ttMove, depth, pos.this_thread()->history, to_sq((ss-1)->currentMove));
1296+
MovePicker mp(pos, ttMove, depth, to_sq((ss-1)->currentMove));
12991297
CheckInfo ci(pos);
13001298

13011299
// Loop through the moves until no moves remain or a beta cutoff occurs
@@ -1449,9 +1447,9 @@ namespace {
14491447
Value bonus = Value((depth / ONE_PLY) * (depth / ONE_PLY) + depth / ONE_PLY - 1);
14501448

14511449
Square prevSq = to_sq((ss-1)->currentMove);
1452-
CounterMoveStats * cmh = (ss-1)->cms;
1453-
CounterMoveStats * fmh = (ss-2)->cms;
1454-
CounterMoveStats * fmh2 = (ss-4)->cms;
1450+
CounterMoveStats* cmh = (ss-1)->counterMoves;
1451+
CounterMoveStats* fmh = (ss-2)->counterMoves;
1452+
CounterMoveStats* fmh2 = (ss-4)->counterMoves;
14551453
Thread* thisThread = pos.this_thread();
14561454

14571455
thisThread->history.update(pos.moved_piece(move), to_sq(move), bonus);
@@ -1484,17 +1482,16 @@ namespace {
14841482
}
14851483

14861484
// Extra penalty for a quiet TT move in previous ply when it gets refuted
1487-
if ( (ss-1)->moveCount == 1
1488-
&& !pos.captured_piece_type())
1485+
if ((ss-1)->moveCount == 1 && !pos.captured_piece_type())
14891486
{
1490-
if ((ss-2)->cms) // prevCmh
1491-
(ss-2)->cms->update(pos.piece_on(prevSq), prevSq, -bonus - 2 * (depth + 1) / ONE_PLY);
1487+
if ((ss-2)->counterMoves)
1488+
(ss-2)->counterMoves->update(pos.piece_on(prevSq), prevSq, -bonus - 2 * (depth + 1) / ONE_PLY);
14921489

1493-
if ((ss-3)->cms) // prevFmh
1494-
(ss-3)->cms->update(pos.piece_on(prevSq), prevSq, -bonus - 2 * (depth + 1) / ONE_PLY);
1490+
if ((ss-3)->counterMoves)
1491+
(ss-3)->counterMoves->update(pos.piece_on(prevSq), prevSq, -bonus - 2 * (depth + 1) / ONE_PLY);
14951492

1496-
if ((ss-5)->cms) // prevFmh2
1497-
(ss-5)->cms->update(pos.piece_on(prevSq), prevSq, -bonus - 2 * (depth + 1) / ONE_PLY);
1493+
if ((ss-5)->counterMoves)
1494+
(ss-5)->counterMoves->update(pos.piece_on(prevSq), prevSq, -bonus - 2 * (depth + 1) / ONE_PLY);
14981495
}
14991496
}
15001497

src/search.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030
#include "position.h"
3131
#include "types.h"
3232

33-
template<typename T, bool CM>
34-
struct Stats;
35-
typedef Stats<Value, true> CounterMoveStats;
33+
template<typename T, bool CM> struct Stats;
34+
typedef Stats<Value, true> CounterMoveStats;
3635

3736
namespace Search {
3837

@@ -49,7 +48,7 @@ struct Stack {
4948
Value staticEval;
5049
bool skipEarlyPruning;
5150
int moveCount;
52-
CounterMoveStats * cms;
51+
CounterMoveStats* counterMoves;
5352
};
5453

5554
/// RootMove struct is used for moves at the root of the tree. For each root move

0 commit comments

Comments
 (0)