-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.cpp
100 lines (82 loc) · 1.74 KB
/
class.cpp
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
#ifndef classDef
#define classDef
#include <vector>
#include <cstdlib>
#include <iostream>
#include <ctime>
#include <cstdio>
#include <algorithm>
#include <random>
using namespace std;
class Bot;
class Arena;
class Population;
class Bot
{
private:
//parameters of the bot
double pA;
double pB;
double pC;
int balance;
//results of the arena
vector<int> results;
void mutate();
public:
//constructors
Bot(Bot* a);
Bot(Bot* a, Bot* b);
Bot(double a=0, double b=0, double c=0, int bal=0): pA(a), pB(b), pC(c), balance(bal) {};
//results management
void addResult(int a);
void clearResults();
double averageResult();
double standardDeviation();
double value();
bool operator<(Bot a)
{
if(results.size()==a.results.size())
{
return value() < a.value();
}
else
return results.size() < a.results.size();
}
//printing
void print();
void printCompressed();
string toString();
string toStringCompressed();
};
class Arena
{
private:
vector <Bot> group;
public:
Arena();
void addBot(Bot a);
void newGroup(vector<Bot>* a);
vector <Bot> play();
void play(vector<Bot>::iterator b, vector<Bot>::iterator e);
};
class Population
{
private:
int roundNumber;
int playersPerRound;
int multiplier;
vector<Bot> bots;
Arena * connectedArena;
public:
Population(int rN=1, int pPR=1, int m=1): roundNumber(rN), playersPerRound(pPR), multiplier(m)
{
srand(time(0));
connectedArena = new Arena();
};
void gameSettings(int rN);
void addBot(Bot a);
void print();
void calibrate();
void newGeneration();
};
#endif