-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstrategies.h
92 lines (83 loc) · 2.55 KB
/
strategies.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
#pragma once
#include <vector>
#include <iostream>
#include <unordered_map>
using namespace std;
class strategy {
public:
virtual bool decide(const vector<bool> &opponent) = 0;
};
class tft : public strategy { // an eye for an eye
public:
bool decide(const vector<bool> &opponent) override {
if (opponent.size()==0) return true;
else if (opponent.back()==false) return false;
else return true;
}
};
class johnwick : public strategy { // holds grudges
private:
int flag=0;
public:
bool decide(const vector<bool> &opponent) override {
if (flag==0) return true;
else if (opponent.back()==false || flag==1) {
flag=1;
return false;
}
return true;
}
};
class switcheroo : public strategy { // does the opposite
public:
bool decide(const vector<bool> &opponent) override {
if (opponent.size()==0) return true;
else if (opponent.back()==false) return true;
else return false;
}
};
class coop : public strategy { // the altruist
public:
inline bool decide(const vector<bool> &opponent) override {
return true;
}
};
class def : public strategy { // the backstabber
public:
inline bool decide(const vector<bool> &opponent) override {
return false;
}
};
class agent007 : public strategy { // the cautious
private:
unordered_map<bool, int> m;
public:
bool decide(const vector<bool> &opponent) override {
if (opponent.size()==0) return true;
else {
for (auto it : opponent) m[it]++;
int t=m[true], f=m[false];
return (t>=f)?true:false;
}
}
};
class gamble : public strategy { // the gambler
public:
bool decide(const vector<bool> &opponent) override {
return (rand()%2==0)?true:false;
}
};
class ftft : public strategy { // not decided yet
/*private:
int flag=0;
public:
bool decide(const vector<bool> &opponent) override {
if (flag==0) return true;
else if (opponent.back()==false) ++flag;
else if (flag==1) {
flag=0;
return false;
}
return true;
}*/
};