-
Notifications
You must be signed in to change notification settings - Fork 0
/
MonteCarloTreeSearchAlgorithm.h
43 lines (32 loc) · 1.2 KB
/
MonteCarloTreeSearchAlgorithm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef CODECUP_MONTECARLOTREESEARCHALGORITHM_H
#define CODECUP_MONTECARLOTREESEARCHALGORITHM_H
#include "Algorithm.h"
#include "MonteCarloPolicies.h"
#include <map>
struct Statistic {
std::uint32_t score;
std::uint16_t playCount;
};
typedef std::map<Board, Statistic> Statistics;
class MonteCarloTreeSearchAlgorithm : public Algorithm {
public:
MonteCarloTreeSearchAlgorithm(std::size_t movesToSimulate, double ucb1Constant, std::size_t maxLocalMovesToSimulate, MonteCarloPolicy& policy);
virtual const Coords calculateRedMove() const;
virtual const Coords calculateBlueMove() const;
virtual const Coords calculateGreyMove() const;
virtual SlideDirection calculateSlide() const;
virtual void ensureValidState();
private:
// constants
const std::size_t movesToSimulate;
const double ucb1Constant;
const std::size_t maxLocalMovesToSimulate;
MonteCarloPolicy& policy;
RandomMonteCarloPolicy randomPolicy;
Move nextMove;
Statistics statistics;
void runSimulations(std::size_t movesToSimulate);
void prepareStatisticsForNextRun();
std::size_t simulateGame(const std::size_t movesToSimulate);
};
#endif //CODECUP_MONTECARLOTREESEARCHALGORITHM_H