-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQAgent.cpp
More file actions
27 lines (22 loc) · 803 Bytes
/
QAgent.cpp
File metadata and controls
27 lines (22 loc) · 803 Bytes
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
#include "QAgent.hpp"
QBird::QBird(double l, double d){
for (int i = 0; i < table.size(); i++){
for (int j = 0; j < table[0].size(); j++){
for (int k = 0; k < table[0][0].size(); k++){
for (int l = 0; l < table[0][0][0].size(); l++)
table[i][j][k][l] = 0;
}
}
}
learnrate = l;
discount = d;
}
int QBird::nextAction(int x, int y, int s){
auto e = table[y][x][s];
if (e[1] > e[0]) return 1;
return 0;
}
void QBird::learn(int prev[3], int cur[3], int reward, int a){
double dif = reward + (*max_element(table[cur[1]][cur[0]][cur[2]].begin(), table[cur[1]][cur[0]][cur[2]].end())*discount) - table[prev[1]][prev[0]][prev[2]][a];
table[prev[1]][prev[0]][prev[2]][a] += dif * learnrate;
}