Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpldgr committed Nov 26, 2024
1 parent 1f7ec75 commit bdb353e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/movegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ struct MoveList {

explicit MoveList(const Position& pos)
{
//this->mlb = get_thread_mlb(pos);
this->mlb = pos.get_mlb();
this->moveList = this->mlb->acquire();
this->last = generate<T>(pos, this->moveList);
Expand Down
11 changes: 5 additions & 6 deletions src/movepick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHist
ttMove(ttm), refutations{{killers[0], 0}, {killers[1], 0}, {cm, 0}}, depth(d), ply(pl) {

assert(d > 0);
//this->mlb = get_thread_mlb(pos);

this->mlb = pos.get_mlb();
this->moves = this->mlb->acquire();

Expand All @@ -83,7 +83,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHist
: pos(p), mainHistory(mh), gateHistory(dh), captureHistory(cph), continuationHistory(ch), ttMove(ttm), recaptureSquare(rs), depth(d) {

assert(d <= 0);
//this->mlb = get_thread_mlb(pos);

this->mlb = pos.get_mlb();
this->moves = this->mlb->acquire();

Expand All @@ -99,7 +99,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Value th, const GateHistory*
: pos(p), gateHistory(dh), captureHistory(cph), ttMove(ttm), threshold(th) {

assert(!pos.checkers());
//this->mlb = get_thread_mlb(pos);

this->mlb = pos.get_mlb();
this->moves = this->mlb->acquire();

Expand All @@ -108,12 +108,11 @@ MovePicker::MovePicker(const Position& p, Move ttm, Value th, const GateHistory*
&& pos.see_ge(ttm, threshold));
}

MovePicker::~MovePicker() {

MovePicker::~MovePicker()
{
this->mlb->release(this->moves);
}


/// MovePicker::score() assigns a numerical value to each move in a list, used
/// for sorting. Captures are ordered by Most Valuable Victim (MVV), preferring
/// captures with a good history. Quiets moves are ordered using the histories.
Expand Down
10 changes: 6 additions & 4 deletions src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,16 +528,18 @@ Position& Position::set(const Variant* v, const string& fenStr, bool isChess960,
chess960 = isChess960 || v->chess960;
tsumeMode = Options["TsumeMode"];
thisThread = th;
if ( th )

if ( thisThread )
{
this->thread_id = th->id();
this->mlb = &mlb_pool[this->thread_id];
this->thread_id = thisThread->id();
this->bind_mlb();
}
else
{
this->thread_id = 0;
this->thread_id = -1;
this->mlb = nullptr;
}

set_state(st);

assert(pos_is_ok());
Expand Down
10 changes: 8 additions & 2 deletions src/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,10 @@ class Position {
void put_piece(Piece pc, Square s, bool isPromoted = false, Piece unpromotedPc = NO_PIECE);
void remove_piece(Square s);

size_t thread_id;
int thread_id;
movelist_buf* mlb;

void bind_mlb();
movelist_buf* get_mlb() const;

private:
Expand Down Expand Up @@ -1586,9 +1587,14 @@ inline movelist_buf* get_thread_mlb(const Position& pos)
return &mlb_pool[pos.thread_id];
}

inline void Position::bind_mlb()
{
this->mlb = &mlb_pool[this->thread_id];
}

inline movelist_buf* Position::get_mlb() const
{
return &mlb_pool[this->thread_id];
return this->mlb;
}

} // namespace Stockfish
Expand Down

0 comments on commit bdb353e

Please sign in to comment.