-
Notifications
You must be signed in to change notification settings - Fork 317
Expand file tree
/
Copy pathRobot.java
More file actions
1558 lines (1472 loc) · 43.9 KB
/
Copy pathRobot.java
File metadata and controls
1558 lines (1472 loc) · 43.9 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
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
/*
* Copyright (c) 2001-2025 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://robocode.sourceforge.io/license/epl-v10.html
*/
package robocode;
import robocode.robotinterfaces.*;
import robocode.robotinterfaces.peer.IStandardRobotPeer;
import java.awt.*;
/**
* The basic robot class that you will extend to create your own robots.
* <p>Please note the following standards will be used:
* <br> heading - absolute angle in degrees with 0 facing up the screen,
* positive clockwise. 0 <= heading < 360.
* <br> bearing - relative angle to some object from your robot's heading,
* positive clockwise. -180 < bearing <= 180
* <br> All coordinates are expressed as (x,y).
* <br> All coordinates are positive.
* <br> The origin (0,0) is at the bottom left of the screen.
* <br> Positive x is right.
* <br> Positive y is up.
* </p>
*
* @see <a target="_top" href="https://robocode.sourceforge.io">
* robocode.sourceforge.net</a>
* @see <a href="https://robocode.sourceforge.io/myfirstrobot/MyFirstRobot.html">
* Building your first robot</a>
*
* @see JuniorRobot
* @see AdvancedRobot
* @see TeamRobot
* @see Droid
* @see RateControlRobot
* @see BorderSentry
*
* @author Mathew A. Nelson (original)
* @author Flemming N. Larsen (contributor)
* @author Matthew Reeder (contributor)
* @author Stefan Westen (contributor)
* @author Pavel Savara (contributor)
*/
public class Robot extends _Robot implements IInteractiveRobot, IPaintRobot, IBasicEvents3, IInteractiveEvents, IPaintEvents {
private static final int
WIDTH = 36,
HEIGHT = 36;
/**
* Constructs a new robot.
*/
public Robot() {}
/**
* {@inheritDoc}}
*/
public final Runnable getRobotRunnable() {
return this;
}
/**
* {@inheritDoc}}
*/
public final IBasicEvents getBasicEventListener() {
return this;
}
/**
* {@inheritDoc}}
*/
public final IInteractiveEvents getInteractiveEventListener() {
return this;
}
/**
* {@inheritDoc}}
*/
public final IPaintEvents getPaintEventListener() {
return this;
}
/**
* Immediately moves your robot ahead (forward) by distance measured in
* pixels.
* <p>
* This call executes immediately, and does not return until it is complete,
* i.e. when the remaining distance to move is 0.
* <p>
* If the robot collides with a wall, the move is complete, meaning that the
* robot will not move any further. If the robot collides with another
* robot, the move is complete if you are heading toward the other robot.
* <p>
* Note that both positive and negative values can be given as input,
* where negative values means that the robot is set to move backward
* instead of forward.
* <p>
* Example:
* <pre>
* // Move the robot 100 pixels forward
* ahead(100);
*
* // Afterwards, move the robot 50 pixels backward
* ahead(-50);
* </pre>
*
* @param distance the distance to move ahead measured in pixels.
* If this value is negative, the robot will move back instead of ahead.
* @see #back(double)
* @see #onHitWall(HitWallEvent)
* @see #onHitRobot(HitRobotEvent)
*/
public void ahead(double distance) {
if (peer != null) {
peer.move(distance);
} else {
uninitializedException();
}
}
/**
* Immediately moves your robot backward by distance measured in pixels.
* <p>
* This call executes immediately, and does not return until it is complete,
* i.e. when the remaining distance to move is 0.
* <p>
* If the robot collides with a wall, the move is complete, meaning that the
* robot will not move any further. If the robot collides with another
* robot, the move is complete if you are heading toward the other robot.
* <p>
* Note that both positive and negative values can be given as input,
* where negative values means that the robot is set to move forward instead
* of backward.
* <p>
* Example:
* <pre>
* // Move the robot 100 pixels backward
* back(100);
*
* // Afterwards, move the robot 50 pixels forward
* back(-50);
* </pre>
*
* @param distance the distance to move back measured in pixels.
* If this value is negative, the robot will move ahead instead of back.
* @see #ahead(double)
* @see #onHitWall(HitWallEvent)
* @see #onHitRobot(HitRobotEvent)
*/
public void back(double distance) {
if (peer != null) {
peer.move(-distance);
} else {
uninitializedException();
}
}
/**
* Returns the width of the current battlefield measured in pixels.
*
* @return the width of the current battlefield measured in pixels.
*/
public double getBattleFieldWidth() {
if (peer != null) {
return peer.getBattleFieldWidth();
}
uninitializedException();
return 0; // never called
}
/**
* Returns the height of the current battlefield measured in pixels.
*
* @return the height of the current battlefield measured in pixels.
*/
public double getBattleFieldHeight() {
if (peer != null) {
return peer.getBattleFieldHeight();
}
uninitializedException();
return 0; // never called
}
/**
* Returns the direction that the robot's body is facing, in degrees.
* The value returned will be between 0 and 360 (is excluded).
* <p>
* Note that the heading in Robocode is like a compass, where 0 means North,
* 90 means East, 180 means South, and 270 means West.
*
* @return the direction that the robot's body is facing, in degrees.
* @see #getGunHeading()
* @see #getRadarHeading()
*/
public double getHeading() {
if (peer != null) {
double rv = 180.0 * peer.getBodyHeading() / Math.PI;
while (rv < 0) {
rv += 360;
}
while (rv >= 360) {
rv -= 360;
}
return rv;
}
uninitializedException();
return 0; // never called
}
/**
* Returns the height of the robot measured in pixels.
*
* @return the height of the robot measured in pixels.
* @see #getWidth()
*/
public double getHeight() {
if (peer == null) {
uninitializedException();
}
return HEIGHT;
}
/**
* Returns the width of the robot measured in pixels.
*
* @return the width of the robot measured in pixels.
* @see #getHeight()
*/
public double getWidth() {
if (peer == null) {
uninitializedException();
}
return WIDTH;
}
/**
* Returns the robot's name.
*
* @return the robot's name.
*/
public String getName() {
if (peer != null) {
return peer.getName();
}
uninitializedException();
return null; // never called
}
/**
* Returns the X position of the robot. (0,0) is at the bottom left of the
* battlefield.
*
* @return the X position of the robot.
* @see #getY()
*/
public double getX() {
if (peer != null) {
return peer.getX();
}
uninitializedException();
return 0; // never called
}
/**
* Returns the Y position of the robot. (0,0) is at the bottom left of the
* battlefield.
*
* @return the Y position of the robot.
* @see #getX()
*/
public double getY() {
if (peer != null) {
return peer.getY();
}
uninitializedException();
return 0; // never called
}
/**
* The main method in every robot. You must override this to set up your
* robot's basic behavior.
* <p>
* Example:
* <pre>
* // A basic robot that moves around in a square
* public void run() {
* while (true) {
* ahead(100);
* turnRight(90);
* }
* }
* </pre>
*/
public void run() {}
/**
* Immediately turns the robot's body to the left by degrees.
* <p>
* This call executes immediately, and does not return until it is complete,
* i.e. when the angle remaining in the robot's turn is 0.
* <p>
* Note that both positive and negative values can be given as input,
* where negative values means that the robot's body is set to turn right
* instead of left.
* <p>
* Example:
* <pre>
* // Turn the robot 180 degrees to the left
* turnLeft(180);
*
* // Afterwards, turn the robot 90 degrees to the right
* turnLeft(-90);
* </pre>
*
* @param degrees the amount of degrees to turn the robot's body to the left.
* If {@code degrees} > 0 the robot will turn left.
* If {@code degrees} < 0 the robot will turn right.
* If {@code degrees} = 0 the robot will not turn, but execute.
* @see #turnRight(double)
* @see #turnGunLeft(double)
* @see #turnGunRight(double)
* @see #turnRadarLeft(double)
* @see #turnRadarRight(double)
*/
public void turnLeft(double degrees) {
if (peer != null) {
peer.turnBody(-Math.toRadians(degrees));
} else {
uninitializedException();
}
}
/**
* Immediately turns the robot's body to the right by degrees.
* This call executes immediately, and does not return until it is complete,
* i.e. when the angle remaining in the robot's turn is 0.
* <p>
* Note that both positive and negative values can be given as input,
* where negative values means that the robot's body is set to turn left
* instead of right.
* <p>
* Example:
* <pre>
* // Turn the robot 180 degrees to the right
* turnRight(180);
*
* // Afterwards, turn the robot 90 degrees to the left
* turnRight(-90);
* </pre>
*
* @param degrees the amount of degrees to turn the robot's body to the right.
* If {@code degrees} > 0 the robot will turn right.
* If {@code degrees} < 0 the robot will turn left.
* If {@code degrees} = 0 the robot will not turn, but execute.
* @see #turnLeft(double)
* @see #turnGunLeft(double)
* @see #turnGunRight(double)
* @see #turnRadarLeft(double)
* @see #turnRadarRight(double)
*/
public void turnRight(double degrees) {
if (peer != null) {
peer.turnBody(Math.toRadians(degrees));
} else {
uninitializedException();
}
}
/**
* Do nothing this turn, meaning that the robot will skip it's turn.
* <p>
* This call executes immediately, and does not return until the turn is
* over.
*/
public void doNothing() {
if (peer != null) {
peer.execute();
} else {
uninitializedException();
}
}
/**
* Immediately fires a bullet. The bullet will travel in the direction the
* gun is pointing.
* <p>
* The specified bullet power is an amount of energy that will be taken from
* the robot's energy. Hence, the more power you want to spend on the
* bullet, the more energy is taken from your robot.
* <p>
* The bullet will do (4 * power) damage if it hits another robot. If power
* is greater than 1, it will do an additional 2 * (power - 1) damage.
* You will get (3 * power) back if you hit the other robot. You can call
* {@link Rules#getBulletDamage(double)} for getting the damage that a
* bullet with a specific bullet power will do.
* <p>
* The specified bullet power should be between
* {@link Rules#MIN_BULLET_POWER} and {@link Rules#MAX_BULLET_POWER}.
* <p>
* Note that the gun cannot fire if the gun is overheated, meaning that
* {@link #getGunHeat()} returns a value > 0.
* <p>
* A event is generated when the bullet hits a robot
* ({@link BulletHitEvent}), wall ({@link BulletMissedEvent}), or another
* bullet ({@link BulletHitBulletEvent}).
* <p>
* Example:
* <pre>
* // Fire a bullet with maximum power if the gun is ready
* if (getGunHeat() == 0) {
* fire(Rules.MAX_BULLET_POWER);
* }
* </pre>
*
* @param power the amount of energy given to the bullet, and subtracted
* from the robot's energy.
* @see #fireBullet(double)
* @see #getGunHeat()
* @see #getGunCoolingRate()
* @see #onBulletHit(BulletHitEvent)
* @see #onBulletHitBullet(BulletHitBulletEvent)
* @see #onBulletMissed(BulletMissedEvent)
*/
public void fire(double power) {
if (peer != null) {
peer.setFire(power);
peer.execute();
} else {
uninitializedException();
}
}
/**
* Immediately fires a bullet. The bullet will travel in the direction the
* gun is pointing.
* <p>
* The specified bullet power is an amount of energy that will be taken from
* the robot's energy. Hence, the more power you want to spend on the
* bullet, the more energy is taken from your robot.
* <p>
* The bullet will do (4 * power) damage if it hits another robot. If power
* is greater than 1, it will do an additional 2 * (power - 1) damage.
* You will get (3 * power) back if you hit the other robot. You can call
* {@link Rules#getBulletDamage(double)} for getting the damage that a
* bullet with a specific bullet power will do.
* <p>
* The specified bullet power should be between
* {@link Rules#MIN_BULLET_POWER} and {@link Rules#MAX_BULLET_POWER}.
* <p>
* Note that the gun cannot fire if the gun is overheated, meaning that
* {@link #getGunHeat()} returns a value > 0.
* <p>
* A event is generated when the bullet hits a robot
* ({@link BulletHitEvent}), wall ({@link BulletMissedEvent}), or another
* bullet ({@link BulletHitBulletEvent}).
* <p>
* Example:
* <pre>
* // Fire a bullet with maximum power if the gun is ready
* if (getGunHeat() == 0) {
* Bullet bullet = fireBullet(Rules.MAX_BULLET_POWER);
*
* // Get the velocity of the bullet
* if (bullet != null) {
* double bulletVelocity = bullet.getVelocity();
* }
* }
* </pre>
*
* @param power the amount of energy given to the bullet, and subtracted
* from the robot's energy.
* @return a {@link Bullet} that contains information about the bullet if it
* was actually fired, which can be used for tracking the bullet after it
* has been fired. If the bullet was not fired, {@code null} is returned.
* @see #fire(double)
* @see Bullet
* @see #getGunHeat()
* @see #getGunCoolingRate()
* @see #onBulletHit(BulletHitEvent)
* @see #onBulletHitBullet(BulletHitBulletEvent)
* @see #onBulletMissed(BulletMissedEvent)
*/
public Bullet fireBullet(double power) {
if (peer != null) {
return peer.fire(power);
}
uninitializedException();
return null;
}
/**
* Returns the rate at which the gun will cool down, i.e. the amount of heat
* the gun heat will drop per turn.
* <p>
* The gun cooling rate is default 0.1 / turn, but can be changed by the
* battle setup. So don't count on the cooling rate being 0.1!
*
* @return the gun cooling rate
* @see #getGunHeat()
* @see #fire(double)
* @see #fireBullet(double)
*/
public double getGunCoolingRate() {
if (peer != null) {
return peer.getGunCoolingRate();
}
uninitializedException();
return 0; // never called
}
/**
* Returns the direction that the robot's gun is facing, in degrees.
* The value returned will be between 0 and 360 (is excluded).
* <p>
* Note that the heading in Robocode is like a compass, where 0 means North,
* 90 means East, 180 means South, and 270 means West.
*
* @return the direction that the robot's gun is facing, in degrees.
* @see #getHeading()
* @see #getRadarHeading()
*/
public double getGunHeading() {
if (peer != null) {
return peer.getGunHeading() * 180.0 / Math.PI;
}
uninitializedException();
return 0; // never called
}
/**
* Returns the current heat of the gun. The gun cannot fire unless this is
* 0. (Calls to fire will succeed, but will not actually fire unless
* getGunHeat() == 0).
* <p>
* The amount of gun heat generated when the gun is fired is
* 1 + (firePower / 5). Each turn the gun heat drops by the amount returned
* by {@link #getGunCoolingRate()}, which is a battle setup.
* <p>
* Note that all guns are "hot" at the start of each round, where the gun
* heat is 3.
*
* @return the current gun heat
* @see #getGunCoolingRate()
* @see #fire(double)
* @see #fireBullet(double)
*/
public double getGunHeat() {
if (peer != null) {
return peer.getGunHeat();
}
uninitializedException();
return 0; // never called
}
/**
* Returns the number of rounds in the current battle.
*
* @return the number of rounds in the current battle
* @see #getRoundNum()
*/
public int getNumRounds() {
if (peer != null) {
return peer.getNumRounds();
}
uninitializedException();
return 0; // never called
}
/**
* Returns the sentry border size for a {@link robocode.BorderSentry BorderSentry} that defines the how
* far a BorderSentry is allowed to move from the border edges measured in units.<br>
* Hence, the sentry border size defines the width/range of the border area surrounding the battlefield that
* BorderSentrys cannot leave (sentry robots robots must stay in the border area), but it also define the
* distance from the border edges where BorderSentrys are allowed/able to make damage to robots entering this
* border area.
*
* @return the border size in units/pixels.
*
* @since 1.9.0.0
*/
public int getSentryBorderSize() {
if (peer != null) {
return peer.getSentryBorderSize();
}
uninitializedException();
return 0; // never called
}
/**
* Returns how many opponents that are left in the current round.
*
* @return how many opponents that are left in the current round.
*/
public int getOthers() {
if (peer != null) {
return peer.getOthers();
}
uninitializedException();
return 0; // never called
}
/**
* Returns how many sentry robots that are left in the current round.
*
* @return how many sentry robots that are left in the current round.
*
* @since 1.9.1.0
*/
public int getNumSentries() {
if (peer != null) {
return peer.getNumSentries();
}
uninitializedException();
return 0; // never called
}
/**
* Returns the direction that the robot's radar is facing, in degrees.
* The value returned will be between 0 and 360 (is excluded).
* <p>
* Note that the heading in Robocode is like a compass, where 0 means North,
* 90 means East, 180 means South, and 270 means West.
*
* @return the direction that the robot's radar is facing, in degrees.
* @see #getHeading()
* @see #getGunHeading()
*/
public double getRadarHeading() {
if (peer != null) {
return peer.getRadarHeading() * 180.0 / Math.PI;
}
uninitializedException();
return 0; // never called
}
/**
* Returns the current round number (0 to {@link #getNumRounds()} - 1) of
* the battle.
*
* @return the current round number of the battle (zero indexed).
* @see #getNumRounds()
*/
public int getRoundNum() {
if (peer != null) {
return peer.getRoundNum();
}
uninitializedException();
return 0; // never called
}
/**
* Returns the game time of the current round, where the time is equal to
* the current turn in the round.
* <p>
* A battle consists of multiple rounds.
* <p>
* Time is reset to 0 at the beginning of every round.
*
* @return the game time/turn of the current round.
*/
public long getTime() {
if (peer != null) {
return peer.getTime();
}
uninitializedException();
return 0; // never called
}
/**
* Returns the velocity of the robot measured in pixels/turn.
* <p>
* The maximum velocity of a robot is defined by {@link Rules#MAX_VELOCITY}
* (8 pixels / turn).
*
* @return the velocity of the robot measured in pixels/turn.
* @see Rules#MAX_VELOCITY
*/
public double getVelocity() {
if (peer != null) {
return peer.getVelocity();
}
uninitializedException();
return 0; // never called
}
/**
* {@inheritDoc}
*/
public void onBulletHit(BulletHitEvent event) {}
/**
* {@inheritDoc}
*/
public void onBulletHitBullet(BulletHitBulletEvent event) {}
/**
* {@inheritDoc}
*/
public void onBulletMissed(BulletMissedEvent event) {}
/**
* {@inheritDoc}
*/
public void onDeath(DeathEvent event) {}
/**
* {@inheritDoc}
*/
public void onHitByBullet(HitByBulletEvent event) {}
/**
* {@inheritDoc}
*/
public void onHitRobot(HitRobotEvent event) {}
/**
* {@inheritDoc}
*/
public void onHitWall(HitWallEvent event) {}
/**
* {@inheritDoc}
*/
public void onRobotDeath(RobotDeathEvent event) {}
/**
* {@inheritDoc}
*/
public void onScannedRobot(ScannedRobotEvent event) {}
/**
* {@inheritDoc}
*/
public void onWin(WinEvent event) {}
/**
* {@inheritDoc}
*/
public void onRoundEnded(RoundEndedEvent event) {}
/**
* {@inheritDoc}
*/
public void onBattleEnded(BattleEndedEvent event) {}
/**
* Scans for other robots. This method is called automatically by the game,
* as long as the robot is moving, turning its body, turning its gun, or
* turning its radar.
* <p>
* Scan will cause {@link #onScannedRobot(ScannedRobotEvent)
* onScannedRobot(ScannedRobotEvent)} to be called if you see a robot.
* <p>
* There are 2 reasons to call {@code scan()} manually:
* <ol>
* <li>You want to scan after you stop moving.
* <li>You want to interrupt the {@code onScannedRobot} event. This is more
* likely. If you are in {@code onScannedRobot} and call {@code scan()},
* and you still see a robot, then the system will interrupt your
* {@code onScannedRobot} event immediately and start it from the top.
* </ol>
* <p>
* This call executes immediately.
*
* @see #onScannedRobot(ScannedRobotEvent)
* @see ScannedRobotEvent
*/
public void scan() {
if (peer != null) {
peer.rescan();
} else {
uninitializedException();
}
}
/**
* Sets the gun to turn independent from the robot's turn.
* <p>
* Ok, so this needs some explanation: The gun is mounted on the robot's
* body. So, normally, if the robot turns 90 degrees to the right, then the
* gun will turn with it as it is mounted on top of the robot's body. To
* compensate for this, you can call {@code setAdjustGunForRobotTurn(true)}.
* When this is set, the gun will turn independent from the robot's turn,
* i.e. the gun will compensate for the robot's body turn.
* <p>
* Note: This method is additive until you reach the maximum the gun can
* turn. The "adjust" is added to the amount you set for turning the robot,
* then capped by the physics of the game. If you turn infinite, then the
* adjust is ignored (and hence overridden).
* <p>
* Example, assuming both the robot and gun start out facing up (0 degrees):
* <pre>
* // Set gun to turn with the robot's turn
* setAdjustGunForRobotTurn(false); // This is the default
* turnRight(90);
* // At this point, both the robot and gun are facing right (90 degrees)
* turnLeft(90);
* // Both are back to 0 degrees
*
* -- or --
*
* // Set gun to turn independent from the robot's turn
* setAdjustGunForRobotTurn(true);
* turnRight(90);
* // At this point, the robot is facing right (90 degrees), but the gun is still facing up.
* turnLeft(90);
* // Both are back to 0 degrees.
* </pre>
* <p>
* Note: The gun compensating this way does count as "turning the gun".
* See {@link #setAdjustRadarForGunTurn(boolean)} for details.
*
* @param independent {@code true} if the gun must turn independent from the
* robot's turn; {@code false} if the gun must turn with the robot's turn.
* @see #setAdjustRadarForGunTurn(boolean)
*/
public void setAdjustGunForRobotTurn(boolean independent) {
if (peer != null) {
((IStandardRobotPeer) peer).setAdjustGunForBodyTurn(independent);
} else {
uninitializedException();
}
}
/**
* Sets the radar to turn independent from the robot's turn.
* <p>
* Ok, so this needs some explanation: The radar is mounted on the gun, and
* the gun is mounted on the robot's body. So, normally, if the robot turns
* 90 degrees to the right, the gun turns, as does the radar. Hence, if the
* robot turns 90 degrees to the right, then the gun and radar will turn
* with it as the radar is mounted on top of the gun. To compensate for
* this, you can call {@code setAdjustRadarForRobotTurn(true)}. When this is
* set, the radar will turn independent from the robot's turn, i.e. the
* radar will compensate for the robot's turn.
* <p>
* Note: This method is additive until you reach the maximum the radar can
* turn. The "adjust" is added to the amount you set for turning the robot,
* then capped by the physics of the game. If you turn infinite, then the
* adjust is ignored (and hence overridden).
* <p>
* Example, assuming the robot, gun, and radar all start out facing up (0
* degrees):
* <pre>
* // Set radar to turn with the robots's turn
* setAdjustRadarForRobotTurn(false); // This is the default
* turnRight(90);
* // At this point, the body, gun, and radar are all facing right (90 degrees);
*
* -- or --
*
* // Set radar to turn independent from the robot's turn
* setAdjustRadarForRobotTurn(true);
* turnRight(90);
* // At this point, the robot and gun are facing right (90 degrees), but the radar is still facing up.
* </pre>
*
* @param independent {@code true} if the radar must turn independent from
* the robots's turn; {@code false} if the radar must turn with the robot's
* turn.
* @see #setAdjustGunForRobotTurn(boolean)
* @see #setAdjustRadarForGunTurn(boolean)
*/
public void setAdjustRadarForRobotTurn(boolean independent) {
if (peer != null) {
((IStandardRobotPeer) peer).setAdjustRadarForBodyTurn(independent);
} else {
uninitializedException();
}
}
/**
* Sets the radar to turn independent from the gun's turn.
* <p>
* Ok, so this needs some explanation: The radar is mounted on the robot's
* gun. So, normally, if the gun turns 90 degrees to the right, then the
* radar will turn with it as it is mounted on top of the gun. To compensate
* for this, you can call {@code setAdjustRadarForGunTurn(true)}. When this
* is set, the radar will turn independent from the robot's turn, i.e. the
* radar will compensate for the gun's turn.
* <p>
* Note: This method is additive until you reach the maximum the radar can
* turn. The "adjust" is added to the amount you set for turning the gun,
* then capped by the physics of the game. If you turn infinite, then the
* adjust is ignored (and hence overridden).
* <p>
* Example, assuming both the gun and radar start out facing up (0 degrees):
* <pre>
* // Set radar to turn with the gun's turn
* setAdjustRadarForGunTurn(false); // This is the default
* turnGunRight(90);
* // At this point, both the radar and gun are facing right (90 degrees);
*
* -- or --
*
* // Set radar to turn independent from the gun's turn
* setAdjustRadarForGunTurn(true);
* turnGunRight(90);
* // At this point, the gun is facing right (90 degrees), but the radar is still facing up.
* </pre>
* Note: Calling {@code setAdjustRadarForGunTurn(boolean)} will
* automatically call {@link #setAdjustRadarForRobotTurn(boolean)} with the
* same value, unless you have already called it earlier. This behavior is
* primarily for backward compatibility with older Robocode robots.
*
* @param independent {@code true} if the radar must turn independent from
* the gun's turn; {@code false} if the radar must turn with the gun's
* turn.
* @see #setAdjustRadarForRobotTurn(boolean)
* @see #setAdjustGunForRobotTurn(boolean)
*/
public void setAdjustRadarForGunTurn(boolean independent) {
if (peer != null) {
((IStandardRobotPeer) peer).setAdjustRadarForGunTurn(independent);
} else {
uninitializedException();
}
}
/**
* Sets the color of the robot's body, gun, and radar in the same time.
* <p>
* A {@code null} indicates the default (blue) color.
* <p>
* Example:
* <pre>
* // Don't forget to import java.awt.Color at the top...
* import java.awt.Color;
* ...
*
* public void run() {
* setColors(null, Color.RED, new Color(150, 0, 150));
* ...
* }
* </pre>
*
* @param bodyColor the new body color
* @param gunColor the new gun color
* @param radarColor the new radar color
* @see #setColors(Color, Color, Color, Color, Color)
* @see #setAllColors(Color)
* @see #setBodyColor(Color)
* @see #setGunColor(Color)
* @see #setRadarColor(Color)
* @see #setBulletColor(Color)
* @see #setScanColor(Color)
* @see Color
*/
public void setColors(Color bodyColor, Color gunColor, Color radarColor) {
if (peer != null) {
peer.setBodyColor(bodyColor);
peer.setGunColor(gunColor);
peer.setRadarColor(radarColor);
} else {
uninitializedException();
}
}
/**
* Sets the color of the robot's body, gun, radar, bullet, and scan arc in
* the same time.
* <p>
* A {@code null} indicates the default (blue) color for the body, gun,
* radar, and scan arc, but white for the bullet color.
* <p>
* Example:
* <pre>
* // Don't forget to import java.awt.Color at the top...
* import java.awt.Color;
* ...
*
* public void run() {
* setColors(null, Color.RED, Color.GREEN, null, new Color(150, 0, 150));
* ...
* }
* </pre>
*
* @param bodyColor the new body color
* @param gunColor the new gun color
* @param radarColor the new radar color
* @param bulletColor the new bullet color
* @param scanArcColor the new scan arc color
* @see #setColors(Color, Color, Color)
* @see #setAllColors(Color)
* @see #setBodyColor(Color)
* @see #setGunColor(Color)
* @see #setRadarColor(Color)
* @see #setBulletColor(Color)
* @see #setScanColor(Color)
* @see Color
* @since 1.1.3
*/
public void setColors(Color bodyColor, Color gunColor, Color radarColor, Color bulletColor, Color scanArcColor) {
if (peer != null) {