zxqfl / mcts

Generic, parallel Monte Carlo tree search library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Committing to moves

Ten0 opened this issue · comments

First of all, thanks a lot for this library. It's super well thought and designed and works great.

I'm using this in a real-time context in a deterministic full information game.

For performance purposes, I would like to be able to register that a player "commits" to one of the available moves at the root, just dropping the other possible moves out of the tree but maintaining the computation of everything that was below that move (since it's typically one of the main variations, this is where a very significant portion of the nodes should be).

Would that be something that can be achieved? (I would probably work on it but the little amount of documentation makes it somewhat hard to be sure of the all the unsafe invariants that have to be upheld.)

Thank you for your help!

Thoughts:

  • That seems pretty straightforward to not reclaim memory (we just change the root node and put all the other nodes in orphaned). However to reclaim memory that's a whole other story, mostly due to potential cycles.

Thoughts on reclaiming memory:

  • As nodes may reference each other a lot, in order to reclaim space in the main structure we'd have to figure out a way to determine a new owner for a node when we are discarding an owning node, while properly handling cyclic references to avoid memory leaks.
  • I use transposition_table::ApproxTable - if I understand correctly space can never be reclaimed in this particular struct because otherwise we'd have to remove early-stopping upon finding an empty entry. Overall if we intend to free we need an extra CleanableTranspositionTable trait (or like) that enables removing entries, and condition commit_move on that the transposition table supports it.

Some garbage collection mechanism could be a solution to the reclaiming memory issue.
Maybe something based on crossbeam-epoch ?