-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPowderPuff.java
912 lines (831 loc) · 27.4 KB
/
PowderPuff.java
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
/*
- Check to make sure move around ball works correctly : CLAIRE
- Break Away Function??? : CLAIRE
- try to kick away from defenders and toward teammates? : MICHELLE
*/
import java.awt.*;
public class PowderPuff extends Player {
static int playersX[];
static int playersY[];
static int distancesToBall[];
static boolean someoneOnBall;
static int playersOnBall[];
static final int ATTACK = 1;
static int attacker = 0;
static final int LEFTFORWARD = 2;
static int leftForward = 1;
static final int RIGHTFORWARD = 3;
static int rightForward = 2;
static final int DEFENDER = 4;
static int defender = 3;
static final int playerDistance = 8;
static int positions[];
static int angles[];
private int getBallX(int x, int distance, int angle) {
return (int)Math.round((x + (distance * Math.cos(angle))));
}
private int getBallY(int y, int distance, int angle) {
return (int)Math.round((y + (distance * Math.sin(angle))));
}
private int DefendRow(int x, int y) {
for (int i = 4; i > 0; i--)
if ((GetOpponentDirection(i) == NORTH) ||
(GetOpponentDirection(i) == NORTHEAST) ||
(GetOpponentDirection(i) == SOUTHEAST) ||
(GetOpponentDirection(i) == EAST) ||
(GetOpponentDirection(i) == SOUTH)) {
return MoveToPos(GetLocation().x + 1, y);
}
return MoveToPos(x, y);
}
private int MoveToPos(int gx, int gy) {
int x = GetLocation().x;
int y = GetLocation().y;
int ew = 0;
int ns = 0;
if (y > gy) {
ns = NORTH;
} else if (y < gy) {
ns = SOUTH;
}
if (x > gx) {
ew = WEST;
} else if (x < gx) {
ew = EAST;
}
int move = NORTH;
if (ew == EAST) {
if (ns == NORTH) {
move = NORTHEAST;
} else if (ns == SOUTH) {
move = SOUTHEAST;
} else {
move = EAST;
}
} else if (ew == WEST) {
if (ns == NORTH) {
move = NORTHWEST;
} else if (ns == SOUTH) {
move = SOUTHWEST;
} else {
move = WEST;
}
} else if (ns == NORTH) {
move = NORTH;
} else if (ns == SOUTH) {
move = SOUTH;
} else {
return PLAYER;
}
return PickMove(move);
}
private int PickMove(int dir) {
if (Look(dir) == EMPTY)
return dir;
return MakeAlternateMove(dir);
}
private int MakeAlternateMove(int dir) {
switch (dir) {
case 0:
if (Look(NORTHWEST) == EMPTY) return NORTHWEST;
if (Look(NORTHEAST) == EMPTY) return NORTHEAST;
return PLAYER;
case 1:
if (Look(EAST) == EMPTY) return EAST;
if (Look(NORTH) == EMPTY) return NORTH;
return PLAYER;
case 7:
if (Look(NORTH) == EMPTY) return NORTH;
if (Look(WEST) == EMPTY) return WEST;
return PLAYER;
case 6:
if (Look(NORTHWEST) == EMPTY) return NORTHWEST;
if (Look(SOUTHWEST) == EMPTY) return SOUTHWEST;
return PLAYER;
case 2:
if (Look(NORTHEAST) == EMPTY) return NORTHEAST;
if (Look(SOUTHEAST) == EMPTY) return SOUTHEAST;
return PLAYER;
case 5:
if (Look(SOUTH) == EMPTY) return SOUTH;
if (Look(WEST) == EMPTY) return WEST;
return PLAYER;
case 4:
if (Look(SOUTHEAST) == EMPTY) return SOUTHEAST;
if (Look(SOUTHWEST) == EMPTY) return SOUTHWEST;
return PLAYER;
case 3:
if (Look(EAST) == EMPTY) return EAST;
if (Look(SOUTH) == EMPTY) return SOUTH;
return PLAYER;
}
return PLAYER;
}
/*private final int GetOpponentDistance(Player Client, int nth) {
if(nth>0 && nth<5)
{
Team ClientTeam = Parent.GetTeam(Client);
Point PlayerLocation = Parent.ClientTeam.GetPlayerLocation(Client);
Player other = ClientTeam.GetPlayer(nth);
Point OtherPlayerLocation = Parent.ClientTeam.GetPlayerLocation(other);
return (int)Math.round(GetDistance(PlayerLocation, OtherPlayerLocation));
}
return -1;
}
private final int GetOpponentDirection(Player Client, int nth) {
if(nth>0 && nth<5)
{
Team ClientTeam = GetTeam(Client);
Point PlayerLocation = ClientTeam.GetPlayerLocation(Client);
Player other = ClientTeam.GetPlayer(nth);
Point OtherPlayerLocation = Parent.ClientTeam.GetPlayerLocation(other);
return GetDirection(PlayerLocation, OtherPlayerLocation, ClientTeam.GetSide());
}
return -1;
}*/
/* Check to see if there is a "clear" path by checking the direction around
each player */
public boolean isClearPath(int x1, int y1, int x2, int y2) {
int xDifference = Math.abs(x1 - x2);
int yDifference = Math.abs(y1 - y2);
int startX, endX;
int startY, endY;
boolean isClear = false;
if (y1 < y2) {
if (Look(EAST) == EMPTY) {
isClear = true;
}
} else {
if (Look(WEST) == EMPTY) {
isClear = true;
}
}
if (x1 < x2) {
startX = x1;
endX = x2;
if (Look(EAST) == EMPTY) {
isClear = true;
}
} else {
startX = x2;
endX = x1;
if (Look(WEST) == EMPTY) {
isClear = true;
}
}
return isClear;
}
public int MoveToClearPath(int position) {
int attackX = 0;
int attackY = 0;
int secondX = 0;
int secondY = 0;
for (int i = 0; i <= 3; i++) {
if (positions[i] == ATTACK) {
attackX = playersX[i];
attackY = playersY[i];
} else if (positions[i] == LEFTFORWARD && positions[i] == position) {
secondX = playersX[i];
secondY = playersY[i];
} else if (positions[i] == RIGHTFORWARD && positions[i] == position) {
secondX = playersX[i];
secondY = playersY[i];
} else if (positions[i] == DEFENDER && positions[i] == position) {
secondX = playersX[i];
secondY = playersY[i];
}
}
if (isClearPath(attackX, attackY, secondX, secondY)) {
return KICK;
} else if (isClearPath(attackX, attackY, secondX + 1, secondY)) {
return EAST;
} else if (isClearPath(attackX, attackY, secondX - 1, secondY)) {
return WEST;
} else if (isClearPath(attackX, attackY, secondX, secondY - 1)) {
return NORTH;
} else if (isClearPath(attackX, attackY, secondX, secondY + 1)) {
return SOUTH;
} else if (isClearPath(attackX, attackY, secondX + 1, secondY + 1)) {
return SOUTHEAST;
} else if (isClearPath(attackX, attackY, secondX - 1, secondY + 1)) {
return SOUTHWEST;
} else if (isClearPath(attackX, attackY, secondX + 1, secondY - 1)) {
return NORTHEAST;
} else if (isClearPath(attackX, attackY, secondX - 1, secondY - 1)) {
return NORTHWEST;
} else {
return WEST;
}
}
public int KickToClearPath() {
int move = PLAYER;
int attackX = 0;
int attackY = 0;
int forwardX = 0;
int forwardY = 0;
for (int i = 0; i <= 3; i++) {
if (positions[i] == ATTACK) {
attackX = playersX[i];
attackY = playersY[i];
}
if (positions[i] == LEFTFORWARD || positions[i] == RIGHTFORWARD) {
forwardX = playersX[i];
forwardY = playersY[i];
}
}
if (isClearPath(attackX, attackY, forwardX, forwardY)) {
//move around ball to kick in the correct direction
move = MoveAroundBall();
}
return move;
}
//attack function
//Goals: move the ball west
// defend if necessary
// kick away from majority of players
public int Attack() {
int move = WEST;
int x = GetLocation().x;
int index = 0;
for (int i = 0; i <= 3; i++) {
if (positions[i] == ATTACK) {
index = i;
}
}
if (GetBallDistance() <= 1) {
playersOnBall[index] = 1;
}
if (playersOnBall[index] == 1) {
if (Look(NORTH) == BALL) {
//check for opponents
if (Look(WEST) == OPPONENT || Look(NORTHWEST) == OPPONENT) {
return KICK;
}
//get ball away from goal if there are also opponents
else if ((x > 3 * FieldX() / 4) && Look(WEST) == OPPONENT || Look(NORTHWEST) == OPPONENT) {
return KICK;
}
//if no opponents and not near goal move northeast so can kick west
else {
return NORTHEAST;
}
}
if (Look(NORTHWEST) == BALL) {
//if close to goal, kick ic
if ((x > 3 * FieldX() / 4)) {
return KICK;
}
//if not near goal move north so can kick west
else {
return NORTH;
}
}
if (Look(WEST) == BALL) {
return KICK;
}
if (Look(SOUTHWEST) == BALL) {
if ((x > 3 * FieldX() / 4)) {
return KICK;
}
//if not near goal move nouth so can kick west
else {
return SOUTH;
}
}
if (Look(SOUTH) == BALL) {
//check for opponents
if (Look(WEST) == OPPONENT || Look(SOUTHWEST) == OPPONENT) {
return KICK;
}
//get ball away from goal if there are also opponents
else if ((x > 3 * FieldX() / 4) && (Look(WEST) == OPPONENT || Look(NORTHWEST) == OPPONENT)) {
return KICK;
}
//if no opponents and not near goal move northeast so can kick west
else {
return SOUTHEAST;
}
}
if (Look(SOUTHEAST) == BALL) {
//try to get into position to kick ball
return EAST;
}
if (Look(EAST) == BALL) {
if (Look(NORTHEAST) == EMPTY) {
return NORTH;
}
if (Look(SOUTHEAST) == EMPTY) {
return SOUTH;
}
if (Look(WEST) == OPPONENT) {
return WEST;
}
if (Look(SOUTH) == EMPTY) {
return SOUTH;
}
return NORTH;
}
if (Look(NORTHEAST) == BALL) {
return EAST;
}
}
return MakeAlternateMove(GetBallDirection());
}
//leftForward function
public int LeftForward() {
int horizontal = -1;
int vertical = -1;
int x = GetLocation().x;
int y = GetLocation().y;
for (int i = 0; i <= 3; i++) {
if (positions[i] == ATTACK) {
attacker = i;
}
if (positions[i] == LEFTFORWARD) {
leftForward = i;
}
}
/* If near the ball, act like a leader */
if (GetBallDistance() < 5) {
assignAttacker();
return(Attack());
}
//get out of way of attacker
/* if (isClearPath(playersX[attacker], playersY[attacker],
playersX[leftForward], playersY[leftForward])) {
return MoveToClearPath(LEFTFORWARD);
}*/
//if in back part of field act like a defender
if ((x > 3 * FieldX() / 4)) {
return (defender());
}
/* Try to get into position */
//no on is north and attacker isn't in your way
if (Look(NORTH) == EMPTY && (y > playersY[attacker] - playerDistance)) {
vertical = NORTH;
}
if (Look(SOUTH) == EMPTY && (y < playersY[attacker] - playerDistance)) {
vertical = SOUTH;
}
//if behind attacker but in same y line, move down
if ((x < playersX[attacker]) && (y == playersY[attacker])) {
vertical = SOUTH;
}
if (Look(WEST) == EMPTY && (x > playersX[attacker] + playerDistance)) {
horizontal = WEST;
}
if (Look(EAST) == EMPTY && (x < playersX[attacker] + playerDistance)) {
horizontal = EAST;
}
if ((horizontal == EAST) && (vertical == NORTH)) {
return(NORTHEAST);
}
if ((horizontal == EAST) && (vertical == SOUTH)) {
return(SOUTHEAST);
}
if ((horizontal == WEST) && (vertical == NORTH)) {
return(NORTHWEST);
}
if ((horizontal == WEST) && (vertical== SOUTH)) {
return(SOUTHWEST);
}
if (horizontal == EAST) {
return(EAST);
}
if (horizontal == WEST) {
return(WEST);
}
if (vertical == NORTH) {
return(NORTH);
}
if (vertical == SOUTH) {
return(SOUTH);
}
return MakeAlternateMove(GetBallDirection());
}
//rightForward function
public int RightForward() {
int move = WEST;
//find attack index
int attacker = 0;
//find rightForward index
int rightForward = 0;
//get into position
//if you have ball & defense in front of you, pass to right forward
//else keep moving toward ball down the field
int horizontal = -1;
int vertical = -1;
int x = GetLocation().x;
int y = GetLocation().y;
for (int i = 0; i <= 3; i++) {
if (positions[i] == ATTACK) {
attacker = i;
}
if (positions[i] == RIGHTFORWARD) {
rightForward = i;
}
}
/* If near the ball, act like a leader */
if (GetBallDistance() < 5) {
assignAttacker();
return(Attack());
}
//if in back half of field, act like on defense
if ((x > 3 * FieldX() / 4)) {
return (defender());
}
/* Try to get into position */
//no on is north and attacker insn't in your way
if (Look(NORTH) == EMPTY && (y > playersY[attacker] + playerDistance) ) {
vertical = NORTH;
}
if (Look(SOUTH) == EMPTY && (y < playersY[attacker] + playerDistance) ) {
vertical = SOUTH;
}
//if behind attacker but in same y line, move down
if ((x < playersX[attacker]) && (y == playersY[attacker])) {
vertical = NORTH;
}
if (Look(WEST) == EMPTY && (x > playersX[attacker] + playerDistance)) {
horizontal = WEST;
}
if (Look(EAST) == EMPTY && (x < playersX[attacker] + playerDistance)) {
horizontal = EAST;
}
if ((horizontal == EAST) && (vertical == NORTH)) {
return(NORTHEAST);
}
if ((horizontal == EAST) && (vertical == SOUTH)) {
return(SOUTHEAST);
}
if ((horizontal == WEST) && (vertical == NORTH)) {
return(NORTHWEST);
}
if ((horizontal == WEST) && (vertical== SOUTH)) {
return(SOUTHWEST);
}
if (horizontal == EAST) {
return(EAST);
}
if (horizontal == WEST) {
return(WEST);
}
if (vertical == NORTH) {
return(NORTH);
}
if (vertical == SOUTH) {
return(SOUTH);
}
return MakeAlternateMove(GetBallDirection());
}
//defender function
public int defender() {
int x = GetLocation().x;
int y = GetLocation().y;
if (GetBallDirection() == NORTHEAST || GetBallDirection() == EAST || GetBallDirection() == SOUTHEAST) {
int goToX = getBallX(x, GetBallDistance(), angles[GetBallDirection()]);
int goToY = getBallY(y, GetBallDistance(), angles[GetBallDirection()]);
return DefendRow(goToX, goToY);
}
//priority 1 = get ball out of the goal zone
//priority 2 = get between defender and goal
if (Look(SOUTHWEST) == BALL) {
if (Look(SOUTH) == EMPTY) {
return NORTH;
}
return KICK;
}
else if (Look(NORTHWEST) == BALL) {
if (Look(NORTH) == EMPTY) {
return NORTH;
}
return KICK;
}
else if (Look(WEST) == BALL) {
//kick ball away
return KICK;
}
//try to get between the ball and the endline
else if (Look(NORTH) == BALL) {
/* If an opponent can kick toward my goal, try to kick the ball
away */
if (Look(WEST) == OPPONENT && Look(NORTHWEST) == OPPONENT) {
return KICK;
}
if (Look(NORTHEAST) != EMPTY && Look(EAST) != EMPTY) {
return KICK;
}
if (Look(NORTHEAST) == EMPTY) {
return NORTHEAST;
}
return EAST;
}
else if (Look(EAST) == BALL) {
if (Look(NORTHEAST) == EMPTY && Look(WEST) != OPPONENT) {
return NORTHEAST;
}
if (Look(SOUTHEAST) == EMPTY && Look(WEST) != OPPONENT) {
return SOUTHEAST;
}
//can we do nothing?
return EAST;
}
else if (Look(SOUTH) == BALL) {
/* If an opponent can kick toward my goal, try to kick the ball
away */
if (Look(WEST) == OPPONENT && (Look(SOUTHWEST) == OPPONENT)) {
return(KICK);
}
return SOUTHEAST;
}
else if (Look(SOUTHEAST) == BALL || Look(SOUTHEAST) == OPPONENT) {
//get between ball and goal
/** east or west? **/
return(EAST);
}
else if (Look(NORTHEAST) == BALL || Look(NORTHEAST) == OPPONENT) {
return EAST;
}
else if (Look(NORTH) == OPPONENT) {
if (Look(NORTHEAST) == EMPTY) {
return NORTHEAST;
}
return EAST;
}
else if (Look(SOUTH) == OPPONENT) {
if (Look(SOUTHEAST) == EMPTY) {
return SOUTHEAST;
}
return EAST;
}
else if (Look(EAST) == OPPONENT) {
if (Look(NORTHEAST) == EMPTY) {
return NORTHEAST;
}
if (Look(SOUTHEAST) == EMPTY) {
return SOUTHEAST;
}
}
else if (Look(WEST) == OPPONENT) {
return WEST;
}
else if (Look(NORTHWEST) == OPPONENT) {
return NORTH;
}
else if (Look(SOUTHWEST) == OPPONENT) {
return SOUTH;
}
//if no ball or opponents around, act like attacker
return MakeAlternateMove(GetBallDirection());
}
public void assignAttacker() {
attacker = GetPlayerClosestToBall();
assignOthers(attacker);
}
//assignOthers function
public void assignOthers(int attacker) {
int lowX = Integer.MAX_VALUE;
int highX = Integer.MIN_VALUE;
int lowY = Integer.MAX_VALUE;
int highY = Integer.MIN_VALUE;
int newLeftForward = 0;
int newRightForward = 0;
int newDefender = 0;
for (int i = 0; i < 4; i++) {
positions[i] = 0;
}
positions[attacker] = ATTACK;
//assigning defender
for (int i = 0; i < 4; i++) {
if (positions[i] == 0) {
if (playersX[i] > highX) {
highX = playersX[i];
newDefender = i;
}
}
}
defender = newDefender;
positions[defender] = DEFENDER;
//assigning leftForward
for (int i = 0; i < 4; i++) {
if (positions[i] == 0) {
if (playersY[i] > highY) {
lowY = playersY[i];
newLeftForward = i;
}
}
}
leftForward = newLeftForward;
positions[leftForward] = LEFTFORWARD;
//assigning rightForward
for (int i = 0; i < 4; i++) {
if (positions[i] == 0) {
if (playersY[i] < lowY) {
highY = playersY[i];
newRightForward = i;
}
}
}
rightForward = newRightForward;
positions[rightForward] = RIGHTFORWARD;
}
public void InitializeGame () {
playersX = new int[4];
playersY = new int[4];
distancesToBall = new int[4];
someoneOnBall = false;
playersOnBall = new int[4];
positions = new int[4];
angles = new int[]{90,45,0,315,270,225,180,135};
}
public void InitializePoint() {
for (int i = 0; i <= 3; i++) {
playersX[i] = 0;
playersY[i] = 0;
playersOnBall[i] = 0;
}
positions[0] = ATTACK;
positions[1] = RIGHTFORWARD;
positions[2] = LEFTFORWARD;
positions[3] = DEFENDER;
}
public int AlternateMove(int move) {
int originalMove = move;
move = move + 1;
while (Look(move) != EMPTY || Look(move) == BOUNDARY) {
// try another move
if (move < NORTHWEST) {
move++;
} else {
move = 0;
}
if (move == originalMove) {
return PLAYER;
}
}
return move;
}
public int GetPlayerClosestToBall() {
int minDistance = distancesToBall[0];
int closestPlayer = 0;
for (int i = 1; i <= 3; i++) {
if (distancesToBall[i] < minDistance) {
minDistance = distancesToBall[i];
closestPlayer = i;
if (distancesToBall[i] <= 1) {
someoneOnBall = true;
playersOnBall[i] = 1;
}
}
}
return closestPlayer;
}
public int MoveAroundBall() {
int move = PLAYER;
int alternateMove = PLAYER;
int direction = PLAYER;
for (int i = 0; i <= 7; i++) {
if (Look(i) == BALL) {
direction = i;
}
}
switch (direction) {
case NORTH:
//NORTHEAST
move = EAST;
alternateMove = EAST;
case NORTHEAST:
move = EAST;
alternateMove = NORTH;
case EAST:
//NORTHEAST
move = NORTH;
alternateMove = SOUTHEAST;
case SOUTHEAST:
move = EAST;
alternateMove = SOUTH;
case SOUTH:
//SOUTHEAST
move = EAST;
alternateMove = EAST;
case SOUTHWEST:
move = SOUTH;
alternateMove = WEST;
case WEST:
move = KICK;
alternateMove = PLAYER;
case NORTHWEST:
move = NORTH;
alternateMove = WEST;
}
/* If there is an opponent blocking the move you want to make */
if (Look(move) != EMPTY || Look(move) == BOUNDARY) {
move = MakeAlternateMove(move); //alternateMove;
}
return move;
}
public int Player1() {
int action = PLAYER;
playersX[0] = GetLocation().x;
playersY[0] = GetLocation().y;
distancesToBall[0] = GetBallDistance();
if (GetBallDistance() <= 1) {
playersOnBall[0] = 1;
}
int closestPlayer = GetPlayerClosestToBall();
assignAttacker();
switch (positions[0]) {
case ATTACK: action = Attack();
break;
case LEFTFORWARD: action = LeftForward();
break;
case RIGHTFORWARD: action = RightForward();
break;
case DEFENDER: action = defender();
break;
}
return action;
}
public int Player2() {
int action = PLAYER;
playersX[1] = GetLocation().x;
playersY[1] = GetLocation().y;
distancesToBall[1] = GetBallDistance();
if (GetBallDistance() <= 1) {
playersOnBall[1] = 1;
}
int closestPlayer = GetPlayerClosestToBall();
// assignAttacker();
switch (positions[1]) {
case ATTACK: action = Attack();
break;
case LEFTFORWARD: action = LeftForward();
break;
case RIGHTFORWARD: action = RightForward();
break;
case DEFENDER: action = defender();
break;
}
return action;
}
public int Player3() {
int action = PLAYER;
playersX[2] = GetLocation().x;
playersY[2] = GetLocation().y;
distancesToBall[2] = GetBallDistance();
if (GetBallDistance() <= 1) {
playersOnBall[2] = 1;
}
int closestPlayer = GetPlayerClosestToBall();
// assignAttacker();
switch (positions[2]) {
case ATTACK: action = Attack();
break;
case LEFTFORWARD: action = LeftForward();
break;
case RIGHTFORWARD: action = RightForward();
break;
case DEFENDER: action = defender();
break;
}
return action;
}
public int Player4() {
int action = PLAYER;
playersX[3] = GetLocation().x;
playersY[3] = GetLocation().y;
distancesToBall[3] = GetBallDistance();
if (GetBallDistance() <= 1) {
playersOnBall[3] = 1;
}
int closestPlayer = GetPlayerClosestToBall();
switch (positions[3]) {
case ATTACK: action = Attack();
break;
case LEFTFORWARD: action = LeftForward();
break;
case RIGHTFORWARD: action = RightForward();
break;
case DEFENDER: action = defender();
break;
}
return action;
}
public void WonPoint () {};
public void LostPoint () {};
public void GameOver () {};
public int getAction() {
switch(ID)
{
case 1:
return Player1();
case 2:
return Player2();
case 3:
return Player3();
case 4:
return Player4();
}
return BALL;
}
}