libmcts
A Monte Carlo Tree Search Library
sampling_selector.hpp
1 #ifndef SAMPLING_SELECTOR_H
2 #define SAMPLING_SELECTOR_H
3 
4 #include <random>
5 #include "inode.hpp"
6 #include "iselection_strategy.hpp"
7 
8 namespace mcts {
9 
10 // ----------------------------------------------------------------------
15 // ----------------------------------------------------------------------
16 template <typename Context, typename Config>
17 class SamplingSelector : public ISelectionStrategy<Context, Config> {
18  typedef typename INode<Context, Config>::node_t node_t;
19 
20 public:
21  typedef std::uniform_int_distribution<> DistributionType;
22 
23  // ----------------------------------------------------------------------
29  // ----------------------------------------------------------------------
30  node_t *select(node_t *node) {
31  DistributionType dist(0, node->children().size() - 1);
32  int rand = dist(*node->config()->nb_gen());
33  return node->children()[rand];
34  }
35 };
36 }
37 
38 #endif
node_t * select(node_t *node)
randomly chooses a child of node
selector that chooses random children uniformly
interface for all selection strategies. A selection strategy selects one child of a parent node accor...
basic interface for a node in the tree. Every node has to implement this functions.
Definition: inode.hpp:18
virtual Config * config() const =0
gets the config object
virtual const vector< node_t * > children() const =0
get the children of the current node