-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
326 lines (278 loc) · 9.04 KB
/
main.cpp
File metadata and controls
326 lines (278 loc) · 9.04 KB
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#include <iostream>
#include <map>
#include "ThirdParty/json.h"
#include "craftingClass.h"
#include "action.h"
#include "jsonLoader.h"
#include "recipe.h"
#include "crafter.h"
#include "worldState.h"
#include "actionApplication.h"
#include "expectimax.h"
// Applies data from a recipe and crafter to the world state:
void initializeWorldState(WorldState &worldState, Crafter crafter, Recipe recipe)
{
worldState.condition = WorldState::Condition::Normal;
worldState.cp = crafter.cp;
worldState.crafter = crafter;
worldState.recipe = recipe;
worldState.durability = recipe.durability;
worldState.progress = 0;
worldState.quality = 0;
}
void mainMenu();
void configureCrafters();
void performCraft();
int main()
{
std::cout << "Welcome to Goobbue!" << std::endl;
mainMenu();
return 0;
}
void mainMenu()
{
while(true)
{
std::cout << "-- Main Menu --" << std::endl;
std::cout << "\t1. Configure your crafters." << std::endl;
std::cout << "\t2. Perform a craft" << std::endl;
std::cout << "Please enter a choice (1 or 2):" << std::endl;
char choice;
std::cin >> choice;
if (choice == '1')
{
configureCrafters();
}
else if (choice == '2')
{
performCraft();
}
else
{
std::cout << "Unrecognized selection, quitting (goodbye!)" << std::endl;
break;
}
}
}
void configureCrafters()
{
std::cout << "-- Crafter Configuration --" << std::endl;
std::cout << "Select your crafting class:" << std::endl;
std::cout << "\t1. Alchemist" << std::endl;
std::cout << "\t2. Armorer" << std::endl;
std::cout << "\t3. Blacksmith" << std::endl;
std::cout << "\t4. Carpenter" << std::endl;
std::cout << "\t5. Culinarian" << std::endl;
std::cout << "\t6. Goldsmith" << std::endl;
std::cout << "\t7. Leatherworker" << std::endl;
std::cout << "\t8. Weaver" << std::endl;
std::cout << "Please enter a choice (1 to 8):" << std::endl;
char choice;
std::cin >> choice;
if(choice>'8' || choice <'1')
{
std::cout << "Unrecognized selection, quitting" << std::endl;
return;
}
CraftingClass craftingClass = (CraftingClass)(choice-'1');
std::cout << "Configure your " << craftingClassToString(craftingClass) << std::endl;
std::cout << "Feature not supported, coming soon!" << std::endl;
}
typedef std::vector<Action> ActionVector;
Crafter selectCrafter(const std::string& dataPath, const ActionVector& actions)
{
std::map<CraftingClass, Crafter> crafters = readCrafters(loadJson(dataPath + "Crafters.json"), actions);
Crafter crafter;
while(true)
{
std::cout << "Enter the name of your crafting class" << std::endl;
std::string craftingClassName;
std::cin >> craftingClassName;
CraftingClass craftingClass = stringToCraftingClass(craftingClassName);
if(craftingClass==CraftingClass::All)
{
continue;
}
else if(crafters.end()==crafters.find(craftingClass))
{
std::cout << "Crafter does not exist in JSON file" << std::endl;
}
else
{
crafter = crafters[craftingClass];
crafter.print();
break;
}
}
return crafter;
}
Recipe selectRecipe(const std::string& dataPath, CraftingClass craftingClass)
{
Recipe recipe;
while(true)
{
std::cin.ignore();
std::cout << "Enter the name of the recipe" << std::endl;
std::string recipeName;
std::getline(std::cin, recipeName);
std::cout << "Searching for " << recipeName << std::endl;
if(readRecipe(loadJson(dataPath + "Recipes.json"), craftingClass, recipeName, recipe))
{
std::cout << "Found recipe." << std::endl;
recipe.print();
break;
}
else
{
std::cout << "Could not find specified recipe" << std::endl;
}
}
return recipe;
}
int getStartingQuality()
{
std::cout << "Enter the starting quality" << std::endl;
int quality = 0;
std::cin >> quality;
return quality;
}
void performCraftingAlgorithm(const WorldState & worldStateIn, const ActionVector& actions)
{
WorldState worldState = worldStateIn;
std::cout << "Starting Craft!" << std::endl;
while(true)
{
Expectimax expectimax;
expectimax.actions = actions;
worldState.print();
Action::Identifier id = expectimax.evaluateAction(worldState);
std::cout << "Use the " << actions[id].name << " skill!" << std::endl;
Outcomes outcomes = applyAction(worldState, actions[id]);
if(outcomes.first.worldState.durability<=0)
{
std::cout << "Congratulations on finishing your craft! (durability)" << std::endl;
outcomes.first.worldState.print();
break;
}
if(outcomes.first.probability==1.0f)
{
worldState = outcomes.first.worldState;
}
else
{
std::cout << "Did the action succeed? (y or n)" << std::endl;
char decision;
std::cin >> decision;
if(decision=='y')
{
worldState = outcomes.first.worldState;
}
else if(decision=='n')
{
worldState = outcomes.second.worldState;
}
else
{
break;
}
}
if(worldState.progress >= worldState.recipe.difficulty)
{
worldState.print();
if(worldState.quality < worldState.recipe.maxQuality)
{
std::cout << "Congratulations on finishing your craft! (progress)" << std::endl;
}
else
{
std::cout << "Congratulations on HQing your craft!" << std::endl;
}
break;
}
if(worldState.condition==WorldState::Condition::Normal && worldState.quality < worldState.recipe.maxQuality)
{
while(true)
{
std::cout << "What is the condition: (p)oor, (n)ormal, (g)ood or (e)xcellent?" << std::endl;
char condition;
std::cin >> condition;
switch (condition)
{
case 'p':
worldState.condition = WorldState::Condition::Poor;
break;
case 'n':
worldState.condition = WorldState::Condition::Normal;
break;
case 'g':
worldState.condition = WorldState::Condition::Good;
break;
case 'e':
worldState.condition = WorldState::Condition::Excellent;
break;
default:
std::cout << "Condition not understood, try again" << std::endl;
continue;
}
break;
}
}
else
{
if(worldState.condition==WorldState::Condition::Excellent)
{
worldState.condition=WorldState::Condition::Poor;
}
else if(worldState.condition==WorldState::Condition::Good || worldState.condition==WorldState::Condition::Poor)
{
worldState.condition=WorldState::Condition::Normal;
}
}
}
}
bool yesNoQuestion(const std::string& text)
{
std::cout << text << " (y or n)" << std::endl;
char decision;
std::cin >> decision;
return decision=='y';
}
void performCraft()
{
std::string dataPath = "E:/Dropbox/Goobbue/Data/";
ActionVector actions = readActions(loadJson(dataPath + "Skills.json"));
while (true)
{
Crafter crafter = selectCrafter(dataPath, actions);
while (true)
{
Recipe recipe = selectRecipe(dataPath, crafter.craftingClass);
WorldState worldState;
initializeWorldState(worldState, crafter, recipe);
worldState.quality = getStartingQuality();
while (true)
{
performCraftingAlgorithm(worldState, actions);
if (!yesNoQuestion("Repeat the craft with the same recipe and quality?"))
{
break;
}
}
if (!yesNoQuestion("Repeat the craft with the same crafter?"))
{
break;
}
}
if (yesNoQuestion("Go to the main menu?"))
{
break;
}
}
}
/*
Outcomes outcomes = applyAction(worldState, actions[Action::Identifier::greatStrides]);
outcomes = applyAction(outcomes.first.worldState, actions[Action::Identifier::steadyHand]);
outcomes.first.worldState.condition = WorldState::Condition::Good;
outcomes = applyAction(outcomes.first.worldState, actions[Action::Identifier::standardTouch]);
std::cout << "Quality: " << outcomes.first.worldState.quality << std::endl;
*/