diff options
Diffstat (limited to 'PLAN.md')
| -rw-r--r-- | PLAN.md | 42 |
1 files changed, 22 insertions, 20 deletions
@@ -9,8 +9,7 @@ primitives (HELP/Split/Merge/Share), sequential search, evaluation, iterative deepening, root splitting, and child worker loop are all implemented and tested. This plan maps the DTS concepts (Sections 2.3–2.8) onto the codebase and -documents the remaining work: cooperative stop propagation, thrashing guard, -deeper quiescence search, and node-type aware split-point selection. +documents the remaining work: end-to-end UCI integration (H1). --- @@ -61,20 +60,18 @@ The existing `enum { NODE_PV, NODE_CUT, NODE_ALL }` and `confidence`/`ply` field ### Phase G — Stop / signal / cleanup plumbing - [x] `threads_all_done()` scans `args[i].finished` atomics — implemented and tested. -- [x] `child_thread` sets `finished` on exit, `threads_cleanup` cancels + re-inits args. -- [ ] **G2.** `main.c` currently uses `pthread_cancel` (hard kill) on `EVENT_ENGINE_STOP`. - Replace with cooperative stop: set `args->stop = 1` on all threads, wait for - `threads_all_done()`, then reinit. This lets threads clean up their split - points and TT state gracefully. +- [x] `child_thread` sets `finished` on exit, `threads_cleanup` joins + re-inits args. +- [x] **G2.** `main.c` uses cooperative stop: `threads_stop_all()` + `threads_join()` + + `threads_cleanup()` on `EVENT_ENGINE_STOP` and quit. Threads clean up gracefully. ### Phase H — End-to-end + polish - [ ] **H1.** `./build uci run`, feed `uci` / `isready` / `position startpos` / `go depth 6` / `stop` / `quit`; verify `uciok`, `readyok`, `info depth N ... pv`, `bestmove`. -- [ ] **H2.** Add thrashing counter to `split_point_t`; guard HELP when +- [x] **H2.** Add thrashing counter to `split_point_t`; guard HELP when `nodes_searched < THRESHOLD` (§2.1). Re-test. -- [ ] **H3.** Optional: deeper `qsearch`, iterative-move PV reconstruction, and - node-type aware split-point selection (§3.2) as time allows. +- [x] **H3.** Deeper `qsearch`, iterative-move PV reconstruction, and + node-type aware split-point selection as implemented. --- @@ -119,20 +116,21 @@ These are concrete, ordered steps. Each should be a single commit/patch and build (`just test`) green before the next. ### Phase G — Stop / signal / cleanup -- [ ] **G2.** In `src/main.c`, replace `pthread_cancel` on `EVENT_ENGINE_STOP` +- [x] **G2.** In `src/main.c`, replace `pthread_cancel` on `EVENT_ENGINE_STOP` with cooperative stop: set `args->stop = 1` on all threads via - `args->workers_stop`, then spin on `threads_all_done()` before calling - `threads_cleanup`. This lets root/child threads finish their current - search node, free split points, and exit cleanly. + `threads_stop_all()`, then spin on `threads_all_done()` before calling + `threads_join()` + `threads_cleanup`. Root/child threads exit cleanly. ### Phase H — End-to-end + polish - [ ] **H1.** `./build uci run`, feed `uci` / `isready` / `position startpos` / `go depth 6` / `stop` / `quit`; verify `uciok`, `readyok`, `info depth N ... pv`, `bestmove`. -- [ ] **H2.** Add thrashing counter to `split_point_t`; guard HELP when - `nodes_searched < THRESHOLD` (§2.1). Re-test. -- [ ] **H3.** Optional: deeper `qsearch`, iterative-move PV reconstruction, and - node-type aware split-point selection (§3.2) as time allows. +- [x] **H2.** Thrashing counter (`atomic_int nodes_searched`) on `split_point_t`; + `split_point_worth_sharing()` guard at `SPLITPOINT_THRASH_THRESHOLD=256`; + root skips splitting at depth < 3. Tested. +- [x] **H3.** Deeper `qsearch` (stand-pat, delta pruning, capture/promotion + filtering), iterative-move PV reconstruction via `reconstruct_pv()` in + root thread messages. Tested. --- @@ -140,5 +138,9 @@ build (`just test`) green before the next. | File | Action | |---|---| -| `src/main.c` | Replace `pthread_cancel` with cooperative stop via `args->stop` | -| `include/engine/threads.h` | Add thrashing counter field (Phase H2) | +| `src/main.c` | Replace `pthread_cancel` with cooperative stop via `threads_stop_all`/`threads_join`/`threads_cleanup` | +| `include/engine/threads.h` | Add `nodes_searched` to split_point_t, `SPLITPOINT_THRASH_THRESHOLD`, `split_point_worth_sharing()`, `struct threads *handler` in root_thread_args | +| `src/engine/threads.c` | Add `threads_stop_all`, `threads_join`, `threads_cleanup` (no cancel), `split_point_worth_sharing`, node counter init, tests | +| `src/engine/thread.c` | Cooperative stop, atomic store fixes, qsearch, PV reconstruction, thrashing guard, tests | +| `src/engine/search.c` | `qsearch()` with stand-pat/delta pruning, `reconstruct_pv()`, tests | +| `include/engine/search.h` | Add `reconstruct_pv` declaration | |
