-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathF.cpp
203 lines (178 loc) · 4.3 KB
/
F.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
* F.cpp
*
* Created on: May 6, 2012
* Author: Toby
*/
#include "F.h"
//#include <iostream>
#include <sstream>
//#include "Name.h"
//#include "MersenneTwister.h"
#include "RandomSingleton.h"
#include "Config.h"
#include "GameState.h"
#include "Population.h"
#include "Scv.h"
#include "NoEntity.h"
#include "CommandCenter.h"
#include "SupplyDepot.h"
#include "Barracks.h"
#include "Refinery.h"
#include "OrbitalCommand.h"
#include "Marine.h"
#include "BarrackWithTechlab.h"
#include "BarracksWithReactor.h"
#include "Marauder.h"
#include "ProducerStack.h"
#include "EntityStack.h"
#include "planetaryfortress.h"
#include "engineeringbay.h"
using namespace std;
namespace
{
// these aren't mutated, so can be reused.
static auto marine = Marine();
static auto supplyDepot = SupplyDepot();
static auto marauder = Marauder();
}
Entity F::create(E::Name name) {
switch (name) {
case E::SCV:
return Scv();
case E::COMMAND_CENTER:
return CommandCenter();
case E::SUPPLY_DEPOT:
return supplyDepot;
case E::BARRACKS:
return Barracks();
case E::BARRACKS_WITH_TECHLAB:
return BarracksWithTechlab();
case E::BARRACKS_WITH_REACTOR:
return BarracksWithReactor();
case E::REFINERY:
return Refinery();
case E::ORBITAL_COMMAND:
return OrbitalCommand();
case E::PLANETARY_FORTRESS:
return PlanetaryFortress();
case E::MARINE:
return marine;
case E::MARAUDER:
return marauder;
case E::ENGINEERING_BAY:
return EngineeringBay();
default:
return NoEntity();
}
}
string F::toString(E::Name n) {
switch (n) {
case E::EMPTY:
return "empty";
case E::SCV:
return "SCV";
case E::COMMAND_CENTER:
return "Command Center";
case E::SUPPLY_DEPOT:
return "Supply Depot";
case E::BARRACKS:
return "Barracks";
case E::BARRACKS_WITH_TECHLAB:
return "Barracks with Techlab";
case E::BARRACKS_WITH_REACTOR:
return "Barracks with Reactor";
case E::REFINERY:
return "Refinery";
case E::ORBITAL_COMMAND:
return "Orbital Command";
case E::PLANETARY_FORTRESS:
return "Planetary Fortress";
case E::MARINE:
return "Marine";
case E::MARAUDER:
return "Marauder";
case E::ENGINEERING_BAY:
return "Engineering Bay";
default:
return "Undefined";
}
}
//unsigned long F::nextInt(unsigned long min, unsigned long max) {
// unsigned long r = RandomSingleton::nextInt(min, max);
// return r;
//}
//double F::nextDouble() {
// double r = RandomSingleton::nextDouble();
// return r;
//}
void F::printNewUnit(E::Name name, GameState* gs) {
stringstream ss;
ss << displayTime(gs->getTime()) << ", ";
ss << displayResources(gs);
ss << displaySupply(gs);
ss << toString(name);
F::println(ss.str());
}
std::string F::displaySupply(GameState* gs) {
string str;
str.append(" (");
str.append(to_string(gs->getSupply()));
str.append("/");
str.append(to_string(gs->getSupplyMax()));
str.append(") ");
return str;
}
std::string F::displayResources(GameState* gs) {
std::string str;
str.append("mins: ");
str.append(to_string((int) gs->getMinerals()));
str.append(", gas: ");
str.append(to_string((int) gs->getGas()));
str.append(" ");
// str = makeStr("mins: " + (int) gs->getMinerals() + ", gas: " + (int) gs->getGas() + " ");
return str;
}
std::string F::displayTime(int time) {
std::string str;
str += " ";
if (time % 60 < 10) {
str += to_string(time / 60);
str.append(":0");
str.append(to_string(time % 60));
} else {
str.append(to_string(time / 60));
str.append(":");
str.append(to_string(time % 60));
}
return str;
}
void F::printGen(int gen, Population *p) {
stringstream ss;
ss << "Completed generation " << (gen + 1);
int fitness = p->getListOfBuilds().back()->getFitness();
ss << " highest fitness: " << fitness;
ss << " best: " << p->getHighest()->getFitness() << ".";
// cout << ss.str() << endl;
F::println(ss.str());
}
void F::print(string s) {
cout << s;
}
//void F::println() {
// cout << endl;
//}
//void F::println(S str) {
// cout << str.get() << endl;
//}
//string F::makeStr(S str) {
// return str.get();
//}
void F::printInit(Population* p) {
if (p->getSize() % 1 == 0) {
string s;
s += "generated build ";
s += to_string(p->getSize());
F::println(s);
}
}