-
Notifications
You must be signed in to change notification settings - Fork 11
/
node_print.c
288 lines (262 loc) · 8.11 KB
/
node_print.c
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
#include <stdio.h>
#include <stdlib.h>
#include "node_print.h"
#include "base.h"
#include "calculator.h"
#include "logger.h"
#include "recipes.h"
extern Recipe *recipeList;
/*-------------------------------------------------------------------
* Function : printCh5Data
* Inputs : BranchPath *curNode
* MoveDescription desc
* FILE *fp
*
* Print to a txt file the data which pertains to Chapter 5 evaluation
* (where to place Dried Bouquet, Coconut, etc.)
-------------------------------------------------------------------*/
void printCh5Data(const BranchPath *curNode, const MoveDescription desc, FILE *fp) {
const CH5 *ch5Data = desc.data;
// Determine how many nulls there are when allocations start
int nulls = curNode->prev->inventory.nulls;
if (indexOfItemInInventory(curNode->prev->inventory, Mousse_Cake) < 10) {
++nulls;
}
fprintf(fp, "Ch.5 Break: ");
if (nulls) {
fprintf(fp, "DB filling null, ");
--nulls;
}
else {
fprintf(fp, "DB replacing #%d, ", ch5Data->indexDriedBouquet + 1);
}
if (nulls) {
fprintf(fp, "CO filling null, ");
--nulls;
}
else {
fprintf(fp, "CO replacing #%d, ", ch5Data->indexCoconut + 1);
}
if (ch5Data->lateSort) {
if (nulls) {
fprintf(fp, "KM filling null, ");
}
else {
fprintf(fp, "KM replacing #%d, ", ch5Data->indexKeelMango + 1);
}
printCh5Sort(ch5Data, fp);
}
else {
printCh5Sort(ch5Data, fp);
fprintf(fp, "KM replacing #%d, ", ch5Data->indexKeelMango + 1);
}
fprintf(fp, "CS replacing #%d, use TR in #%d",
ch5Data->indexCourageShell + 1, ch5Data->indexThunderRage + 1);
}
/*-------------------------------------------------------------------
* Function : printCh5Sort
* Inputs : CH5 *ch5Data
* FILE *fp
*
* Print to a txt file the data which pertains to Chapter 5 sorting
-------------------------------------------------------------------*/
void printCh5Sort(const CH5 *ch5Data, FILE *fp) {
fprintf(fp, "sort ");
switch (ch5Data->ch5Sort) {
case ESort_Alpha_Asc:
fprintf(fp, "(Alpha), ");
break;
case ESort_Alpha_Des:
fprintf(fp, "(Reverse-Alpha), ");
break;
case ESort_Type_Asc:
fprintf(fp, "(Type), ");
break;
case ESort_Type_Des:
fprintf(fp, "(Reverse-Type), ");
break;
default:
fprintf(fp, "ERROR IN CH5SORT SWITCH CASE");
};
}
/*-------------------------------------------------------------------
* Function : printCookData
* Inputs : BranchPath *curNode
* MoveDescription desc
* FILE *fp
*
* Print to a txt file the data which pertains to cooking a recipe,
* which includes what items were used and what happens to the output.
-------------------------------------------------------------------*/
void printCookData(const BranchPath *curNode, const MoveDescription desc, FILE *fp) {
Cook *cookData = desc.data;
int nulls = curNode->prev->inventory.nulls;
fprintf(fp, "Use [%s] in slot %d ", getItemName(cookData->item1),
cookData->itemIndex1 - (cookData->itemIndex1 < 10 ? nulls : 0) + 1);
if (cookData->numItems == 2) {
fprintf(fp, "and [%s] in slot %d ", getItemName(cookData->item2),
cookData->itemIndex2 - (cookData->itemIndex2 < 10 ? nulls : 0) + 1);
}
fputs("to make ", fp);
if (cookData->handleOutput == Toss) {
fputs("(and toss) ", fp);
}
else if (cookData->handleOutput == Autoplace) {
fputs("(and auto-place) ", fp);
}
fprintf(fp, "<%s>", getItemName(cookData->output));
if (cookData->handleOutput == TossOther) {
fprintf(fp, ", toss [%s] in slot %d", getItemName(cookData->toss), cookData->indexToss + 1);
}
if (curNode->numOutputsCreated == NUM_RECIPES) {
if (((Cook *) curNode->description.data)->handleOutput == Autoplace) {
fputs(" (No-Toss 5 Frame Penalty for Jump Storage)", fp);
}
else {
fputs(" (Jump Storage on Tossed Item)", fp);
}
}
}
/*-------------------------------------------------------------------
* Function : printFileHeader
* Inputs : FILE *fp
*
* Print to a txt file the header information for the file.
-------------------------------------------------------------------*/
void printFileHeader(FILE *fp) {
fputs("Description\tFrames Taken\tTotal Frames", fp);
for (int i = 0; i < 20; i++) {
fprintf(fp, "\tSlot #%d", i+1);
}
for (int i = 0; i < NUM_RECIPES; i++) {
fprintf(fp, "\t%s", getItemName(recipeList[i].output));
}
fprintf(fp, "\n");
recipeLog(5, "Calculator", "File", "Write", "Header for new output written");
}
/*-------------------------------------------------------------------
* Function : printInventoryData
* Inputs : BranchPath *curNode
* FILE *fp
*
* Print to a txt file the header information for the file.
-------------------------------------------------------------------*/
void printInventoryData(const BranchPath *curNode, FILE *fp) {
int nulls = curNode->inventory.nulls;
int i;
for (i = nulls; i < 10; ++i) {
fprintf(fp, "\t%s", getItemName(curNode->inventory.inventory[i]));
}
for (i = 0; i < nulls; ++i) {
fprintf(fp, "\tNULL");
}
for (i = 10; i < curNode->inventory.length - nulls; ++i) {
fprintf(fp, "\t%s", getItemName(curNode->inventory.inventory[i]));
}
for (; i < curNode->inventory.length; ++i) {
fprintf(fp, "\t(%s)", getItemName(curNode->inventory.inventory[i]));
}
for (; i < 20; ++i) {
fprintf(fp, "\tBLOCKED");
}
}
/*-------------------------------------------------------------------
* Function : printOutputsCreated
* Inputs : BranchPath *curNode
* FILE *fp
*
* Print to a txt file data pertaining to which recipes
* have been cooked thus far.
-------------------------------------------------------------------*/
void printOutputsCreated(const BranchPath *curNode, FILE *fp) {
for (int i = 0; i < NUM_RECIPES; i++) {
if (curNode->outputCreated[i]) {
fprintf(fp, "\tTrue");
}
else {
fprintf(fp, "\tFalse");
}
}
}
void printNodeDescription(const BranchPath * curNode, FILE * fp)
{
MoveDescription desc = curNode->description;
enum Action curNodeAction = desc.action;
switch (curNodeAction) {
case ECook:
printCookData(curNode, desc, fp);
break;
case ECh5:
printCh5Data(curNode, desc, fp);
break;
case EBegin:
fputs("Begin", fp);
break;
default:
// Some type of sorting
printSortData(fp, curNodeAction);
}
}
/*-------------------------------------------------------------------
* Function : printResults
* Inputs : char *filename
* BranchPath *path
*
* Parent function for children print functions. This parent function
* is called when a roadmap has been found which beats the current
* local record.
-------------------------------------------------------------------*/
void printResults(const char *filename, const BranchPath *path) {
FILE *fp = fopen(filename, "w");
if (fp == NULL) {
printf("Could not locate %s... This is a bug.\n", filename);
printf("Press ENTER to exit.\n");
awaitKeyFromUser();
exit(1);
}
// Write header information
printFileHeader(fp);
// Print data information
const BranchPath *curNode = path;
do {
printNodeDescription(curNode, fp);
// Print out frames taken
fprintf(fp, "\t%d", curNode->description.framesTaken);
// Print out total frames taken
fprintf(fp, "\t%d", curNode->description.totalFramesTaken);
// Print out inventory
printInventoryData(curNode, fp);
// Print out whether or not all 58 items were created
printOutputsCreated(curNode, fp);
// Add newline character to put next node on new line
fprintf(fp, "\n");
} while ((curNode = curNode->next) != NULL);
fclose(fp);
recipeLog(5, "Calculator", "File", "Write", "Data for roadmap written.");
}
/*-------------------------------------------------------------------
* Function : printSortData
* Inputs : FILE *fp
* enum Action curNodeAction
*
* Print to a file data which pertains to sorting the inventory.
-------------------------------------------------------------------*/
void printSortData(FILE *fp, enum Action curNodeAction) {
fprintf(fp, "Sort - ");
switch (curNodeAction) {
case ESort_Alpha_Asc:
fputs("Alphabetical", fp);
break;
case ESort_Alpha_Des:
fputs("Reverse Alphabetical", fp);
break;
case ESort_Type_Asc:
fputs("Type", fp);
break;
case ESort_Type_Des:
fputs("Reverse Type", fp);
break;
default:
fputs("ERROR IN HANDLING OF SORT", fp);
};
}