summaryrefslogtreecommitdiff
path: root/include/engine
diff options
context:
space:
mode:
authorAargh Rai <aargh.rai+git@gmail.com>2026-08-27 17:41:07 +0530
committerAargh Rai <aargh.rai+git@gmail.com>2026-08-27 17:41:07 +0530
commit5a02743c0c9563f41a8c3821a7bbce4fc3b0b839 (patch)
treef36aa805b8c90a8d786e8561a9d84f57e6191c19 /include/engine
parentd87b4744bed8f0c43e11ea12508ef2941bdd7186 (diff)
bug fixes
Diffstat (limited to 'include/engine')
-rw-r--r--include/engine/search.h9
-rw-r--r--include/engine/threads.h17
2 files changed, 23 insertions, 3 deletions
diff --git a/include/engine/search.h b/include/engine/search.h
index 94b5da5..506a4bc 100644
--- a/include/engine/search.h
+++ b/include/engine/search.h
@@ -33,4 +33,13 @@ search_result_t search(
search_ctx_t *ctx
);
+// Reconstruct the principal variation by following TT best-move entries.
+// Writes at most `max_len` moves into `pv_out`; returns the number written.
+int reconstruct_pv(
+ position_t position,
+ ttable_t tt,
+ move_t *pv_out,
+ int max_len
+);
+
#endif // SEARCH_H
diff --git a/include/engine/threads.h b/include/engine/threads.h
index 1e63a5d..a511998 100644
--- a/include/engine/threads.h
+++ b/include/engine/threads.h
@@ -11,12 +11,17 @@
enum { SPLITPOINT_STATE_FREE, SPLITPOINT_STATE_ACTIVE };
enum { NODE_PV, NODE_CUT, NODE_ALL };
+
+// §2.1 thrashing guard: refuse HELP when nodes_searched < THRESHOLD at a
+// split point. Prevents the end-of-iteration "N idle procs split 1 proc".
+enum { SPLITPOINT_THRASH_THRESHOLD = 256 };
typedef struct split_point {
atomic_int state;
atomic_int next_move_idx;
atomic_int alpha, beta;
atomic_int best_score;
atomic_int workers;
+ atomic_int nodes_searched; // §2.1 thrashing guard: refuse HELP when < threshold
move_t best_move;
struct split_point *parent;
@@ -60,12 +65,12 @@ struct root_thread_args {
split_point_t *split_points; // shared DTS pool (§2.4)
size_t sp_pool_capacity;
- // the root stops its workers when the search completes
- atomic_int *workers_stop;
+ // the root stops its workers when the search completes.
+ struct threads *handler;
int workers_count;
};
-typedef union {
+typedef union thread_args {
struct child_thread_args child_thread_args;
struct root_thread_args root_thread_args;
} thread_args_t;
@@ -101,6 +106,10 @@ bool split_point_claim_move(split_point_t *split_point, move_t *move);
bool split_point_merge(split_point_t *split_point);
void split_point_share(split_point_t *split_point, i32 score, move_t move);
+// §2.1 thrashing guard: true if this split point has been searched enough
+// to be worth publishing for HELP.
+bool split_point_worth_sharing(split_point_t *split_point);
+
// HELP (§2.3): scan the pool for a published split point with work left
split_point_t *threads_find_work(struct threads *handler);
split_point_t *__pool_find_work(split_point_t *pool, size_t capacity);
@@ -111,6 +120,8 @@ void threads_reserve(struct threads *handler, size_t capacity);
void threads_go(struct threads *handler);
bool threads_go_loop(struct threads *handler);
bool threads_all_done(struct threads *handler);
+void threads_stop_all(struct threads *handler);
+void threads_join(struct threads *handler);
void threads_cleanup(struct threads *handler);
void *child_thread(void *args);