-
Notifications
You must be signed in to change notification settings - Fork 16
/
fantastic-bits.cpp
2142 lines (1677 loc) · 50.1 KB
/
fantastic-bits.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
#pragma GCC optimize("-O3")
#pragma GCC optimize("inline")
#pragma GCC optimize("omit-frame-pointer")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <chrono>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
using namespace std::chrono;
// #define PROFILE
// #define PROD
// #define DEBUG
#ifdef PROFILE
const int DURATIONS_COUNT = 1;
double durations[DURATIONS_COUNT];
high_resolution_clock::time_point starts[DURATIONS_COUNT];
#define PS(i) starts[i] = NOW;
#define PE(i) durations[i] = durations[i] + duration_cast<duration<double>>(NOW - starts[i]).count();
#else
#define PS(i)
#define PE(i)
#endif
high_resolution_clock::time_point start;
#define NOW high_resolution_clock::now()
#define TIME duration_cast<duration<double>>(NOW - start).count()
// ***********************************************************
constexpr double WIDTH = 16000.0;
constexpr double HEIGHT = 7500.0;
constexpr int OBLIVIATE = 0;
constexpr int PETRIFICUS = 1;
constexpr int ACCIO = 2;
constexpr int FLIPENDO = 3;
constexpr int SPELL_DURATIONS[] = {3, 1, 6, 3};
constexpr int SPELL_COSTS[] = {5, 10, 20, 20};
constexpr double E = 0.00001;
constexpr int VERTICAL = 1;
constexpr int HORIZONTAL = 2;
constexpr double INF = 16000*16000 + 7500*7500;
constexpr int WIZARD = 1;
constexpr int SNAFFLE = 2;
constexpr int BLUDGER = 3;
constexpr int POLE = 4;
constexpr double TO_RAD = M_PI / 180.0;
constexpr double ANGLES[] = {0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 110.0, 120.0, 130.0, 140.0, 150.0, 160.0, 170.0, 180.0, 190.0, 200.0, 210.0, 220.0, 230.0, 240.0, 250.0, 260.0, 270.0, 280.0, 290.0, 300.0, 310.0, 320.0, 330.0, 340.0, 350.0};
constexpr int ANGLES_LENGTH = 36;
constexpr int DEPTH = 4;
constexpr int SPELL_DEPTH = 8;
constexpr int POOL = 50;
constexpr double MUTATION = 2;
// ***********************************************************
double cosAngles[ANGLES_LENGTH];
double sinAngles[ANGLES_LENGTH];
int myTeam;
int mana = 0;
int turn = 0;
int myScore = 0;
int hisScore = 0;
double energy = 0;
int depth = 0;
int smana;
int smyScore;
int shisScore;
class Point;
class Unit;
class Wizard;
class Snaffle;
class Bludger;
class Spell;
class Pole;
Wizard* myWizard1;
Wizard* myWizard2;
Wizard* hisWizard1;
Wizard* hisWizard2;
Point* myGoal;
Point* hisGoal;
Point* mid;
Unit* units[20];
int unitsFE = 0;
Unit* unitsById[24];
Snaffle* snaffles[20];
int snafflesFE = 0;
Wizard* wizards[4];
Bludger* bludgers[2];
Pole* poles[4];
Unit* spellTargets[4][20];
int spellTargetsFE[4];
bool doLog = false;
Spell* spells[16];
int victory;
// ***********************************************************
static unsigned int g_seed;
inline void fast_srand(int seed) {
//Seed the generator
g_seed = seed;
}
inline int fastrand() {
//fastrand routine returns one integer, similar output value range as C lib.
g_seed = (214013*g_seed+2531011);
return (g_seed>>16)&0x7FFF;
}
inline int fastRandInt(int maxSize) {
return fastrand() % maxSize;
}
inline int fastRandInt(int a, int b) {
return(a + fastRandInt(b - a));
}
inline double fastRandDouble() {
return static_cast<double>(fastrand()) / 0x7FFF;
}
inline double fastRandDouble(double a, double b) {
return a + (static_cast<double>(fastrand()) / 0x7FFF)*(b-a);
}
// ****************************************************************************************
class Solution {
public:
double energy;
int moves1[DEPTH];
int moves2[DEPTH];
int spellTurn1;
Unit* spellTarget1;
int spell1;
int spellTurn2;
Unit* spellTarget2;
int spell2;
Solution* merge(Solution* solution) {
Solution* child = new Solution();
for (int i = 0; i < DEPTH; ++i) {
if (fastRandInt(2)) {
child->moves1[i] = solution->moves1[i];
child->moves2[i] = solution->moves2[i];
} else {
child->moves1[i] = moves1[i];
child->moves2[i] = moves2[i];
}
}
if (fastRandInt(2)) {
child->spellTurn1 = solution->spellTurn1;
child->spellTarget1 = solution->spellTarget1;
child->spell1 = solution->spell1;
} else {
child->spellTurn1 = spellTurn1;
child->spellTarget1 = spellTarget1;
child->spell1 = spell1;
}
if (fastRandInt(2)) {
child->spellTurn2 = solution->spellTurn2;
child->spellTarget2 = solution->spellTarget2;
child->spell2 = solution->spell2;
} else {
child->spellTurn2 = spellTurn2;
child->spellTarget2 = spellTarget2;
child->spell2 = spell2;
}
return child;
}
void copy(Solution* solution) {
for (int i = 0; i < DEPTH; ++i) {
moves1[i] = solution->moves1[i];
moves2[i] = solution->moves2[i];
}
spellTurn1 = solution->spellTurn1;
spell1 = solution->spell1;
spellTarget1 = solution->spellTarget1;
spellTurn2 = solution->spellTurn2;
spell2 = solution->spell2;
spellTarget2 = solution->spellTarget2;
this->energy = solution->energy;
}
void mutate();
void randomize();
};
// ****************************************************************************************
class Point {
public:
double x;
double y;
Point() {};
Point(double x, double y) {
this->x = x;
this->y = y;
}
};
inline double dist(double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
inline double dist2(double x1, double y1, double x2, double y2) {
return (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
}
inline double dist(Point* p, double x2, double y2) {
return dist(p->x, p->y, x2, y2);
}
inline double dist2(Point* p, double x2, double y2) {
return dist2(p->x, p->y, x2, y2);
}
inline double dist(Point* u1, Point* u2) {
return dist(u1->x, u1->y, u2->x, u2->y);
}
inline double dist2(Point* u1, Point* u2) {
return dist2(u1->x, u1->y, u2->x, u2->y);
}
// ****************************************************************************************
class Collision {
public:
double t;
int dir;
Unit* a;
Unit* b;
Collision() {}
Collision* update(double t, Unit* a, int dir) {
b = NULL;
this->t = t;
this->a = a;
this->dir = dir;
return this;
}
Collision* update(double t, Unit* a, Unit* b) {
dir = 0;
this->t = t;
this->a = a;
this->b = b;
return this;
}
};
Collision** collisionsCache;
int collisionsCacheFE = 0;
// ****************************************************************************************
class Spell {
public:
Wizard* caster;
int duration;
Unit* target;
int type;
int sduration;
Unit* starget;
void cast(Unit* target);
void apply();
void save();
void reset() {
duration = sduration;
target = starget;
}
void reloadTarget();
virtual void effect() {}
virtual void print() {}
};
// ****************************************************************************************
class Obliviate : public Spell {
public:
Obliviate(Wizard* caster, int type) {
duration = 0;
this->type = type;
this->caster = caster;
}
virtual void print();
virtual void effect();
};
// ****************************************************************************************
class Petrificus : public Spell {
public:
Petrificus(Wizard* caster, int type) {
duration = 0;
this->type = type;
this->caster = caster;
}
virtual void print();
virtual void effect();
};
// ****************************************************************************************
class Accio : public Spell {
public:
Accio(Wizard* caster, int type) {
duration = 0;
this->type = type;
this->caster = caster;
}
virtual void print();
virtual void effect();
};
// ****************************************************************************************
class Flipendo : public Spell {
public:
Flipendo(Wizard* caster, int type) {
duration = 0;
this->type = type;
this->caster = caster;
}
virtual void print();
virtual void effect();
};
// ****************************************************************************************
class Unit : public Point {
public:
int id;
int type;
int state;
bool dead = false;
double r;
double m;
double f;
double vx;
double vy;
double sx;
double sy;
double svx;
double svy;
Wizard* carrier = NULL;
Snaffle* snaffle = NULL;
int grab = 0;
#ifndef PROD
double lx;
double ly;
double lvx;
double lvy;
Wizard* lcarrier;
Snaffle* lsnaffle;
bool ldead;
void store() {
lx = x;
ly = y;
lvx = vx;
lvy = vy;
lcarrier = carrier;
lsnaffle = snaffle;
ldead = dead;
}
void compare();
#endif
void update(int id, int x, int y, int vx, int vy, int state) {
this->id = id;
this->x = x;
this->y = y;
this->vx = vx;
this->vy = vy;
this->state = state;
}
double speedTo(Point* p) {
double d = 1.0 / dist(this, x, y);
// vitesse dans la direction du checkpoint - (vitesse orthogonale)^2/dist au cheeckpoint
double dx = (p->x - this->x) * d;
double dy = (p->y - this->y) * d;
double nspeed = vx*dx + vy*dy;
double ospeed = dy*vx - dx*vy;
return nspeed - (5 * ospeed * ospeed * d);
}
double speed() {
return sqrt(vx*vx + vy*vy);
}
inline void thrust(double thrust, Point* p, double distance) {
double coef = (thrust/m) / distance;
vx += (p->x - x) * coef;
vy += (p->y - y) * coef;
}
inline void thrust(double thrust, double x, double y, double distance) {
double coef = (thrust/m) / distance;
vx += (x - this->x) * coef;
vy += (y - this->y) * coef;
}
virtual void move(double t) {
x += vx * t;
y += vy * t;
}
virtual Collision* collision(double from) {
double tx = 2.0;
double ty = tx;
if (x + vx < r) {
tx = (r - x)/vx;
} else if (x + vx > WIDTH - r) {
tx = (WIDTH - r - x)/vx;
}
if (y + vy < r) {
ty = (r - y)/vy;
} else if (y + vy > HEIGHT - r) {
ty = (HEIGHT - r - y)/vy;
}
int dir;
double t;
if (tx < ty) {
dir = HORIZONTAL;
t = tx + from;
} else {
dir = VERTICAL;
t = ty + from;
}
if (t <= 0.0 || t > 1.0) {
return NULL;
}
return collisionsCache[collisionsCacheFE++]->update(t, this, dir);
}
virtual Collision* collision(Unit* u, double from) {
double x2 = x - u->x;
double y2 = y - u->y;
double r2 = r + u->r;
double vx2 = vx - u->vx;
double vy2 = vy - u->vy;
double a = vx2*vx2 + vy2*vy2;
if (a < E) {
return NULL;
}
double b = -2.0*(x2*vx2 + y2*vy2);
double delta = b*b - 4.0*a*(x2*x2 + y2*y2 - r2*r2);
if (delta < 0.0) {
return NULL;
}
// double sqrtDelta = sqrt(delta);
// double d = 1.0/(2.0*a);
// double t1 = (b + sqrtDelta)*d;
// double t2 = (b - sqrtDelta)*d;
// double t = t1 < t2 ? t1 : t2;
double t = (b - sqrt(delta))*(1.0/(2.0*a));
if (t <= 0.0) {
return NULL;
}
t += from;
if (t > 1.0) {
return NULL;
}
return collisionsCache[collisionsCacheFE++]->update(t, this, u);
}
virtual void bounce(Unit* u) {
double mcoeff = (m + u->m) / (m * u->m);
double nx = x - u->x;
double ny = y - u->y;
double nxnydeux = nx*nx + ny*ny;
double dvx = vx - u->vx;
double dvy = vy - u->vy;
double product = (nx*dvx + ny*dvy) / (nxnydeux * mcoeff);
double fx = nx * product;
double fy = ny * product;
double m1c = 1.0 / m;
double m2c = 1.0 / u->m;
vx -= fx * m1c;
vy -= fy * m1c;
u->vx += fx * m2c;
u->vy += fy * m2c;
// Normalize vector at 100
double impulse = sqrt(fx*fx + fy*fy);
if (impulse < 100.0) {
double min = 100.0 / impulse;
fx = fx * min;
fy = fy * min;
}
vx -= fx * m1c;
vy -= fy * m1c;
u->vx += fx * m2c;
u->vy += fy * m2c;
}
virtual void bounce(int dir) {
if (dir == HORIZONTAL) {
vx = -vx;
} else {
vy = -vy;
}
}
virtual void end() {
x = round(x);
y = round(y);
vx = round(vx*f);
vy = round(vy*f);
}
bool can(Unit* u) {
if (type == SNAFFLE) {
return !carrier && !dead && !u->snaffle && !u->grab;
} else if (u->type == SNAFFLE) {
return !u->carrier && !u->dead && !snaffle && !grab;
}
return true;
}
virtual void print() {}
virtual void save() {
sx = x;
sy = y;
svx = vx;
svy = vy;
}
virtual void reset() {
x = sx;
y = sy;
vx = svx;
vy = svy;
}
};
// ****************************************************************************************
class Pole : public Unit {
public:
Pole(int id, double x, double y) {
this->id = id;
r = 300;
m = INF;
type = POLE;
this->x = x;
this->y = y;
vx = 0;
vy = 0;
dead = false;
f = 0.0;
}
virtual void move(double t) {}
virtual void save() {}
virtual void reset() {}
virtual Collision* collision(double from) {
return NULL;
}
};
// ****************************************************************************************
class Wizard : public Unit {
public:
int team;
Spell* spells[4];
int sgrab;
Snaffle* ssnaffle;
int spell;
Unit* spellTarget;
Wizard(int team) {
this->team = team;
this->r = 400.0;
this->m = 1;
this->f = 0.75;
snaffle = NULL;
grab = 0;
type = WIZARD;
spells[OBLIVIATE] = new Obliviate(this, OBLIVIATE);
spells[PETRIFICUS] = new Petrificus(this, PETRIFICUS);
spells[ACCIO] = new Accio(this, ACCIO);
spells[FLIPENDO] = new Flipendo(this, FLIPENDO);
spellTarget = NULL;
}
inline void grabSnaffle(Snaffle* snaffle);
void apply(int move);
void output(int move, int spellTurn, int spell, Unit* target) {
if (!spellTurn && spells[spell]->duration == SPELL_DURATIONS[spell]) {
if (spell == OBLIVIATE) {
cout << "OBLIVIATE ";
} else if (spell == PETRIFICUS) {
cout << "PETRIFICUS ";
} else if (spell == ACCIO) {
cout << "ACCIO ";
} else if (spell == FLIPENDO) {
cout << "FLIPENDO ";
}
cout << target->id << endl;
return;
}
// Adjust the targeted point for this angle
// Find a point with the good angle
double px = x + cosAngles[move] * 10000.0;
double py = y + sinAngles[move] * 10000.0;
if (snaffle) {
cout << "THROW " << round(px) << " " << round(py) << " 500";
} else {
cout << "MOVE " << round(px) << " " << round(py) << " 150";
}
cout << endl;
}
bool cast(int spell, Unit* target) {
int cost = SPELL_COSTS[spell];
if (mana < cost || target->dead) {
return false;
}
mana -= cost;
this->spell = spell;
spellTarget = target;
return true;
}
virtual Collision* collision(Unit* u, double from) {
if (u->type == SNAFFLE) {
u->r = -1.0;
Collision* result = Unit::collision(u, from);
u->r = 150.0;
return result;
} else {
return Unit::collision(u, from);
}
}
virtual void bounce(Unit* u);
void play();
virtual void end();
virtual void save() {
Unit::save();
sgrab = grab;
ssnaffle = snaffle;
}
virtual void reset() {
Unit::reset();
grab = sgrab;
snaffle = ssnaffle;
}
virtual void print();
void updateSnaffle();
void apply(Solution* solution, int turn, int index) {
if (index == 1) {
if (solution->spellTurn1 == turn) {
if (!myWizard1->cast(solution->spell1, solution->spellTarget1)) {
myWizard1->apply(solution->moves1[turn]);
}
} else {
myWizard1->apply(solution->moves1[turn]);
}
} else {
if (solution->spellTurn2 == turn) {
if (!myWizard2->cast(solution->spell2, solution->spellTarget2)) {
myWizard2->apply(solution->moves2[turn]);
}
} else {
myWizard2->apply(solution->moves2[turn]);
}
}
}
};
// ****************************************************************************************
class Snaffle : public Unit {
public:
Wizard* scarrier;
Snaffle() {
this->r = 150.0;
this->m = 0.5;
this->f = 0.75;
carrier = NULL;
type = SNAFFLE;
}
virtual Collision* collision(double from) {
if (carrier || dead) {
return NULL;
}
double tx = 2.0;
double ty = tx;
if (x + vx < 0.0) {
tx = -x/vx;
} else if (x + vx > WIDTH) {
tx = (WIDTH - x)/vx;
}
if (y + vy < r) {
ty = (r - y)/vy;
} else if (y + vy > HEIGHT - r) {
ty = (HEIGHT - r - y)/vy;
}
int dir;
double t;
if (tx < ty) {
dir = HORIZONTAL;
t = tx + from;
} else {
dir = VERTICAL;
t = ty + from;
}
if (t <= 0.0 || t > 1.0) {
return NULL;
}
return collisionsCache[collisionsCacheFE++]->update(t, this, dir);
}
virtual Collision* collision(Unit* u, double from) {
if (u->type == WIZARD) {
r = -1.0;
Collision* result = Unit::collision(u, from);
r = 150.0;
return result;
} else {
return Unit::collision(u, from);
}
}
virtual void bounce(Unit* u) {
if (u->type == WIZARD) {
Wizard* target = (Wizard*) u;
if (!target->snaffle && !target->grab && !dead && !carrier) {
target->grabSnaffle(this);
}
} else {
Unit::bounce(u);
}
}
virtual void bounce(int dir) {
if (dir == HORIZONTAL && y >= 1899.0 && y <= 5599.0) {
dead = true;
if (!myTeam) {
if (x > 8000) {
myScore += 1;
} else {
hisScore += 1;
}
} else {
if (x > 8000) {
hisScore += 1;
} else {
myScore += 1;
}
}
} else {
Unit::bounce(dir);
}
}
virtual void move(double t) {
if (!dead && !carrier) {
Unit::move(t);
}
}
virtual void end() {
if (!dead && !carrier) {
Unit::end();
}
}
virtual void save() {
Unit::save();
scarrier = carrier;
}
virtual void reset() {
Unit::reset();
carrier = scarrier;
dead = false;
}
virtual void print() {
if (dead) {
cerr << "Snaffle " << id << " dead";
} else {
cerr << "Snaffle " << id << " " << x << " " << y << " " << vx << " " << vy << " " << speed() << " " << " | ";
if (carrier) {
cerr << "Carrier " << carrier->id << " | ";
}
}
cerr << endl;
}
};
// ****************************************************************************************
class Bludger : public Unit {
public:
Wizard* last;
int ignore[2];
Wizard* slast;
Bludger() {
this->r = 200.0;
this->m = 8;
this->f = 0.9;
last = NULL;
ignore[0] = -1;
ignore[1] = -1;
type = BLUDGER;
}
virtual void print() {
cerr << "Bludger " << id << " " << x << " " << y << " " << vx << " " << vy << " " << speed() << " " << ignore[0] << " " << ignore[1] << " | ";
if (last) {
cerr << "Last " << last->id << " | ";
}
cerr << endl;
}
virtual void save() {
Unit::save();
slast = last;
}
virtual void reset() {
Unit::reset();
last = slast;
ignore[0] = -1;
ignore[1] = -1;
}
virtual void bounce(Unit* u) {
if (u->type == WIZARD) {
last = (Wizard*) u;
}
Unit::bounce(u);
}
void play() {
// Find our target
Wizard* target = NULL;
double d;
for (int i = 0; i < 4; ++i) {
Wizard* wizard = wizards[i];
if ((last && last->id == wizard->id) || wizard->team == ignore[0] || wizard->team == ignore[1]) {
continue;
}
double d2 = dist2(this, wizard);
if (!target || d2 < d) {
d = d2;
target = wizard;
}
}
if (target) {
thrust(1000.0, target, sqrt(d));
}
ignore[0] = -1;
ignore[1] = -1;