-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAI.cpp
1840 lines (1753 loc) · 79.7 KB
/
AI.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
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
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <vector>
#include <thread>
#include <cmath>
#include <array>
#include "AI.h"
#include "constants.h"
#define MeaningfulValue1 1 // F above this value means the student is valuable enough to use prop AddSpeed
#define MeaningfulValue2 2 // F above this value means the student is valuable enough to use prop ClairAudience
using namespace std;
// 为假则play()期间确保游戏状态不更新,为真则只保证游戏状态在调用相关方法时不更新
extern const bool asynchronous = true;
// 选手需要依次将player0到player4的职业在这里定义
extern const std::array<THUAI6::StudentType, 4> studentType = {
THUAI6::StudentType::StraightAStudent,
THUAI6::StudentType::StraightAStudent,
THUAI6::StudentType::StraightAStudent,
THUAI6::StudentType::StraightAStudent};
extern const THUAI6::TrickerType trickerType = THUAI6::TrickerType::Assassin;
// 可以在AI.cpp内部声明变量与函数
#pragma region 常量
const int myGridPerSquare = 100;
const int numSquarePerCell = numOfGridPerCell / myGridPerSquare;
const int myRow = Constants::rows * numOfGridPerCell / myGridPerSquare;
const int myCol = Constants::cols * numOfGridPerCell / myGridPerSquare; // NEW CONSTANT ADDED
#define framet Constants::frameDuration
#pragma endregion
bool firstTime = false;
std::shared_ptr<const THUAI6::Student> selfInfoStudent;
std::shared_ptr<const THUAI6::Tricker> selfInfoTricker;
std::shared_ptr<const THUAI6::Player> selfInfo;
std::shared_ptr<const THUAI6::GameInfo> gameInfo;
std::shared_ptr<const THUAI6::Student> students[4];
int studentsFrame[4];
int TrickerIdlePhase = 0;
double F_parameters[5][7] = {{0, 0, 10000, 0, 0, 0, 0}, {0, 1, 10000, 1, 1, 1, 1}, {0, 20000, 0, 20000, 20000, 20000, 20000}, {0, 200, 0, 200, 200, 200, 200}, {0, 0.4, 0, 0.4, 0.4, 0.4, 0.4}};
int myOriVelocity;
int myVelocity;
#pragma region 自定义辅助
class XY
{
public:
int x, y;
XY(int xx, int yy) :
x(xx),
y(yy)
{
}
XY()
{
x = y = 0;
}
XY operator-(const XY& A) const;
XY operator+(const XY& A) const;
};
XY XY::operator-(const XY& A) const
{
XY B;
B.x = this->x - A.x;
B.y = this->y - A.y;
return B;
}
XY XY::operator+(const XY& A) const
{
XY B;
B.x = this->x + A.x;
B.y = this->y + A.y;
return B;
}
class XYSquare : public XY
{
public:
XYSquare(int xx, int yy) :
XY(xx, yy)
{
}
XYSquare() :
XY()
{
}
friend bool operator==(XYSquare comp1, XYSquare comp2);
} selfSquare;
bool operator==(XYSquare comp1, XYSquare comp2)
{
return (comp1.x == comp2.x && comp1.y == comp2.y);
}
class XYGrid : public XY
{
public:
XYGrid(int xx, int yy) :
XY(xx, yy)
{
}
XYGrid() :
XY()
{
}
};
XYSquare GridToSquare(XYGrid xy)
{
return XYSquare(xy.x / myGridPerSquare, xy.y / myGridPerSquare);
}
XYGrid SquareToGrid(XYSquare xy)
{
return XYGrid(xy.x * myGridPerSquare + myGridPerSquare / 2, xy.y * myGridPerSquare + myGridPerSquare / 2);
}
class XYCell : public XY
{
public:
XYCell(int xx, int yy) :
XY(xx, yy)
{
}
XYCell() :
XY()
{
}
};
XYGrid CellToGrid(XYCell xy)
{
return XYGrid(xy.x * numOfGridPerCell + numOfGridPerCell / 2, xy.y * numOfGridPerCell + numOfGridPerCell / 2);
}
XYCell numGridToXYCell(int x, int y)
{
return XYCell(x / numOfGridPerCell, y / numOfGridPerCell);
}
XYCell XYToCell(XY xy)
{
return XYCell(xy.x, xy.y);
}
int numGridToSquare(int grid) // Converting no. of grids in a given row to its corresponding square number
{
return grid / myGridPerSquare;
}
int numGridToCell(int grid)
{
return grid / numOfGridPerCell;
}
XYSquare numGridToXYSquare(int gridx, int gridy) // Converting grid coordinates row to its corresponding square instance
{
return XYSquare(gridx / myGridPerSquare, gridy / myGridPerSquare);
}
XYCell numSquareToXYCell(int squarex, int squarey)
{
return XYCell(squarex / numSquarePerCell, squarey / numSquarePerCell);
}
bool IsApproach(XYCell cell)
{
return abs(numGridToCell(selfInfo->x) - cell.x) <= 1 && abs(numGridToCell(selfInfo->y) - cell.y) <= 1;
}
bool ApproachToInteractInACross(XYCell cell)
{
return (abs(numGridToCell(selfInfo->x) - cell.x) + abs(numGridToCell(selfInfo->y) - cell.y)) <= 1;
}
XYCell SquareToCell(XYSquare xy)
{
return XYCell(xy.x / numSquarePerCell, xy.y / numSquarePerCell);
}
inline double dist(const XYGrid& vec)
{
return sqrt(vec.x * vec.x + vec.y * vec.y);
}
int DistanceUP(int x, int y)
{
return int(sqrt((x - selfInfo->x) * (x - selfInfo->x) + (y - selfInfo->y) * (y - selfInfo->y)) + 1);
}
#pragma endregion
#pragma region Map
std::vector<std::vector<THUAI6::PlaceType>> oriMap;
int speedOriMap[myRow][myRow]; // 0 Wall
int untilTimeMap[myRow][myRow]; //处理门,隐藏校门等
int disMap[myRow][myRow]; //实际距离
XYSquare fromMap[myRow][myRow];
XYCell ClassroomCell[Constants::numOfClassroom];
XYCell openedGateCell[2 + 1];
XYCell GateCell[2];
// XYCell DoorCell
#pragma endregion
// The region above is moved to use oriMap
XYSquare IdleAim = XYSquare(-1, -1);
class BGM_Utilize
{
public:
void UpdateBGM(double trickDesire, double classVolume);
inline bool Decreasing() const;
XYSquare GradientAim(bool aimrow) const;
inline bool DecreasingClassVolume() const;
inline void GetDir(double dirs[2]) const;
inline void GetField(bool row, double ret[2]) const;
private:
double bgm[2][3] = {0};
double PastDir[2] = {0};
} BGM;
void BGM_Utilize::UpdateBGM(double trickDesire, double classVolume)
{
this->bgm[0][2] = this->bgm[0][1], this->bgm[1][2] = this->bgm[1][1];
this->bgm[0][1] = this->bgm[0][0], this->bgm[1][1] = this->bgm[1][0];
this->bgm[0][0] = trickDesire, this->bgm[1][2] = classVolume;
PastDir[1] = PastDir[0];
PastDir[0] = selfInfo->facingDirection;
return;
}
inline bool BGM_Utilize::Decreasing() const
{
return (this->bgm[0][0] < this->bgm[0][2] && this->bgm[1][0] < this->bgm[1][2]);
}
inline bool BGM_Utilize::DecreasingClassVolume() const
{
return this->bgm[1][0] < this->bgm[1][2];
}
inline void BGM_Utilize::GetDir(double dirs[2]) const
{
dirs[0] = this->PastDir[0];
dirs[1] = this->PastDir[1];
return;
}
inline void BGM_Utilize::GetField(bool row, double ret[2]) const
{
if (row)
{
ret[0] = this->bgm[1][0] - this->bgm[1][1];
ret[1] = this->bgm[1][1] - this->bgm[1][2];
}
else
{
ret[0] = this->bgm[0][0] - this->bgm[0][1];
ret[1] = this->bgm[0][1] - this->bgm[0][2];
}
return;
}
double SeekDir(double dir1, double dir2, double grad1, double grad2)
{
double PI = acos(-1.0);
double a = dir2 - dir1;
double x = -grad1 + grad2 * cos(a);
double y = grad2 * sin(a);
double k = tan(a + PI / 2);
double b, r;
b = y + k * (0 - x);
if (grad1 == 0)
{
if (b > 0)
{
r = PI / 2;
}
else
{
r = -PI / 2;
}
}
else
{
r = atan2(b, grad1);
}
return (r + dir1);
}
XYSquare BGM_Utilize::GradientAim(bool aimrow) const
{
double dirs[2] = {0};
BGM.GetDir(dirs);
bool shrink = true;
double grads[2] = {0};
printf("GradientAimBegin\n");
if (aimrow)
BGM.GetField(true, grads); // Find larger classVolume
else
BGM.GetField(false, grads); // Normally does not happen, but try to be compatible to find larger TrickDesire
double asylum = SeekDir(dirs[0], dirs[1], grads[0], grads[1]); // Direction of ascending BGM
printf("asylum Found %lf\n", asylum);
XYGrid aiming;
if (aimrow)
aiming = XYGrid((int)(selfInfoTricker->x + 20000 / (bgm[1][2] + 1) * cos(asylum)), (int)(selfInfoTricker->y + 20000 / (bgm[1][2] + 1) * sin(asylum)));
else
aiming = XYGrid((int)(selfInfoTricker->x + 20000 / (bgm[0][2] + 1) * cos(asylum)), (int)(selfInfoTricker->y + 20000 / (bgm[0][2] + 1) * sin(asylum)));
while ((aiming.x >= 1000 && aiming.x < 49000 && aiming.y >= 1000 && aiming.y < 49000) &&
(oriMap[SquareToCell(GridToSquare(aiming)).x][SquareToCell(GridToSquare(aiming)).y] != THUAI6::PlaceType::Grass && oriMap[SquareToCell(GridToSquare(aiming)).x][SquareToCell(GridToSquare(aiming)).y] != THUAI6::PlaceType::Land))
{
if (shrink)
{
aiming.x -= (int)(round(1000 * cos(asylum)));
aiming.y -= (int)(round(1000 * sin(asylum)));
printf("Route shrinking\n");
if (dist(XYGrid(aiming.x - selfInfoTricker->x, aiming.y - selfInfoTricker->y)) < 1000)
{
aiming.x = 2 * selfInfoTricker->x - 25000;
aiming.y = 2 * selfInfoTricker->y - 25000;
shrink = false;
break;
}
}
}
if (!shrink)
{
while ((aiming.x >= 1000 && aiming.x < 49000 && aiming.y >= 1000 && aiming.y < 49000) &&
(oriMap[SquareToCell(GridToSquare(aiming)).x][SquareToCell(GridToSquare(aiming)).y] != THUAI6::PlaceType::Grass && oriMap[SquareToCell(GridToSquare(aiming)).x][SquareToCell(GridToSquare(aiming)).y] != THUAI6::PlaceType::Land))
{
aiming.x += (int)(round(1000 * cos(asylum)));
aiming.y += (int)(round(1000 * sin(asylum)));
printf("Route expanding\n");
}
if ((oriMap[SquareToCell(GridToSquare(aiming)).x][SquareToCell(GridToSquare(aiming)).y] != THUAI6::PlaceType::Grass && oriMap[SquareToCell(GridToSquare(aiming)).x][SquareToCell(GridToSquare(aiming)).y] != THUAI6::PlaceType::Land))
{
printf("Gradaim exit 0");
return GridToSquare(CellToGrid(XYCell(25, 13)));
}
}
if (!(oriMap[SquareToCell(GridToSquare(aiming)).x][SquareToCell(GridToSquare(aiming)).y] != THUAI6::PlaceType::Grass &&
oriMap[SquareToCell(GridToSquare(aiming)).x][SquareToCell(GridToSquare(aiming)).y] != THUAI6::PlaceType::Land))
{
printf("Gradaim exit 1");
return GridToSquare(CellToGrid(SquareToCell(GridToSquare(aiming)))); // Repeated procedures turn target to center of the cell
}
else
{
printf("Gradaim exit 2");
return GridToSquare(CellToGrid(XYCell(25, 13)));
}
}
// How a Tricker perceives a Student
class TrickerPerspect
{
public:
short StudentNumber;
char MovementInUse;
THUAI6::StudentType career;
bool isFixed;
//-2 symbolizes only former is updated, -1 symbolizes NotUpdated but retains former value, 0 symbolizes NotFoundEver, 1 symbolizes useable and is updating
TrickerPerspect(short number) :
StudentNumber(number)
{
MovementInUse = 0;
movement[0] = XYGrid(-1, -1);
movement[1] = XYGrid(-1, -1);
this->playerstate = THUAI6::PlayerState::Idle;
this->F_value = 0;
this->career = THUAI6::StudentType::NullStudentType; // Means not acquired yet
this->isFixed = false;
this->last_blood_value = 30000000;
this->addiction = 0;
this->speed = 3000;
this->radius = 800;
this->lastframe = -1;
this->blacklisted = false;
}
inline long long GetLastBlood() const;
inline XYGrid GetLatestCooridinates() const;
inline void UpdateBlood(long long new_blood);
inline void UpdateMovement(XYGrid grid);
inline void UpdateFValue(long long value);
inline bool GetMovement(XYGrid* copy) const;
inline unsigned long long GetFValue() const;
THUAI6::PlayerState playerstate;
int lastframe;
long long addiction;
long long speed;
int radius;
bool blacklisted;
private:
XYGrid movement[3];
unsigned long long F_value;
unsigned long long last_blood_value;
};
inline long long TrickerPerspect::GetLastBlood() const
{
return this->last_blood_value;
}
inline void TrickerPerspect::UpdateBlood(long long new_blood)
{
this->last_blood_value = new_blood;
return;
}
inline void TrickerPerspect::UpdateMovement(XYGrid grid)
{
if (!((grid.x == -1) && (grid.y == -1)))
{
// Update cooridnates
this->movement[1] = this->movement[0];
this->movement[0] = grid;
// Update MovementInUse
if (MovementInUse == 0 || MovementInUse == -1)
MovementInUse = -2;
else if (MovementInUse == -2)
MovementInUse = 1;
}
else
MovementInUse = -1;
return;
}
inline XYGrid TrickerPerspect::GetLatestCooridinates() const
{
return movement[0];
}
inline void TrickerPerspect::UpdateFValue(long long value)
{
if (value >= 0)
this->F_value = value;
return;
}
inline unsigned long long TrickerPerspect::GetFValue() const
{
return this->F_value;
}
inline bool TrickerPerspect::GetMovement(XYGrid* copy) const
{
if (MovementInUse == -2 || MovementInUse == 0)
return false; // Unable to acquire
else
{
copy[0] = movement[0];
copy[1] = movement[1];
return true;
}
}
TrickerPerspect Trickers_Students[4] = {TrickerPerspect(0), TrickerPerspect(1), TrickerPerspect(2), TrickerPerspect(3)};
short TrickerStatus = -1; // Initialize. Show the lasting status of the Tricker
short fixation = -1; // Symbolizes the status of the Tricker's fixation. 0~3 shows Student Number, -1 means not fixed
THUAI6::PlaceType CellPlaceType(XYCell cell)
{
return oriMap[cell.x][cell.y];
}
void Initialize(const IStudentAPI& api)
{
if (firstTime)
return;
memset(speedOriMap, 0x3f, sizeof(speedOriMap));
firstTime = true;
oriMap = api.GetFullMap();
myOriVelocity = api.GetSelfInfo()->speed;
int i = 0, j = 0, numClassroom = 0, numGate = 0;
int l = 0; // temp
for (i = 0; i < Constants::rows; ++i) // traverse all Cells
{
for (j = 0; j < Constants::rows; ++j)
{
switch (oriMap[i][j]) // To seek the placetype of this square, convert coordinates to cells first
{
case THUAI6::PlaceType::Wall:
case THUAI6::PlaceType::NullPlaceType:
case THUAI6::PlaceType::Chest:
for (int ii = max((i - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); ii < min((i + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 490); ++ii)
for (int jj = max((j - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); jj < min((j + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 490); ++jj)
speedOriMap[ii][jj] = 0;
break;
case THUAI6::PlaceType::Gate:
for (int ii = max((i - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); ii < max((i + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++ii)
for (int jj = max((j - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); jj < max((j + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++jj)
speedOriMap[ii][jj] = 0;
GateCell[numGate++] = XYCell(i, j);
break;
case THUAI6::PlaceType::ClassRoom:
for (int ii = max((i - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); ii < max((i + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++ii)
for (int jj = max((j - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); jj < max((j + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++jj)
speedOriMap[ii][jj] = 0;
ClassroomCell[numClassroom++] = XYCell(i, j);
break;
case THUAI6::PlaceType::Window: // Cases with windows differ with player type and is non-linear with myOriVelocity
switch (api.GetSelfInfo()->studentType)
{
case THUAI6::StudentType::Athlete:
l = Constants::Athlete::speedOfClimbingThroughWindows;
break;
case THUAI6::StudentType::Teacher:
l = Constants::Teacher::speedOfClimbingThroughWindows;
break;
case THUAI6::StudentType::StraightAStudent:
l = Constants::StraightAStudent::speedOfClimbingThroughWindows;
break;
case THUAI6::StudentType::Sunshine:
l = Constants::Sunshine::speedOfClimbingThroughWindows;
break;
default:
l = 0;
break;
}
for (int ii = max((i - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); ii < max((i + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++ii)
for (int jj = max((j - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); jj < max((j + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++jj)
speedOriMap[ii][jj] = l;
break;
case THUAI6::PlaceType::Land:
case THUAI6::PlaceType::Grass:
default:
for (int ii = max((i - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); ii < max((i + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++ii)
for (int jj = max((j - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); jj < max((j + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++jj)
speedOriMap[ii][jj] = myOriVelocity;
break;
}
}
}
}
void Initialize(const ITrickerAPI& api)
{
if (firstTime)
return;
memset(speedOriMap, 0x3f, sizeof(speedOriMap));
firstTime = true;
oriMap = api.GetFullMap();
myOriVelocity = api.GetSelfInfo()->speed;
int i = 0, j = 0, numClassroom = 0, numGate = 0;
int l = 0; // temp
for (i = 0; i < Constants::rows; ++i) // traverse all Cells
{
for (j = 0; j < Constants::rows; ++j)
{
switch (oriMap[i][j]) // To seek the placetype of this square, convert coordinates to cells first
{
case THUAI6::PlaceType::Wall:
case THUAI6::PlaceType::NullPlaceType:
case THUAI6::PlaceType::Chest:
for (int ii = max((i - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); ii < min((i + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 490); ++ii)
for (int jj = max((j - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); jj < min((j + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 490); ++jj)
speedOriMap[ii][jj] = 0;
break;
case THUAI6::PlaceType::Gate:
for (int ii = max((i - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); ii < max((i + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++ii)
for (int jj = max((j - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); jj < max((j + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++jj)
speedOriMap[ii][jj] = 0;
GateCell[numGate++] = XYCell(i, j);
break;
case THUAI6::PlaceType::ClassRoom:
for (int ii = max((i - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); ii < max((i + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++ii)
for (int jj = max((j - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); jj < max((j + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++jj)
speedOriMap[ii][jj] = 0;
ClassroomCell[numClassroom++] = XYCell(i, j);
break;
case THUAI6::PlaceType::Window: // Cases with windows differ with player type and is non-linear with myOriVelocity
l = Constants::Assassin::speedOfClimbingThroughWindows;
for (int ii = max((i - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); ii < max((i + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++ii)
for (int jj = max((j - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); jj < max((j + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++jj)
speedOriMap[ii][jj] = l;
break;
case THUAI6::PlaceType::Land:
case THUAI6::PlaceType::Grass:
default:
for (int ii = max((i - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); ii < max((i + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++ii)
for (int jj = max((j - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); jj < max((j + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++jj)
speedOriMap[ii][jj] = myOriVelocity;
break;
}
}
}
for (l = 0; l < 4; ++l)
Trickers_Students[i] = TrickerPerspect(l);
}
void drawMap(const ITrickerAPI& api)
{
memset(untilTimeMap, 0x3f, sizeof(untilTimeMap));
for (int i = 0; i < Constants::rows; ++i) // traverse all Cells
{
for (int j = 0; j < Constants::rows; ++j)
{
switch (oriMap[i][j]) // To seek the placetype of this square, convert coordinates to cells first
{
case THUAI6::PlaceType::Wall:
case THUAI6::PlaceType::NullPlaceType:
case THUAI6::PlaceType::ClassRoom:
case THUAI6::PlaceType::Gate:
case THUAI6::PlaceType::Chest:
//
case THUAI6::PlaceType::Door6:
case THUAI6::PlaceType::Door3:
case THUAI6::PlaceType::Door5:
case THUAI6::PlaceType::HiddenGate:
// for (int k=)
for (int ii = max((i - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); ii < max((i + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++ii)
for (int jj = max((j - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); jj < max((j + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++jj)
untilTimeMap[ii][jj] = -1;
break;
default:
break;
}
}
}
auto tl = api.GetStudents();
for (int n = 0; n < tl.size(); ++n)
if (Trickers_Students[tl[n]->playerID].addiction > 0 || Trickers_Students[tl[n]->playerID].career == THUAI6::StudentType::Teacher)
{
int tx = numGridToSquare(tl[n]->x), ty = numGridToSquare(tl[n]->y);
for (int i = max(tx - 10, 5); i < min(tx + 10, 496); ++i)
for (int j = max(ty - 10, 5); j < min(ty + 10, 496); ++j)
untilTimeMap[i][j] = -1;
}
}
void drawMap(const IStudentAPI& api)
{
memset(untilTimeMap, 0x3f, sizeof(untilTimeMap));
for (int i = 0; i < Constants::rows; ++i) // traverse all Cells
{
for (int j = 0; j < Constants::rows; ++j)
{
switch (oriMap[i][j]) // To seek the placetype of this square, convert coordinates to cells first
{
case THUAI6::PlaceType::Wall:
case THUAI6::PlaceType::NullPlaceType:
case THUAI6::PlaceType::ClassRoom:
case THUAI6::PlaceType::Gate:
case THUAI6::PlaceType::Chest:
//
case THUAI6::PlaceType::Door6:
case THUAI6::PlaceType::Door3:
case THUAI6::PlaceType::Door5:
case THUAI6::PlaceType::HiddenGate:
// for (int k=)
for (int ii = max((i - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); ii < max((i + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++ii)
for (int jj = max((j - 1) * numSquarePerCell + numSquarePerCell / 2 + 1, 0); jj < max((j + 1) * numSquarePerCell + numSquarePerCell / 2 - 1, 0); ++jj)
untilTimeMap[ii][jj] = -1;
break;
default:
break;
}
}
}
auto t = api.GetTrickers();
if (t.size())
{
int tx = numGridToSquare(t[0]->x), ty = numGridToSquare(t[0]->y);
for (int i = max(tx - 20, 5); i < min(tx + 20, 496); ++i)
for (int j = max(ty - 20, 5); j < min(ty + 20, 496); ++j)
untilTimeMap[i][j] = -1;
}
auto tl = api.GetStudents();
for (int n = 0; n < 4; ++n)
if (tl[n]->playerID != selfInfo->playerID)
{
int tx = numGridToSquare(tl[n]->x), ty = numGridToSquare(tl[n]->y);
for (int i = max(tx - 10, 5); i < min(tx + 10, 496); ++i)
for (int j = max(ty - 10, 5); j < min(ty + 10, 496); ++j)
untilTimeMap[i][j] = -1;
}
}
int xq[myRow * myRow << 2], yq[myRow * myRow << 2];
int v[myRow][myRow];
inline void SPFAin(int x, int y, int xx, int yy, int vd, int l, int& r)
{
if (untilTimeMap[x][yy] > framet && untilTimeMap[xx][y] > framet)
{
// printf("%d %d %d %d SPFA\n", x, y, xx, yy);
if ((disMap[x][y] + vd) * 1000 < myVelocity * ((long long)untilTimeMap[xx][yy] - framet))
if (disMap[xx][yy] > disMap[x][y] + vd)
{
// if(xx==225) printf("%d %d\n",xx,yy);
disMap[xx][yy] = disMap[x][y] + vd;
fromMap[xx][yy] = XYSquare(x, y);
if (!v[xx][yy])
xq[++r] = xx, yq[r] = yy, v[xx][yy] = 1;
}
}
}
inline void SPFA()
{
memset(disMap, 0x3f, sizeof(disMap));
memset(v, 0, sizeof(v)); // 节点标记
int l = 0, r = 1;
disMap[selfSquare.x][selfSquare.y] = disMap[selfSquare.x][selfSquare.y] = 0;
v[selfSquare.x][selfSquare.y] = 1;
fromMap[selfSquare.x][selfSquare.y] = selfSquare;
xq[1] = selfSquare.x;
yq[1] = selfSquare.y;
while (l < r)
{
++l;
int x = xq[l], y = yq[l];
v[x][y] = 0;
int xx = x - 1, yy = y - 1;
int vd;
vd = int(round((1 + 1.4142 * myGridPerSquare) * (speedOriMap[x][y] + speedOriMap[xx][yy]) / (2 * myOriVelocity)));
SPFAin(x, y, xx, yy, vd, l, r);
xx += 2;
vd = int(round((1 + 1.4142 * myGridPerSquare) * (speedOriMap[x][y] + speedOriMap[xx][yy]) / (2 * myOriVelocity)));
SPFAin(x, y, xx, yy, vd, l, r);
yy += 2;
vd = int(round((1 + 1.4142 * myGridPerSquare) * (speedOriMap[x][y] + speedOriMap[xx][yy]) / (2 * myOriVelocity)));
SPFAin(x, y, xx, yy, vd, l, r);
xx -= 2;
vd = int(round((1 + 1.4142 * myGridPerSquare) * (speedOriMap[x][y] + speedOriMap[xx][yy]) / (2 * myOriVelocity)));
SPFAin(x, y, xx, yy, vd, l, r);
--yy;
vd = myGridPerSquare * (speedOriMap[x][y] + speedOriMap[xx][yy]) / (2 * myOriVelocity);
SPFAin(x, y, xx, yy, vd, l, r);
xx += 2;
vd = myGridPerSquare * (speedOriMap[x][y] + speedOriMap[xx][yy]) / (2 * myOriVelocity);
SPFAin(x, y, xx, yy, vd, l, r);
--xx;
--yy;
vd = myGridPerSquare * (speedOriMap[x][y] + speedOriMap[xx][yy]) / (2 * myOriVelocity);
SPFAin(x, y, xx, yy, vd, l, r);
yy += 2;
vd = myGridPerSquare * (speedOriMap[x][y] + speedOriMap[xx][yy]) / (2 * myOriVelocity);
SPFAin(x, y, xx, yy, vd, l, r);
}
}
void Move(IAPI& api, XYSquare toMove)
{
// 包括翻窗
api.EndAllAction();
XYCell cell = XYToCell(SquareToCell(selfSquare) + (toMove - selfSquare));
if (CellPlaceType(cell) == THUAI6::PlaceType::Window && ApproachToInteractInACross(cell))
{
api.SkipWindow();
return;
}
int x = SquareToGrid(toMove).x;
int y = SquareToGrid(toMove).y;
api.Print("AboutToMove\n");
api.Move(60, atan2(y - selfInfo->y, x - selfInfo->x));
api.Print("Moved\n");
}
XYSquare FindMoveNext(XYSquare toMove)
{
// printf("%d %d MoveNext\n", toMove.x, toMove.y);
int x = toMove.x, y = toMove.y, lx = toMove.x, ly = toMove.x;
if (x <= 0 || y <= 0)
{
printf("Erroneous pos at 714\n");
return selfSquare;
}
while (x != selfSquare.x || y != selfSquare.y)
{
lx = x;
ly = y;
x = fromMap[lx][ly].x;
y = fromMap[lx][ly].y;
printf("MoveNextFound\n");
if (x == lx && y == ly && (x != selfSquare.x || y != selfSquare.y))
{
printf("x= %d, y = %d, lx = %d, ly = %d\n", x, y, lx, ly);
break;
}
}
return XYSquare(lx, ly);
}
XYSquare FindNearInCell(XYCell cell)
{
int i = max((cell.x - 1) * numSquarePerCell, 10);
int j = max((cell.y - 1) * numSquarePerCell, 10);
int d = disMap[i][j];
XYSquare toFind = XYSquare(i, j);
for (; j < min(490, (cell.y + 2) * numSquarePerCell); ++j)
if (disMap[i][j] < d)
{
d = disMap[i][j];
toFind = XYSquare(i, j);
}
--j;
for (; i < min(490, (cell.x + 2) * numSquarePerCell); ++i)
if (disMap[i][j] < d)
{
d = disMap[i][j];
toFind = XYSquare(i, j);
}
--i;
for (; j >= max((cell.y - 1) * numSquarePerCell, 10); --j)
if (disMap[i][j] < d)
{
d = disMap[i][j];
toFind = XYSquare(i, j);
}
++j;
for (; i >= max((cell.x - 1) * numSquarePerCell, 10); --i)
if (disMap[i][j] < d)
{
d = disMap[i][j];
toFind = XYSquare(i, j);
}
return toFind;
}
XYCell FindActualClassroom(ITrickerAPI& api) // Instead of finding a cell near a classroom, we need actual coordinates of one
{
double min = 100000;
int i = 0, ind = -1;
for (i = 0; i < 10; ++i)
{
XYGrid vec = CellToGrid(ClassroomCell[i]);
vec.x -= selfInfo->x, vec.y -= selfInfo->y;
if (dist(vec) < min)
{
ind = i;
min = dist(vec);
}
}
if (ind == -1)
return XYCell(-1, -1);
else
return ClassroomCell[ind];
}
XYSquare FindClassroom()
{
XYSquare toFind = FindNearInCell(ClassroomCell[0]);
int d = disMap[toFind.x][toFind.y];
// printf("%d %d %d Class\n", toFind.x, toFind.y, disMap[toFind.x][toFind.y]);
for (int i = 1; i < Constants::numOfClassroom; ++i)
{
XYSquare t = FindNearInCell(ClassroomCell[i]);
if (disMap[t.x][t.y] < d)
{
toFind = t;
d = disMap[toFind.x][toFind.y];
}
// printf("%d %d %d %d Class\n", t.x, t.y, i, disMap[t.x][t.y]);
}
return toFind;
}
XYSquare FindGate()
{
// if (gameInfo->studentGraduated + gameInfo->studentQuited==3&& gameInfo->subjectFinished >= Constants::numOfRequiredClassroomForHiddenGate)
if (gameInfo->subjectFinished < Constants::numOfRequiredClassroomForGate)
return XYSquare(0, 0);
XYSquare toFind = FindNearInCell(GateCell[0]);
int d = disMap[toFind.x][toFind.y];
XYSquare t = FindNearInCell(GateCell[1]);
if (disMap[t.x][t.y] < d)
{
toFind = t;
d = disMap[toFind.x][toFind.y];
}
return toFind;
//隐藏校门或校门
// return (0,0)false
}
bool Commandable(const IAPI& api)
{
auto p = selfInfo->playerState;
// printf("ok\n");
// api.PrintSelfInfo();
return p != THUAI6::PlayerState::Addicted && p != THUAI6::PlayerState::Roused && p != THUAI6::PlayerState::Climbing && p != THUAI6::PlayerState::Attacking && p != THUAI6::PlayerState::Graduated && p != THUAI6::PlayerState::Quit && p != THUAI6::PlayerState::Stunned && p != THUAI6::PlayerState::Swinging;
}
void Update(const IStudentAPI& api)
{
gameInfo = api.GetGameInfo();
selfInfoStudent = api.GetSelfInfo();
selfInfo = selfInfoStudent;
selfSquare = numGridToXYSquare(selfInfoStudent->x, selfInfoStudent->y);
// printf("%d %d self\n", selfSquare.x, selfSquare.y);
for (int i = 0; i < Constants::numOfClassroom; ++i)
if (api.GetClassroomProgress(ClassroomCell[i].x, ClassroomCell[i].y) == 10000000)
ClassroomCell[i] = XYCell(0, 0);
myVelocity = selfInfo->speed;
// openedGateCell
for (int i = 0; i < 2; ++i)
if (api.GetGateProgress(ClassroomCell[i].x, ClassroomCell[i].y) == 18000)
openedGateCell[i] = GateCell[i];
}
inline long long getMaxBlood(int number)
{
switch (Trickers_Students[number].career)
{
case THUAI6::StudentType::Teacher:
return 30000000;
break;
case THUAI6::StudentType::Athlete:
return 3000000;
break;
case THUAI6::StudentType::StraightAStudent:
return 3300000;
break;
case THUAI6::StudentType::Sunshine:
return 3200000;
break;
case THUAI6::StudentType::Robot:
return 3000; // Needs replacing
break;
case THUAI6::StudentType::TechOtaku:
return 900000; // Needs replacing
break;
default:
return 30000000;
break;
}
}
inline long long getMaxAddiction(short fixation)
{
switch (Trickers_Students[fixation].career)
{
case THUAI6::StudentType::Teacher:
return 600000;
break;
case THUAI6::StudentType::Athlete:
return 54000;
break;
case THUAI6::StudentType::StraightAStudent:
return 78000;
break;
case THUAI6::StudentType::Sunshine:
return 66000;
break;
case THUAI6::StudentType::Robot:
return 3000; // Needs replacing
break;
case THUAI6::StudentType::TechOtaku:
return 90000; // Needs replacing
break;
default:
return 600000;
break;
}
}
void Update(const ITrickerAPI& api)
{
gameInfo = api.GetGameInfo();
selfInfoTricker = api.GetSelfInfo();
selfInfo = selfInfoTricker;
selfSquare = numGridToXYSquare(selfInfoTricker->x, selfInfoTricker->y);
for (int i = 0; i < Constants::numOfClassroom; ++i)
{
if (api.GetClassroomProgress(ClassroomCell[i].x, ClassroomCell[i].y) == 10000000)
ClassroomCell[i] = XYCell(0, 0);
}
myVelocity = selfInfo->speed;
auto stu = api.GetStudents();
for (int i = 0; i < 4; ++i)
Trickers_Students[i].blacklisted = false;
if (stu.size() > 0)
{
for (int i = 0; i < stu.size(); ++i)
{
students[stu[i]->playerID] = stu[i], studentsFrame[stu[i]->playerID] = api.GetFrameCount();
if (Trickers_Students[stu[i]->playerID].career == THUAI6::StudentType::NullStudentType)
{
Trickers_Students[stu[i]->playerID].career = stu[i]->studentType;
Trickers_Students[stu[i]->playerID].StudentNumber = short(stu[i]->playerID);
Trickers_Students[stu[i]->playerID].radius = stu[i]->radius;
Trickers_Students[stu[i]->playerID].speed = stu[i]->speed;
}
if (Trickers_Students[stu[i]->playerID].addiction > getMaxAddiction((short)(stu[i]->playerID)) * 0.12)
Trickers_Students[stu[i]->playerID].blacklisted = true;
Trickers_Students[stu[i]->playerID].UpdateMovement(XYGrid(stu[i]->x, stu[i]->y));
Trickers_Students[stu[i]->playerID].addiction = stu[i]->addiction;
Trickers_Students[stu[i]->playerID].playerstate = stu[i]->playerState;
Trickers_Students[stu[i]->playerID].UpdateBlood(stu[i]->determination);
Trickers_Students[stu[i]->playerID].lastframe = api.GetFrameCount();
}
}