5
5
#include < iostream>
6
6
#include < filesystem>
7
7
#include < string>
8
+ #include < vector>
9
+ #include < algorithm>
8
10
9
11
namespace fs = std::filesystem;
10
12
using namespace std ;
@@ -62,6 +64,7 @@ map<string, Solution> solutions;
62
64
map<string, Info> dataMap;
63
65
vector<string> ids = { };
64
66
vector<string> battles = { };
67
+ vector<string> bonus = { };
65
68
66
69
// Utils
67
70
string readString (ifstream& stream) {
@@ -157,6 +160,7 @@ int main(int argc, char* argv[])
157
160
int globalCounter = 0 ;
158
161
int solutionCounter = 1 ;
159
162
int battleCounter = 1 ;
163
+ int bonusCounter = 1 ;
160
164
string line;
161
165
while (getline (dataStream, line)) {
162
166
int i1 = line.find (' ,' );
@@ -171,6 +175,8 @@ int main(int argc, char* argv[])
171
175
172
176
bool isBattle = description.rfind (" battle-" , 0 ) == 0 ;
173
177
int counter = isBattle ? battleCounter++ : solutionCounter++;
178
+ bool isBonus = description.rfind (" bonus-" , 0 ) == 0 ;
179
+ counter = isBonus ? bonusCounter++ : counter;
174
180
175
181
// Create path based on title
176
182
string path = ((counter < 10 ) ? (" 0" + to_string (counter)) : to_string (counter)) + ' -' ;
@@ -200,8 +206,9 @@ int main(int argc, char* argv[])
200
206
201
207
dataMap[id] = info;
202
208
203
- if (!isBattle) ids.push_back (id);
209
+ if (!isBattle) ids.push_back (id);
204
210
else battles.push_back (id);
211
+ if (isBonus) bonus.push_back (id);
205
212
206
213
globalCounter++;
207
214
}
@@ -323,6 +330,15 @@ int main(int argc, char* argv[])
323
330
cout << " No 'battles' directory found" << endl;
324
331
}
325
332
333
+ fs::path pathOutputBonus = pathOutput / " bonus" ;
334
+ if (fs::is_directory (pathOutputBonus)) {
335
+ fs::remove_all (pathOutputBonus);
336
+ cout << " Clearing 'bonus' directory" << endl;
337
+ }
338
+ else {
339
+ cout << " No 'bonus' directory found" << endl;
340
+ }
341
+
326
342
cout << endl << " Create files:" << endl;
327
343
328
344
// Create README
@@ -360,7 +376,7 @@ int main(int argc, char* argv[])
360
376
for (int i = 0 ; i < maxChars + 2 + 4 ; i++) readmeOut << ' -' ;
361
377
readmeOut << " |--------|------|----------|" << endl;
362
378
363
- for (int i = 0 ; i < ids. size () ; i++) {
379
+ for (int i = 0 ; i < 34 ; i++) {
364
380
Info info = dataMap[ids[i]];
365
381
readmeOut << " | [" << to_string (i + 1 ) << " : " << info.title << " ](solutions/" << info.path << " ) " ;
366
382
@@ -404,6 +420,34 @@ int main(int argc, char* argv[])
404
420
writeNum (readmeOut, solution.losses , 6 );
405
421
readmeOut << " | S+ |" << endl;
406
422
}
423
+
424
+ // Create bonus
425
+ readmeOut << endl << " | Bonus campaign level" ;
426
+ for (int i = 0 ; i < maxChars - 5 + 1 + 4 ; i++) readmeOut << ' ' ;
427
+ readmeOut << " | Cycles | Size | Activity |" << endl;
428
+
429
+ readmeOut << " |" ;
430
+ for (int i = 0 ; i < maxChars + 2 + 4 ; i++) readmeOut << ' -' ;
431
+ readmeOut << " |--------|------|----------|" << endl;
432
+
433
+ for (int i = 0 ; i < bonus.size (); i++) {
434
+ Info info = dataMap[bonus[i]];
435
+ readmeOut << " | [" << to_string (i + 1 ) << " : " << info.title << " ](bonus/" << info.path << " ) " ;
436
+
437
+ int total = maxChars - (1 + info.title .length () + 12 + info.path .length () + 1 );
438
+ for (int j = 0 ; j < total; j++) readmeOut << ' ' ;
439
+
440
+ if (i < 9 ) readmeOut << ' ' ;
441
+
442
+ Solution solution = solutions[ids[34 + i]];
443
+ readmeOut << " | " ;
444
+ writeNum (readmeOut, solution.cycles , CYCLE_N);
445
+ readmeOut << " | " ;
446
+ writeNum (readmeOut, solution.size , SIZE_N);
447
+ readmeOut << " | " ;
448
+ writeNum (readmeOut, solution.activity , ACTIVITY_N);
449
+ readmeOut << " |" << endl;
450
+ }
407
451
}
408
452
else if (line == " <!-- EXA_END -->" ) {
409
453
readmeOut << line << endl;
@@ -425,7 +469,7 @@ int main(int argc, char* argv[])
425
469
426
470
cout << endl << " Making solutions:" << endl;
427
471
428
- for (int i = 0 ; i < ids. size () ; i++) {
472
+ for (int i = 0 ; i < 34 ; i++) {
429
473
Info info = dataMap[ids[i]];
430
474
431
475
fs::create_directories (pathOutputSolutions / info.path );
@@ -531,4 +575,66 @@ int main(int argc, char* argv[])
531
575
532
576
cout << " " << info.title << endl;
533
577
}
578
+
579
+ // Create bonus folder
580
+ fs::create_directories (pathOutputBonus);
581
+
582
+ cout << endl << " Making bonus:" << endl;
583
+
584
+ for (int i = 0 ; i < bonus.size (); i++) {
585
+ Info info = dataMap[bonus[i]];
586
+
587
+ fs::create_directories (pathOutputBonus / info.path );
588
+ ofstream readmeOut (pathOutputBonus / info.path / " README.md" );
589
+
590
+ readmeOut << " # " << to_string (i + 1 ) << " : " << info.title << endl << endl;
591
+
592
+ // Copy GIF
593
+ fs::copy (info.gif , pathOutputBonus / info.path / info.gif .filename ());
594
+ readmeOut << " <div align=\" center\" ><img src=\" " << info.gif .filename ().string () << " \" /></div>" << endl << endl;
595
+
596
+ // Read description files
597
+ ifstream descriptionStream (pathDescriptions / info.description );
598
+ if (descriptionStream) {
599
+ readmeOut << " ## Instructions" << endl;
600
+ while (getline (descriptionStream, line)) {
601
+ readmeOut << " > " << line << endl;
602
+ }
603
+ readmeOut << endl;
604
+ }
605
+
606
+ readmeOut << " ## Solution" << endl << endl;
607
+
608
+ // Add source as well
609
+ Solution solution = solutions[bonus[i]];
610
+
611
+ for (int j = 0 ; j < solution.exas .size (); j++) {
612
+ EXA exa = solution.exas [j];
613
+ readmeOut << " ### [" << exa.name << " ](" << exa.name << " .exa) (" << (exa.local ? " local" : " global" ) << " )" << endl;
614
+ readmeOut << " ```asm" << endl;
615
+ readmeOut << exa.source << endl;
616
+ readmeOut << " ```" << endl << endl;
617
+
618
+ // Generate file as well
619
+ ofstream exaOut (pathOutputBonus / info.path / (exa.name + " .exa" ));
620
+ exaOut << exa.source ;
621
+ }
622
+
623
+ // Copy OG file save as well
624
+ fs::copy (solution.path , pathOutputBonus / info.path / solution.path .filename ());
625
+
626
+ // Add score
627
+ readmeOut << " #### Results" << endl;
628
+ readmeOut << " | Cycles | Size | Activity |" << endl;
629
+ readmeOut << " |--------|------|----------|" << endl;
630
+ readmeOut << " | " ;
631
+ writeNum (readmeOut, solution.cycles , CYCLE_N);
632
+ readmeOut << " | " ;
633
+ writeNum (readmeOut, solution.size , SIZE_N);
634
+ readmeOut << " | " ;
635
+ writeNum (readmeOut, solution.activity , ACTIVITY_N);
636
+ readmeOut << " |" << endl;
637
+
638
+ cout << " " << info.title << endl;
639
+ }
534
640
}
0 commit comments