1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package nl.tudelft.goal.ut2004.agent;
22
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.LinkedList;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.concurrent.ConcurrentLinkedQueue;
29
30 import nl.tudelft.goal.EIS2Java.annotation.AsAction;
31 import nl.tudelft.goal.EIS2Java.annotation.AsAllPercepts;
32 import nl.tudelft.goal.EIS2Java.annotation.AsPercept;
33 import nl.tudelft.goal.EIS2Java.translation.Filter.Type;
34 import nl.tudelft.goal.unreal.messages.BotParameters;
35 import nl.tudelft.goal.unreal.messages.Parameters;
36 import nl.tudelft.goal.unreal.messages.Team;
37 import nl.tudelft.goal.unreal.util.Selector;
38 import nl.tudelft.goal.ut2004.agent.module.PerceptModule;
39 import nl.tudelft.goal.ut2004.messages.Action;
40 import nl.tudelft.goal.ut2004.messages.Combo;
41 import nl.tudelft.goal.ut2004.messages.FireMode;
42 import nl.tudelft.goal.ut2004.messages.FlagState;
43 import nl.tudelft.goal.ut2004.messages.None;
44 import nl.tudelft.goal.ut2004.messages.Percept;
45 import nl.tudelft.goal.ut2004.messages.SelectorList;
46 import nl.tudelft.goal.ut2004.messages.UnrealIdOrLocation;
47 import nl.tudelft.goal.ut2004.messages.WeaponPrefList;
48 import nl.tudelft.goal.ut2004.selector.ClosestEnemy;
49 import nl.tudelft.goal.ut2004.selector.ContextSelector;
50 import nl.tudelft.pogamut.ut2004.agent.module.sensor.Projectiles;
51 import nl.tudelft.pogamut.ut2004.agent.module.shooting.WeaponryShooting;
52 import nl.tudelft.pogamut.ut2004.agent.module.shooting.util.FocusProvider;
53 import nl.tudelft.pogamut.ut2004.agent.module.shooting.util.OrderedFocusProvider;
54 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.AssaultRifleShooting;
55 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.BioRifleShooting;
56 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.FlakCannonShooting;
57 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.LigthningGunShooting;
58 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.LinkGunShooting;
59 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.MinigunShooting;
60 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.RocketLauncherShooting;
61 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.ShieldGunShooting;
62 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.ShockRifleShooting;
63 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.SniperRifleShooting;
64 import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.EventListener;
65 import cz.cuni.amis.pogamut.base.communication.worldview.object.IWorldObject;
66 import cz.cuni.amis.pogamut.base.utils.logging.IAgentLogger;
67 import cz.cuni.amis.pogamut.base.utils.math.DistanceUtils;
68 import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
69 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
70 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
71 import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Weapon;
72 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.WeaponPref;
73 import cz.cuni.amis.pogamut.ut2004.agent.navigation.NavigationState;
74 import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004DistanceStuckDetector;
75 import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004PositionStuckDetector;
76 import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004TimeStuckDetector;
77 import cz.cuni.amis.pogamut.ut2004.agent.params.UT2004AgentParameters;
78 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
79 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotModuleController;
80 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType;
81 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Initialize;
82 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.BotKilled;
83 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.FlagInfo;
84 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Item;
85 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
86 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
87 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PlayerKilled;
88 import cz.cuni.amis.pogamut.ut2004.utils.UT2004BotRunner;
89
90 @SuppressWarnings("rawtypes")
91 public class UT2004BotBehavior extends UT2004BotModuleController<UT2004Bot> {
92
93 protected List<ContextSelector> targetSelector = new ArrayList<ContextSelector>();
94 protected List<ContextSelector> lookSelector = new ArrayList<ContextSelector>();
95 protected Projectiles projectiles;
96 protected WeaponryShooting weaponShooting;
97 protected FocusProvider lookFocus = new FocusProvider();
98 protected OrderedFocusProvider focus = new OrderedFocusProvider();
99 protected long logicIteration;
100 protected PerceptModule percepts;
101
102
103
104 protected BotParameters parameters;
105
106
107
108
109 private ConcurrentLinkedQueue<Action> actions = new ConcurrentLinkedQueue<Action>();
110
111 @Override
112 public void initializeController(UT2004Bot bot) {
113 super.initializeController(bot);
114
115
116 IAgentLogger logger = bot.getLogger();
117 UT2004AgentParameters parameters = bot.getParams();
118 if ((parameters instanceof BotParameters)) {
119 this.parameters = (BotParameters) parameters;
120 } else {
121 log.warning("Provided parameters were not a subclass of UnrealGoalParameters, using defaults.");
122 this.parameters = new BotParameters(logger);
123 }
124 Parameters defaults = BotParameters.getDefaults(logger);
125 this.parameters.assignDefaults(defaults);
126
127 }
128
129
130
131
132 protected void initializeModules(UT2004Bot bot) {
133 super.initializeModules(bot);
134
135 projectiles = new Projectiles(bot, info);
136 weaponShooting = new WeaponryShooting(bot, info, weaponry, weaponPrefs, shoot);
137
138
139 percepts = new PerceptModule(bot);
140
141 initializeWeaponShootings();
142 }
143
144
145
146
147 protected void initializeWeaponShootings() {
148 weaponShooting.addWeaponShooting(new LinkGunShooting(bot, info, shoot, weaponry));
149 weaponShooting.addWeaponShooting(new ShockRifleShooting(bot, info, shoot, weaponry, projectiles));
150 weaponShooting.addWeaponShooting(new MinigunShooting(bot, info, shoot, weaponry));
151 weaponShooting.addWeaponShooting(new FlakCannonShooting(bot, info, shoot, weaponry));
152 weaponShooting.addWeaponShooting(new ShieldGunShooting(bot, info, shoot, weaponry, projectiles, senses));
153 weaponShooting.addWeaponShooting(new BioRifleShooting(bot, info, shoot, weaponry));
154 weaponShooting.addWeaponShooting(new AssaultRifleShooting(bot, info, shoot, weaponry));
155 weaponShooting.addWeaponShooting(new RocketLauncherShooting(bot, info, shoot, weaponry));
156 weaponShooting.addWeaponShooting(new LigthningGunShooting(bot, info, shoot, weaponry));
157 weaponShooting.addWeaponShooting(new SniperRifleShooting(bot, info, shoot, weaponry));
158 }
159
160
161
162
163
164 @Override
165 public void finishControllerInitialization() {
166 super.finishControllerInitialization();
167
168
169
170
171 focus.add(weaponShooting.getFocus());
172 focus.add(lookFocus);
173 navigation.setFocus(focus);
174 }
175
176
177
178
179
180
181 @Override
182 public Initialize getInitializeCommand() {
183 assert parameters != null;
184
185
186 Initialize init = super.getInitializeCommand();
187 init.setDesiredSkill(parameters.getSkill());
188 init.setSkin(parameters.getSkin().getUnrealName());
189 init.setTeam(parameters.getTeam());
190 init.setShouldLeadTarget(parameters.shouldLeadTarget());
191 init.setLocation(parameters.getStartLocation());
192 init.setRotation(parameters.getStartRotation());
193
194
195
196
197 return init;
198
199 }
200
201
202
203
204
205
206 @Override
207 public void beforeFirstLogic() {
208 targetSelector.add(new ClosestEnemy().setContext(this));
209 lookSelector.add(new ClosestEnemy().setContext(this));
210
211 weaponPrefs.addGeneralPref(ItemType.SHOCK_RIFLE, false);
212 weaponPrefs.addGeneralPref(ItemType.ROCKET_LAUNCHER, true);
213 weaponPrefs.addGeneralPref(ItemType.FLAK_CANNON, true);
214 weaponPrefs.addGeneralPref(ItemType.SNIPER_RIFLE, true);
215 weaponPrefs.addGeneralPref(ItemType.LIGHTNING_GUN, true);
216 weaponPrefs.addGeneralPref(ItemType.MINIGUN, true);
217 weaponPrefs.addGeneralPref(ItemType.LINK_GUN, true);
218 weaponPrefs.addGeneralPref(ItemType.BIO_RIFLE, false);
219 weaponPrefs.addGeneralPref(ItemType.ASSAULT_RIFLE, true);
220 weaponPrefs.addGeneralPref(ItemType.ASSAULT_RIFLE, false);
221 weaponPrefs.addGeneralPref(ItemType.SHIELD_GUN, false);
222 weaponPrefs.addGeneralPref(ItemType.SHIELD_GUN, true);
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 @Override
254 public void logic() {
255 super.logic();
256
257
258 while (!actions.isEmpty()) {
259 actions.remove().execute();
260 }
261
262
263
264 ILocated shootSelected = null;
265 for (Selector<ILocated> selector : targetSelector) {
266 shootSelected = selector.select(players.getVisiblePlayers().values());
267 if (shootSelected != null) {
268 break;
269 }
270 }
271 weaponShooting.shoot(shootSelected);
272
273
274
275 ILocated lookSelected = null;
276 for (Selector<ILocated> selector : lookSelector) {
277 lookSelected = selector.select(players.getVisiblePlayers().values());
278 if (lookSelected != null) {
279 break;
280 }
281 }
282 lookFocus.setFocus(lookSelected);
283
284
285 if (!navigation.isNavigating()) {
286
287 if (focus.getLocation() != null) {
288 move.turnTo(focus.getLocation());
289 }
290
291 else {
292 move.turnHorizontal(30);
293 }
294 }
295
296
297 logicIteration++;
298
299
300 percepts.updatePercepts();
301 }
302
303
304
305
306
307
308
309 public void addAction(Action action) {
310 actions.add(action);
311
312
313
314 try {
315 Thread.sleep(500);
316 } catch (InterruptedException e) {
317
318 e.printStackTrace();
319 }
320 }
321
322
323
324
325
326
327 @AsAllPercepts
328 public Map<String, Object> getAllPercepts() {
329 return percepts.getAllPercepts();
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 @AsAction(name = "navigate")
356 public void navigate(final UnrealIdOrLocation destination) {
357 log.info(String.format("navigate to %s called", destination));
358
359 addAction(new Action() {
360
361 @Override
362 public void execute() {
363 if (destination.isLocation()) {
364 log.info(String.format("navigate to %s executed", destination.getLocation()));
365 navigation.navigate(destination.getLocation());
366 return;
367 }
368
369 UnrealId id = destination.getId();
370
371 IWorldObject object = world.get(id);
372
373 if (object instanceof ILocated) {
374 navigation.navigate((ILocated) object);
375 log.info(String.format("navigate to %s executed", object));
376 return;
377 }
378
379 log.warning(String.format("failed to navigate to %s. Halting.", object));
380 navigation.stopNavigation();
381
382 }
383 });
384 }
385
386
387
388
389
390
391 @AsAction(name = "stop")
392 public void stop() {
393 log.info("stop called");
394
395 addAction(new Action() {
396 @Override
397 public void execute() {
398 log.info("stop executed");
399 navigation.stopNavigation();
400 }
401 });
402 }
403
404
405
406
407
408
409
410
411
412 @AsAction(name = "respawn")
413 public void respawn() {
414 log.info("respawn called");
415 addAction(new Action() {
416 @Override
417 public void execute() {
418 log.info("respawn executed");
419 bot.respawn();
420 }
421 });
422 }
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439 @AsAction(name = "combo")
440 public void combo(final Combo combo) {
441 log.info("combo %s called", combo);
442
443 addAction(new Action() {
444 @Override
445 public void execute() {
446
447 if (info.isAdrenalineSufficient()) {
448 log.info("combo %s executed", combo);
449 body.getAction().startCombo(combo.toString());
450 } else {
451 log.warning("combo %s failed, insufficient adrenaline", combo);
452 }
453
454 }
455 });
456 }
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472 @AsAction(name = "dropWeapon")
473 public void dropWeapon() {
474 log.info("drop called");
475
476 addAction(new Action() {
477 @Override
478 public void execute() {
479 Weapon weapon = weaponry.getCurrentWeapon();
480
481 body.getAction().throwWeapon();
482
483 if (weapon == null) {
484 log.warning(String.format("Could not drop weapon. Not holding a weapon."));
485 } else if (weapon.getType() == ItemType.SHIELD_GUN || weapon.getType() == ItemType.TRANSLOCATOR) {
486 log.warning(String.format("Could not drop weapon %s", weapon));
487 } else {
488 log.info("drop %s executed", weapon);
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 @AsAction(name = "path")
526 public Percept path(NavPoint from, NavPoint to) {
527
528 log.info(String.format("path from %s to %s executed", from, to));
529
530 double distance = fwMap.getDistance(from, to);
531 List<NavPoint> navPoints = fwMap.getPath(from, to);
532 List<UnrealId> unrealIds = new ArrayList<UnrealId>(navPoints.size());
533 for (NavPoint n : navPoints) {
534 unrealIds.add(n.getId());
535 }
536 return new Percept(distance, unrealIds);
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 @AsAction(name = "shoot")
570 public void shoot(final SelectorList targets) {
571 log.info(String.format("target %s called", targets));
572
573 addAction(new Action() {
574
575 @Override
576 public void execute() {
577 log.info(String.format("target %s executed", targetSelector));
578
579 targetSelector = targets.setContext(UT2004BotBehavior.this);
580 }
581 });
582
583 }
584
585
586
587
588
589
590
591
592
593
594
595
596
597 public void stopShooting() {
598 shoot(new SelectorList());
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 @AsAction(name = "prefer")
638 public void prefer(final WeaponPrefList weaponList) {
639 log.info(String.format("prefer %s called", weaponList));
640
641 addAction(new Action() {
642
643 @Override
644 public void execute() {
645 weaponPrefs.clearAllPrefs();
646
647 for (WeaponPref pref : weaponList) {
648 weaponPrefs.addGeneralPref(pref.getWeapon(), pref.isPrimary());
649 }
650
651 log.info(String.format("prefer %s executed", weaponList));
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 @AsAction(name = "look")
687 public void look(final SelectorList targets) {
688 log.info(String.format("look %s called", targets));
689
690 addAction(new Action() {
691
692 @Override
693 public void execute() {
694 log.info(String.format("look %s executed", targets));
695
696 lookSelector = targets.setContext(UT2004BotBehavior.this);
697 }
698 });
699 }
700
701
702
703
704
705
706
707
708
709
710 @AsAction(name = "skip")
711 public void skip() {
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 @AsPercept(name = "navigation", filter = Type.ON_CHANGE)
741 public NavigationState navigation() {
742
743 return navigation.getState().getFlag();
744 }
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764 @AsPercept(name = "self", filter = Type.ON_CHANGE)
765 public Percept self() {
766 return new Percept(info.getId(), info.getName(), Team.valueOf(info.getTeam()));
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 @AsPercept(name = "logic", filter = Type.ON_CHANGE)
793 public Percept logicIteration() {
794 return new Percept(logicIteration);
795 }
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815 @AsPercept(name = "orientation", filter = Type.ON_CHANGE)
816 public Percept orientation() {
817 return new Percept(info.getLocation(), info.getRotation(), info.getVelocity());
818 }
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840 @AsPercept(name = "status", filter = Type.ON_CHANGE)
841 public Percept status() {
842 return new Percept(info.getHealth(), info.getArmor(), info.getAdrenaline(), Combo.parseCombo(info.getSelf()
843 .getCombo()));
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 @AsPercept(name = "score", filter = Type.ON_CHANGE)
872 public Percept score() {
873 return new Percept(info.getKills(), info.getDeaths(), info.getSuicides());
874 }
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897 @AsPercept(name = "currentWeapon", filter = Type.ON_CHANGE)
898 public Percept currentWeapon() {
899 final Weapon weapon = weaponry.getCurrentWeapon();
900
901 if (weapon == null) {
902 return new Percept(new None(), FireMode.NONE);
903 }
904
905 return new Percept(weapon.getType(), FireMode.valueOf(info.isPrimaryShooting(), info.isSecondaryShooting()));
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 @AsPercept(name = "weapon", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
936 public Collection<Percept> weapon() {
937 Collection<Weapon> weapons = weaponry.getWeapons().values();
938 Collection<Percept> percepts = new ArrayList<Percept>(weapons.size());
939
940 for (Weapon w : weapons) {
941 if (w.getType() == ItemType.SHIELD_GUN) {
942
943
944
945 percepts.add(new Percept(w.getType(), 1, w.getSecondaryAmmo()));
946 } else {
947 percepts.add(new Percept(w.getType(), w.getPrimaryAmmo(), w.getSecondaryAmmo()));
948 }
949 }
950
951 return percepts;
952 }
953
954
955
956
957 private List<Percept> fragged = new LinkedList<Percept>();
958
959
960
961
962
963
964
965
966
967 private void fraggedEvent(final double time, final UnrealId killer, final UnrealId victem, final String weaponName) {
968 fragged.add(new Percept(time, killer, victem, ItemType.getItemType(weaponName)));
969 }
970
971
972
973
974
975
976 @EventListener(eventClass = BotKilled.class)
977 public void msgBotKilled(BotKilled msg) {
978 fraggedEvent(msg.getSimTime(), msg.getKiller(), info.getId(), msg.getWeaponName());
979 }
980
981
982
983
984
985
986
987 @EventListener(eventClass = PlayerKilled.class)
988 public void msgPlayerKilled(PlayerKilled msg) {
989 fraggedEvent(msg.getSimTime(), msg.getKiller(), msg.getId(), msg.getWeaponName());
990 }
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013 @AsPercept(name = "fragged", multiplePercepts = true, filter = Type.ALWAYS, event = true)
1014 public List<Percept> fragged() {
1015 ArrayList<Percept> percepts = new ArrayList<Percept>(fragged);
1016 fragged.clear();
1017 return percepts;
1018 }
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041 @AsPercept(name = "navPoint", multiplePercepts = true, filter = Type.ONCE)
1042 public Collection<NavPoint> navPoint() {
1043
1044 return world.getAll(NavPoint.class).values();
1045 }
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080 @AsPercept(name = "pickup", multiplePercepts = true, filter = Type.ONCE)
1081 public Collection<Percept> pickup() {
1082 Collection<Item> pickups = items.getKnownPickups().values();
1083 Collection<Percept> percepts = new ArrayList<Percept>(pickups.size());
1084 for (Item item : pickups) {
1085 if (!item.isDropped()) {
1086 percepts.add(new Percept(item.getNavPoint().getId(), item.getType().getCategory(), item.getType()));
1087
1088 }
1089 }
1090 return percepts;
1091 }
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112 @AsPercept(name = "base", multiplePercepts = true, filter = Type.ONCE)
1113 public List<Percept> base() {
1114 List<Percept> base = new ArrayList<Percept>(2);
1115
1116 Collection<NavPoint> navPoints = world.getAll(NavPoint.class).values();
1117
1118 NavPoint nav = DistanceUtils.getNearest(navPoints, game.getFlagBase(0));
1119 assert nav != null;
1120 base.add(new Percept(Team.RED, nav.getId()));
1121
1122 nav = DistanceUtils.getNearest(navPoints, game.getFlagBase(1));
1123 assert nav != null;
1124 base.add(new Percept(Team.RED, nav.getId()));
1125
1126 return base;
1127 }
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152 @AsPercept(name = "game", filter = Type.ON_CHANGE)
1153 public Percept game() {
1154 return new Percept(game.getGameType(), game.getMapName(), game.getTeamScoreLimit(), game.getRemainingTime());
1155 }
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184 @AsPercept(name = "teamScore", filter = Type.ON_CHANGE)
1185 public Percept teamScore() {
1186 return new Percept(game.getTeamScore(info.getTeam()), game.getTeamScore(1 - info.getTeam()));
1187 }
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216 @AsPercept(name = "flagState", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1217 public List<Percept> flagState() {
1218 List<Percept> percepts = new ArrayList<Percept>(2);
1219
1220 percepts.add(new Percept(Team.RED, FlagState.valueOfIgnoreCase(game.getFlag(Team.RED.id()).getState())));
1221 percepts.add(new Percept(Team.BLUE, FlagState.valueOfIgnoreCase(game.getFlag(Team.BLUE.id()).getState())));
1222
1223 return percepts;
1224 }
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262 @AsPercept(name = "item", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1263 public Collection<Percept> item() {
1264 Collection<Item> visibleItems = items.getVisibleItems().values();
1265 Collection<Percept> percepts = new ArrayList<Percept>(visibleItems.size());
1266
1267 for (Item item : visibleItems) {
1268 if (item.isDropped()) {
1269 percepts.add(new Percept(item.getId(), item.getType().getCategory(), item.getType(), item.getLocation()));
1270 } else {
1271 percepts.add(new Percept(item.getId(), item.getType().getCategory(), item.getType(), item
1272 .getNavPointId()));
1273 }
1274 }
1275
1276 return percepts;
1277 }
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309 @AsPercept(name = "flag", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1310 public Collection<Percept> flag() {
1311 Collection<FlagInfo> flags = game.getAllCTFFlagsCollection();
1312 Collection<Percept> percepts = new ArrayList<Percept>(flags.size());
1313
1314 for (FlagInfo flag : flags) {
1315 if (flag.isVisible())
1316 percepts.add(new Percept(Team.valueOf(flag.getTeam()), flag.getHolder(), flag.getLocation()));
1317 }
1318
1319 return percepts;
1320 }
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345 @AsPercept(name = "bot", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1346 public Collection<Percept> bot() {
1347 Collection<Player> visible = players.getVisiblePlayers().values();
1348 Collection<Percept> wrapped = new ArrayList<Percept>(visible.size());
1349
1350 for (Player p : visible) {
1351 wrapped.add(new Percept(p.getId(), p.getName(), Team.valueOf(p.getTeam()), ItemType.getItemType(p
1352 .getWeapon()), FireMode.valueOf(p.getFiring())));
1353 }
1354
1355 return wrapped;
1356 }
1357 }