-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAI.h
75 lines (67 loc) · 1.86 KB
/
AI.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
/*
*Author:-Pukar Giri
*Created On:-21Th December 2018 at 20:49
*File Name:-AI.h
*Project Name:-dlibprac
*Licence:- MIT
*Email:[email protected]
*/
#ifndef DLIBPRAC_AI_H
#define DLIBPRAC_AI_H
#include <random>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <fstream>
#include <SDL2/SDL.h>
#include "player.h"
typedef struct{
action my_action;
action opp_action;
int distance;
}state;
//enum action{left,right,up,down,none};
typedef struct{
state state1;
action action1;
}state_action_pair;
typedef struct{
state_action_pair pair;
float value;
}key_value;
////typedef state_action_pair;
class AI
{
public:
player &self;
player &opponent;
std::vector<key_value>q;
unsigned long long gencount=0;
unsigned long long no_of_left_choosen=0;
unsigned long long no_of_right_choosen=0;
unsigned long long no_of_jump_choosen=0;
unsigned long long no_of_kick_choosen=0;
unsigned long long no_of_punch_choosen=0;
unsigned long long no_of_idle_choosen=0;
state laststate;
action lastaction;
int lastdistance;
float epsilion;
float alpha;
float gamma;
void setq(state_action_pair pair,float value);
void dump();
void load();
inline state_action_pair get_state_action_pair(state &state1,action & action1);
public:
AI(player &self,player &opp, float epsilion=5, float alpha=0.6, float gamma=0.9);
inline float getq(state_action_pair pair);
void learnq(state state1,action action1,float reward,float value);
action chooseaction(state);
void learn(state state1,action action1, float reward,state state2);
state calc_state();
float calc_reward();
void drive();
};
#endif //DLIBPRAC_AI_H