-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAgent.h
150 lines (116 loc) · 3.23 KB
/
Agent.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#pragma once
#include <string>
#include <iostream>
#include <stdexcept>
#include <vector>
#include <map>
#include <limits>
#include <vector>
#include <sstream>
#include <cmath>
#include <Imagine/Graphics.h>
#include <Imagine/Images.h>
#include <Imagine/LinAlg.h>
using namespace std;
//class Piece{
//protected:
// int player;
//public:
// Piece(int player);
// virtual ~Piece();
// virtual Piece* clone();
// int getPlayer() const;
//};
class Move{
protected:
int player;
public:
Move(int player):player(player){}
virtual ~Move(){}
virtual Move* clone() = 0;
virtual int getx() const=0 ;
virtual int gety() const =0;
int getPlayer() const;
};
class Board{
protected:
int m, n;
// Piece* tab;
int endGameValue;
public:
Board();
Board(int nligcol); // Constructeur carré
Board(int nlig, int ncol); // Constructeur rectangle
Board(const Board& b); // Constructeur copie
virtual Board* clone()=0;
int getLig() const;
int getCol() const;
int getIndex(int x, int y) const;
int getEndGameValue() const;
virtual ~Board(); //Destructeur
virtual int getPiecePlayer(int x, int y) const =0;// Return player index : (0, no player), (-1 player 2), (1 player 1)
// virtual Piece* getPiece(int x, int y) const =0;
// virtual void addPiece(int x, int y, Piece& Piece) = 0;
// void operator=(const Board& b);
virtual void reset() = 0;
virtual bool endGame() = 0;
virtual bool winGame(int x, int y , int& player) = 0;
// TODO Faire une classe move
virtual std::vector< Move* > playableMoves(int playerNumber) = 0;
virtual void playMove(const Move* move, int player) = 0; // Change inplace the state of the board
};
//======================== CLASS AGENT ================================
class Agent{
public:
Agent();
virtual ~Agent(){}
virtual Move* getMove(Board& B, int& player) = 0;
};
class UCTAgent : public Agent{
protected :
int max_iter;
public:
UCTAgent(int iter_max = 1500);
~UCTAgent(){}
virtual Move* getMove(Board& B, int& player);
};
class randomAgent: public Agent{
public:
randomAgent();
~randomAgent(){}
virtual Move* getMove(Board& B, int& player);
};
//======================== CLASS NODE ================================
class UCTNode{
private :
Board* B;
bool isRoot;
bool isTerminal;
UCTNode* parent;
Move* lastMove;
vector< Move* > remainingMoves;
vector<UCTNode*> childNodes;
int player;
int visits;
int wins;
public :
UCTNode(Board& currentB, int player, Move* last_move, bool isRoot = false);
UCTNode(Board& currentB, int current_player, bool current_isRoot = false);
~UCTNode();
int getPlayer() const;
int getWins() const;
int getVisits() const;
void addWins(int newWins);
bool getIsRoot() const;
bool getIsTerminal() const;
Move* getLastMove() const;
UCTNode* selection(bool verbose = false);
UCTNode* selectionFinal();
bool isFullyExpanded() const;
void operator=(const UCTNode& node);// Copie
UCTNode(const UCTNode& node); // Constructeur par copie
UCTNode* selectExpandedPath();
UCTNode* expand();
void backPropagation(int newWins = 0);
int rollout(int globalPlayer);
};