Repository navigation
Expand file tree
/
Copy pathcommon.cpp
More file actions
823 lines (761 loc) · 22.2 KB
/
Copy pathcommon.cpp
File metadata and controls
823 lines (761 loc) · 22.2 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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
#include "common.h"
const int DECREMENT_SKILL_GAGE[] = {
0, // 0 chains
0, // 1 chains
0, // 2 chains
18, // 3 chains
20, // 4 chains
22, // 5 chains
24, // 6 chains
26, // 7 chains
28, // 8 chains
30, // 9 chains
32, // 10 chains
34, // 11 chains
36, // 12 chains
38, // 13 chains
40, // 14 chains
42, // 15 chains
44, // 16 chains
46, // 17 chains
48, // 18 chains
50, // 19 chains
52, // 20 chains
54, // 21 chains
56, // 22 chains
58, // 23 chains
60, // 24 chains
62, // 25 chains
64, // 26 chains
66, // 27 chains
68, // 28 chains
70, // 29 chains
72, // 30 chains
74, // 31 chains
76, // 32 chains
78, // 33 chains
80, // 34 chains
82, // 35 chains
84, // 36 chains
86, // 37 chains
88, // 38 chains
90, // 39 chains
92, // 40 chains
94, // 41 chains
96, // 42 chains
98, // 43 chains
100, // 44 chains
102, // 45 chains
104, // 46 chains
106, // 47 chains
108, // 48 chains
110, // 49 chains
112, // 50 chains
114, // 51 chains
116, // 52 chains
118, // 53 chains
120, // 54 chains
122, // 55 chains
124, // 56 chains
126, // 57 chains
128, // 58 chains
130, // 59 chains
132, // 60 chains
134, // 61 chains
136, // 62 chains
138, // 63 chains
140, // 64 chains
142, // 65 chains
144, // 66 chains
146, // 67 chains
148, // 68 chains
150, // 69 chains
152, // 70 chains
154, // 71 chains
156, // 72 chains
158, // 73 chains
160, // 74 chains
162, // 75 chains
164, // 76 chains
166, // 77 chains
168, // 78 chains
170, // 79 chains
172 // 80 chains
};
const long long CHAIN_SCORE[] = {
0LL, // 0 chains
1LL, // 1 chains
2LL, // 2 chains
4LL, // 3 chains
6LL, // 4 chains
9LL, // 5 chains
13LL, // 6 chains
19LL, // 7 chains
27LL, // 8 chains
37LL, // 9 chains
50LL, // 10 chains
67LL, // 11 chains
90LL, // 12 chains
120LL, // 13 chains
159LL, // 14 chains
210LL, // 15 chains
276LL, // 16 chains
362LL, // 17 chains
474LL, // 18 chains
620LL, // 19 chains
810LL, // 20 chains
1057LL, // 21 chains
1378LL, // 22 chains
1795LL, // 23 chains
2337LL, // 24 chains
3042LL, // 25 chains
3959LL, // 26 chains
5151LL, // 27 chains
6701LL, // 28 chains
8716LL, // 29 chains
11335LL, // 30 chains
14740LL, // 31 chains
19167LL, // 32 chains
24923LL, // 33 chains
32405LL, // 34 chains
42132LL, // 35 chains
54778LL, // 36 chains
71218LL, // 37 chains
92590LL, // 38 chains
120373LL, // 39 chains
156491LL, // 40 chains
203445LL, // 41 chains
264485LL, // 42 chains
343838LL, // 43 chains
446997LL, // 44 chains
581103LL, // 45 chains
755441LL, // 46 chains
982081LL, // 47 chains
1276713LL, // 48 chains
1659735LL, // 49 chains
2157664LL, // 50 chains
2804971LL, // 51 chains
3646471LL, // 52 chains
4740421LL, // 53 chains
6162556LL, // 54 chains
8011332LL, // 55 chains
10414741LL, // 56 chains
13539173LL, // 57 chains
17600934LL, // 58 chains
22881224LL, // 59 chains
29745601LL, // 60 chains
38669291LL, // 61 chains
50270088LL, // 62 chains
65351124LL, // 63 chains
84956471LL, // 64 chains
110443422LL, // 65 chains
143576459LL, // 66 chains
186649407LL, // 67 chains
242644240LL, // 68 chains
315437523LL, // 69 chains
410068791LL, // 70 chains
533089439LL, // 71 chains
693016282LL, // 72 chains
900921178LL, // 73 chains
1171197543LL, // 74 chains
1522556818LL, // 75 chains
1979323876LL, // 76 chains
2573121051LL, // 77 chains
3345057379LL, // 78 chains
4348574605LL, // 79 chains
5653147000LL // 80 chains
};
const long long SKILL_CHAIN_SCORE[] = {
0LL, // 0 chains
1LL, // 1 chains
2LL, // 2 chains
4LL, // 3 chains
6LL, // 4 chains
9LL, // 5 chains
13LL, // 6 chains
19LL, // 7 chains
27LL, // 8 chains
37LL, // 9 chains
50LL, // 10 chains
67LL, // 11 chains
90LL, // 12 chains
120LL, // 13 chains
159LL, // 14 chains
210LL, // 15 chains
276LL, // 16 chains
362LL, // 17 chains
474LL, // 18 chains
620LL, // 19 chains
810LL, // 20 chains
1057LL, // 21 chains
1378LL, // 22 chains
1795LL, // 23 chains
2337LL, // 24 chains
3042LL, // 25 chains
3959LL, // 26 chains
5151LL, // 27 chains
6701LL, // 28 chains
8716LL, // 29 chains
11335LL, // 30 chains
14740LL, // 31 chains
19167LL, // 32 chains
24923LL, // 33 chains
32405LL, // 34 chains
42132LL, // 35 chains
54778LL, // 36 chains
71218LL, // 37 chains
92590LL, // 38 chains
120373LL, // 39 chains
156491LL, // 40 chains
203445LL, // 41 chains
264485LL, // 42 chains
343838LL, // 43 chains
446997LL, // 44 chains
581103LL, // 45 chains
755441LL, // 46 chains
982081LL, // 47 chains
1276713LL, // 48 chains
1659735LL, // 49 chains
2157664LL, // 50 chains
2804971LL, // 51 chains
3646471LL, // 52 chains
4740421LL, // 53 chains
6162556LL, // 54 chains
8011332LL, // 55 chains
10414741LL, // 56 chains
13539173LL, // 57 chains
17600934LL, // 58 chains
22881224LL, // 59 chains
29745601LL, // 60 chains
38669291LL, // 61 chains
50270088LL, // 62 chains
65351124LL, // 63 chains
84956471LL, // 64 chains
110443422LL, // 65 chains
143576459LL, // 66 chains
186649407LL, // 67 chains
242644240LL, // 68 chains
315437523LL, // 69 chains
410068791LL, // 70 chains
533089439LL, // 71 chains
693016282LL, // 72 chains
900921178LL, // 73 chains
1171197543LL, // 74 chains
1522556818LL, // 75 chains
1979323876LL, // 76 chains
2573121051LL, // 77 chains
3345057379LL, // 78 chains
4348574605LL, // 79 chains
5653147000LL // 80 chains
};
const int EXPLODE_SCORE[] = {
25, // 0 blocks
26, // 1 blocks
28, // 2 blocks
29, // 3 blocks
31, // 4 blocks
33, // 5 blocks
35, // 6 blocks
37, // 7 blocks
39, // 8 blocks
42, // 9 blocks
44, // 10 blocks
47, // 11 blocks
50, // 12 blocks
52, // 13 blocks
56, // 14 blocks
59, // 15 blocks
62, // 16 blocks
66, // 17 blocks
70, // 18 blocks
74, // 19 blocks
79, // 20 blocks
84, // 21 blocks
89, // 22 blocks
94, // 23 blocks
100, // 24 blocks
105, // 25 blocks
112, // 26 blocks
118, // 27 blocks
125, // 28 blocks
133, // 29 blocks
141, // 30 blocks
149, // 31 blocks
158, // 32 blocks
168, // 33 blocks
178, // 34 blocks
188, // 35 blocks
200, // 36 blocks
211, // 37 blocks
224, // 38 blocks
237, // 39 blocks
251, // 40 blocks
266, // 41 blocks
282, // 42 blocks
299, // 43 blocks
317, // 44 blocks
336, // 45 blocks
356, // 46 blocks
377, // 47 blocks
400, // 48 blocks
423, // 49 blocks
448, // 50 blocks
475, // 51 blocks
503, // 52 blocks
533, // 53 blocks
565, // 54 blocks
599, // 55 blocks
634, // 56 blocks
672, // 57 blocks
712, // 58 blocks
755, // 59 blocks
800, // 60 blocks
847, // 61 blocks
897, // 62 blocks
951, // 63 blocks
1007, // 64 blocks
1067, // 65 blocks
1131, // 66 blocks
1198, // 67 blocks
1269, // 68 blocks
1345, // 69 blocks
1425, // 70 blocks
1510, // 71 blocks
1600, // 72 blocks
1695, // 73 blocks
1795, // 74 blocks
1902, // 75 blocks
2015, // 76 blocks
2135, // 77 blocks
2262, // 78 blocks
2397, // 79 blocks
2539, // 80 blocks
2690, // 81 blocks
2850, // 82 blocks
3020, // 83 blocks
3200, // 84 blocks
3390, // 85 blocks
3591, // 86 blocks
3805, // 87 blocks
4031, // 88 blocks
4271, // 89 blocks
4525, // 90 blocks
4794, // 91 blocks
5079, // 92 blocks
5381, // 93 blocks
5701, // 94 blocks
6040, // 95 blocks
6400, // 96 blocks
6780, // 97 blocks
7183, // 98 blocks
7610, // 99 blocks
8063, // 100 blocks
8542, // 101 blocks
9050, // 102 blocks
9589, // 103 blocks
10159, // 104 blocks
10763, // 105 blocks
11403, // 106 blocks
12081, // 107 blocks
12800, // 108 blocks
13561, // 109 blocks
14367, // 110 blocks
15221, // 111 blocks
16126, // 112 blocks
17085, // 113 blocks
18101, // 114 blocks
19178, // 115 blocks
20318, // 116 blocks
21526, // 117 blocks
22807, // 118 blocks
24163, // 119 blocks
25600, // 120 blocks
27122, // 121 blocks
28735, // 122 blocks
30443, // 123 blocks
32253, // 124 blocks
34171, // 125 blocks
36203, // 126 blocks
38356, // 127 blocks
40637, // 128 blocks
43053, // 129 blocks
45614, // 130 blocks
48326, // 131 blocks
51200, // 132 blocks
54244, // 133 blocks
57470, // 134 blocks
60887, // 135 blocks
64507, // 136 blocks
68343, // 137 blocks
72407, // 138 blocks
76713, // 139 blocks
81274, // 140 blocks
86107, // 141 blocks
91228, // 142 blocks
96652, // 143 blocks
102400, // 144 blocks
108489, // 145 blocks
114940, // 146 blocks
121774, // 147 blocks
129015, // 148 blocks
136687, // 149 blocks
144815, // 150 blocks
153426, // 151 blocks
162549, // 152 blocks
172215, // 153 blocks
182456, // 154 blocks
193305, // 155 blocks
204800, // 156 blocks
216978, // 157 blocks
229880, // 158 blocks
243549, // 159 blocks
258031 // 160 blocks
};
bool Logger::writeFile = false;
string Logger::fileName{};
void Logger::init() {
writeFile = true;
time_t t = time(nullptr);
char buf[64];
strftime(buf, sizeof(buf), "logs/%Y-%m-%d_%H-%M-%S.log", localtime(&t));
fileName = string(buf);
}
void Logger::print(long long num) {
cerr << num;
if (writeFile) {
ofstream fout(fileName, ios::app);
fout << num;
}
}
void Logger::print(string str) {
cerr << str;
if (writeFile) {
ofstream fout(fileName, ios::app);
fout << str;
}
}
void Logger::print(const char* chr) {
print(move(string(chr)));
}
void Logger::printLine(long long num) {
cerr << num << endl;
if (writeFile) {
ofstream fout(fileName, ios::app);
fout << num << endl;
}
}
void Logger::printLine(string str) {
cerr << str << endl;
if (writeFile) {
ofstream fout(fileName, ios::app);
fout << str << endl;
}
}
void Logger::printLine(const char* chr) {
printLine(string(chr));
}
void Logger::printLine() {
printLine("");
}
Point::Point() = default;
Point::Point(int x, int y) : x(x), y(y) {}
Field::Field() {
memset(columnUpdated, false, sizeof(columnUpdated));
memset(columnHeight, 0, sizeof(columnHeight));
}
long long Field::hashSeed[FIELD_HEIGHT + PACK_SIZE + 1][FIELD_WIDTH][OBSTACLE + 1];
void Field::input(istream &is) {
memset(columnHeight, 0, sizeof(columnHeight));
for (int y = FIELD_HEIGHT + PACK_SIZE; y >= FIELD_HEIGHT; y--) rep(x, FIELD_WIDTH) field[y][x] = 0;
for (int y = FIELD_HEIGHT - 1; y >= 0; y--) rep(x, FIELD_WIDTH) {
is >> field[y][x];
if (field[y][x] != 0 && columnHeight[x] == 0) columnHeight[x] = y + 1;
}
}
void Field::freeFall() {
rep(x, FIELD_WIDTH) {
if (!columnUpdated[x]) continue;
columnUpdated[x] = false;
int bottom = 0;
rep(y, columnHeight[x]) {
if (field[y][x] != 0) {
field[bottom][x] = field[y][x];
if (bottom != y) field[y][x] = 0;
bottom++;
}
}
columnHeight[x] = bottom;
}
}
int Field::eraseBlocks() {
// TODO: 高速化の余地がありそう
vector<Point> erasedPoints;
rep(x, FIELD_WIDTH) rep(y, columnHeight[x]) {
if (field[y][x] == 0 || field[y][x] == OBSTACLE) continue;
rep(directionIdx, 4) {
int ix = x + DX[directionIdx];
int iy = y + DY[directionIdx];
if (!inField(ix, iy)) continue;
int sum = field[y][x] + field[iy][ix];
if (sum == ERASE_SUM) {
erasedPoints.emplace_back(x, y);
erasedPoints.emplace_back(ix, iy);
}
}
}
int cnt = 0;
for (auto p : erasedPoints) {
cnt += field[p.y][p.x] != 0;
field[p.y][p.x] = 0;
columnUpdated[p.x] = true;
}
return cnt;
}
bool Field::isAlive() {
rep(x, FIELD_WIDTH) {
if (field[FIELD_HEIGHT][x] != 0) return false;
}
return true;
}
bool Field::inField(int x, int y) {
return x >= 0 && x < field[0].size() && y >= 0 && y < field.size();
}
int Field::dropPack(const Pack &pack, int position, int rotation) {
return dropPackWithInfo(pack, position, rotation).chainNum;
}
ChainInfo Field::dropPackWithInfo(const Pack &pack, int position, int rotation) {
assert(position >= 0 && position < FIELD_WIDTH - 1);
assert(columnHeight[position] + 1 < FIELD_HEIGHT + PACK_SIZE + 1);
if (rotation == 0) {
field[columnHeight[position]][position] = pack[0][0];
field[columnHeight[position] + 1][position] = pack[1][0];
field[columnHeight[position + 1] + 1][position + 1] = pack[1][1];
field[columnHeight[position + 1]][position + 1] = pack[0][1];
} else if (rotation == 1) {
field[columnHeight[position]][position] = pack[0][1];
field[columnHeight[position] + 1][position] = pack[0][0];
field[columnHeight[position + 1] + 1][position + 1] = pack[1][0];
field[columnHeight[position + 1]][position + 1] = pack[1][1];
} else if (rotation == 2) {
field[columnHeight[position]][position] = pack[1][1];
field[columnHeight[position] + 1][position] = pack[0][1];
field[columnHeight[position + 1] + 1][position + 1] = pack[0][0];
field[columnHeight[position + 1]][position + 1] = pack[1][0];
} else if (rotation == 3) {
field[columnHeight[position]][position] = pack[1][0];
field[columnHeight[position] + 1][position] = pack[1][1];
field[columnHeight[position + 1] + 1][position + 1] = pack[0][1];
field[columnHeight[position + 1]][position + 1] = pack[0][0];
} else assert(false);
columnHeight[position] += 2;
columnHeight[position + 1] += 2;
columnUpdated[position] = true;
columnUpdated[position + 1] = true;
return dropWithInfo(position);
}
int Field::drop() {
return dropWithInfo(-1).chainNum;
}
ChainInfo Field::dropWithInfo(int position) {
ChainInfo info;
while (true) {
int eraseNum;
if (info.chainNum == 0) {
Field prevField = *this;
if (position != -1) {
prevField[columnHeight[position] - 1][position] = 0;
prevField[columnHeight[position] - 2][position] = 0;
prevField[columnHeight[position + 1] - 1][position + 1] = 0;
prevField[columnHeight[position + 1] - 2][position + 1] = 0;
prevField.columnHeight[position] -= 2;
prevField.columnHeight[position + 1] -= 2;
}
freeFall();
eraseNum = eraseBlocks();
info.robustNum = [&]() {
rep(y, FIELD_HEIGHT) rep(x, FIELD_WIDTH) {
if (prevField[y][x] != 0 && field[y][x] == 0 && prevField[y + 1][x] != 0) {
info.erasePoint = Point(x, y);
return prevField.calcRobustNum(x, y);
}
}
return -1;
}();
} else {
freeFall();
eraseNum = eraseBlocks();
}
if (eraseNum == 0) {
if (!isAlive()) info.chainNum = -1;
break;
}
info.eraseBlockNum += eraseNum;
info.chainNum++;
}
return info;
}
void Field::fallObstacle() {
rep(x, FIELD_WIDTH) {
field[columnHeight[x]][x] = OBSTACLE;
columnHeight[x]++;
}
}
void Field::update(int x, int y, int block) {
columnUpdated[x] = true;
field[y][x] = block;
}
int Field::countNumberBlock() {
int cnt = 0;
rep(x, FIELD_WIDTH) rep(y, columnHeight[x]) {
if (field[y][x] >= 1 && field[y][x] <= 9) cnt++;
}
return cnt;
}
int Field::countBlock() {
int cnt = 0;
rep(x, FIELD_WIDTH) {
cnt += columnHeight[x];
}
return cnt;
}
int Field::countExplodeBlockNum() {
int cnt = 0;
rep(x, FIELD_WIDTH) rep(y, columnHeight[x]) {
if (field[y][x] == 0 || field[y][x] == OBSTACLE) continue;
cnt += [&]() {
for (int dy = -1; dy <= 1; dy++) for (int dx = -1; dx <= 1; dx++) {
int nx = x + dx;
int ny = y + dy;
if (!inField(nx, ny)) continue;
if (field[ny][nx] == EXPLODE_NUM) return 1;
}
return 0;
}();
}
return cnt;
}
int Field::countAvailableCell() {
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
bool visited[FIELD_HEIGHT][FIELD_WIDTH];
memset(visited, false, sizeof(visited));
queue<Point> q;
rep(x, FIELD_WIDTH) {
if (field[FIELD_HEIGHT - 1][x] == OBSTACLE) continue;
q.push(Point(x, FIELD_HEIGHT - 1));
visited[FIELD_HEIGHT - 1][x] = true;
}
int cnt = 0;
while (!q.empty()) {
auto p = q.front(); q.pop();
cnt++;
rep(dir, 8) {
int nx = p.x + dx[dir];
int ny = p.y + dy[dir];
if (nx < 0 || nx >= FIELD_WIDTH || ny < 0 || ny >= FIELD_HEIGHT) continue;
if (field[ny][nx] == OBSTACLE) continue;
if (visited[ny][nx]) continue;
visited[ny][nx] = true;
q.push(Point(nx, ny));
}
}
return cnt;
}
int Field::getMaxBlockHeight() {
for (int y = FIELD_HEIGHT + PACK_SIZE; y >= 0; y--) rep(x, FIELD_WIDTH) {
if (field[y][x] != 0) return y;
}
return -1;
}
int Field::calcRobustNum(int x, int y) {
if (field[y][x] == 0 || field[y][x] == OBSTACLE) return -1;
int ret = -1;
rep(ty, FIELD_HEIGHT) {
if ((x > 0 && field[ty][x - 1] == 0)
|| (x < FIELD_WIDTH - 1 && field[ty][x + 1] == 0)) {
ret = y - ty + 1;
break;
}
}
return ret;
}
void Field::initHashSeed() {
RandomNumberGenerator rng;
rep(y, FIELD_HEIGHT + PACK_SIZE + 1) rep(x, FIELD_WIDTH) rep(i, OBSTACLE + 1) {
hashSeed[y][x][i] = rng.rand();
}
}
unsigned long long Field::getHash() {
unsigned long long hash = 0;
rep(y, FIELD_HEIGHT) rep(x, FIELD_WIDTH) {
hash ^= hashSeed[y][x][field[y][x]];
}
return hash;
}
void Field::print(ostream& os) {
for (int y = field.size() - 1; y >= 0; y--) {
rep(x, FIELD_WIDTH) {
os << field[y][x] << " ";
}
os << endl;
}
}
array<int, FIELD_WIDTH>& Field::operator[](int idx) {
return field[idx];
}
void Player::input(istream& is) {
is >> leftTime;
is >> obstacleStock;
is >> skillGage;
is >> score;
field.input(is);
string end;
is >> end;
}
void Player::fallObstacles() {
if (obstacleStock < FIELD_WIDTH) return;
obstacleStock -= FIELD_WIDTH;
field.fallObstacle();
}
void Player::increaseSkillGage() {
skillGage += INCREMENT_SKILL_GAGE;
skillGage = min(skillGage, 100);
}
void Game::inputPackInfo(istream& is) {
string end;
for (auto& pack : packs) {
for (int y = PACK_SIZE - 1; y >= 0; y--) rep(x, PACK_SIZE) is >> pack[y][x];
is >> end;
}
}
void Game::inputTurnInfo(istream& is) {
is >> turn;
player[0].input(is);
player[1].input(is);
}
Action Action::createDropPackAction(int position, int rotation) {
Action action{};
action.type = ActionType::DROP_PACK;
action.position = position;
action.rotation = rotation;
return action;
}
Action Action::createExplodeAction() {
Action action{};
action.type = ActionType::EXPLODE;
return action;
}
Timer::Timer() {
beginCycle = getCycle();
}
double Timer::getTime() {
return (double)(getCycle() - beginCycle) / 2500000000;
}
unsigned long long RandomNumberGenerator::rand() {
static unsigned long long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
unsigned long long t = (x ^ (x << 11));
x = y;
y = z;
z = w;
return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}