From bdb353ec4ad25221a7543eed9a8a5ee916420db6 Mon Sep 17 00:00:00 2001 From: dpldgr <144766863+dpldgr@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:38:58 +0800 Subject: [PATCH] Refactoring. --- src/movegen.h | 1 - src/movepick.cpp | 11 +++++------ src/position.cpp | 10 ++++++---- src/position.h | 10 ++++++++-- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/movegen.h b/src/movegen.h index 8318eeeaa..7486dd64e 100644 --- a/src/movegen.h +++ b/src/movegen.h @@ -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(pos, this->moveList); diff --git a/src/movepick.cpp b/src/movepick.cpp index 1c65b5bba..ceba52c28 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -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(); @@ -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(); @@ -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(); @@ -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. diff --git a/src/position.cpp b/src/position.cpp index b0f427453..a59277568 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -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()); diff --git a/src/position.h b/src/position.h index 8ffaafb07..f6c6977c3 100644 --- a/src/position.h +++ b/src/position.h @@ -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: @@ -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