-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonteCarloAlgorithm.h
More file actions
59 lines (46 loc) · 1.99 KB
/
MonteCarloAlgorithm.h
File metadata and controls
59 lines (46 loc) · 1.99 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef CODECUP_MONTECARLOALGORITHM_H
#define CODECUP_MONTECARLOALGORITHM_H
#include <forward_list>
#include <random>
#include "Algorithm.h"
#include "Move.h"
#include "Simulation.h"
#include "Game6561.h"
#include "MonteCarloPolicies.h"
class MonteCarloAlgorithm : public Algorithm {
public:
MonteCarloAlgorithm(int simulationsThreshold, std::size_t movesToSimulate);
virtual const Coords calculateRedMove() const;
virtual const Coords calculateBlueMove() const;
virtual const Coords calculateGreyMove() const;
virtual SlideDirection calculateSlide() const;
virtual void ensureValidState();
//monte carlo stuff
private:
// constants
const int simulationsThreshold;
const std::size_t movesToSimulate;
// random generator
RandomMonteCarloPolicy randomMonteCarloPolicy;
// simulations
std::forward_list<Simulation> simulations;
Simulation* bestSimulation;
void updateBestSimulation();
bool shouldSimulateMore() const;
void simulate(std::size_t movesToCalculate);
std::size_t simulateGame(std::size_t maxMovesInSimulation);
/**
* Exclusion list SHALL BE SORTED!!!!!!!!!
*/
unsigned short generateRandomNumber(unsigned short max, unsigned short exclusionList[] = nullptr,
unsigned short exclusionListLength = 0);
// add a random slide to the given simulation, and update the given board accordingly
// returns true if a valid move was possible, false otherwise
bool addRandomSlideToSimulation(Simulation& simulation, Board& board);
// add a random piece placement to the given simulation, and update the given board accordingly
// returns true if a valid move was possible, false otherwise
bool addRandomCoordsToSimulation(Simulation& simulation, Board& board, PieceColor color);
unsigned short getNonEmptyCoords(unsigned short nonEmptyCoords[], const Board& board);
unsigned short coordsToUShort(coord row, coord column);
};
#endif //CODECUP_MONTECARLOALGORITHM_H