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.lang.reflect.Method;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.LinkedList;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Set;
30 import java.util.concurrent.ConcurrentLinkedQueue;
31
32 import nl.tudelft.goal.EIS2Java.annotation.AsAction;
33 import nl.tudelft.goal.EIS2Java.annotation.AsAllPercepts;
34 import nl.tudelft.goal.EIS2Java.annotation.AsPercept;
35 import nl.tudelft.goal.EIS2Java.translation.Filter.Type;
36 import nl.tudelft.goal.unreal.messages.BotParameters;
37 import nl.tudelft.goal.unreal.messages.Parameters;
38 import nl.tudelft.goal.unreal.messages.Team;
39 import nl.tudelft.goal.unreal.util.Selector;
40 import nl.tudelft.goal.ut2004.agent.module.PerceptModule;
41 import nl.tudelft.goal.ut2004.messages.Action;
42 import nl.tudelft.goal.ut2004.messages.Combo;
43 import nl.tudelft.goal.ut2004.messages.FireMode;
44 import nl.tudelft.goal.ut2004.messages.FlagState;
45 import nl.tudelft.goal.ut2004.messages.None;
46 import nl.tudelft.goal.ut2004.messages.Percept;
47 import nl.tudelft.goal.ut2004.messages.SelectorList;
48 import nl.tudelft.goal.ut2004.messages.UnrealIdOrLocation;
49 import nl.tudelft.goal.ut2004.messages.WeaponPrefList;
50 import nl.tudelft.goal.ut2004.selector.NearestEnemy;
51 import nl.tudelft.goal.ut2004.selector.ContextSelector;
52 import nl.tudelft.pogamut.ut2004.agent.module.sensor.Projectiles;
53 import nl.tudelft.pogamut.ut2004.agent.module.shooting.WeaponryShooting;
54 import nl.tudelft.pogamut.ut2004.agent.module.shooting.util.FocusProvider;
55 import nl.tudelft.pogamut.ut2004.agent.module.shooting.util.OrderedFocusProvider;
56 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.AssaultRifleShooting;
57 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.BioRifleShooting;
58 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.FlakCannonShooting;
59 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.LigthningGunShooting;
60 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.LinkGunShooting;
61 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.MinigunShooting;
62 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.RocketLauncherShooting;
63 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.ShieldGunShooting;
64 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.ShockRifleShooting;
65 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.SniperRifleShooting;
66 import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.EventListener;
67 import cz.cuni.amis.pogamut.base.communication.worldview.object.IWorldObject;
68 import cz.cuni.amis.pogamut.base.utils.logging.IAgentLogger;
69 import cz.cuni.amis.pogamut.base.utils.math.DistanceUtils;
70 import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
71 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
72 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
73 import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Weapon;
74 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.WeaponPref;
75 import cz.cuni.amis.pogamut.ut2004.agent.navigation.NavigationState;
76 import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004DistanceStuckDetector;
77 import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004PositionStuckDetector;
78 import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004TimeStuckDetector;
79 import cz.cuni.amis.pogamut.ut2004.agent.params.UT2004AgentParameters;
80 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
81 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotModuleController;
82 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType;
83 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.AddInventory;
84 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Initialize;
85 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.BotKilled;
86 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.FlagInfo;
87 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Item;
88 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
89 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
90 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PlayerKilled;
91 import cz.cuni.amis.pogamut.ut2004.utils.UT2004BotRunner;
92 import eis.iilang.Identifier;
93 import eis.iilang.ParameterList;
94
95 @SuppressWarnings("rawtypes")
96 public class UT2004BotBehavior extends UT2004BotModuleController<UT2004Bot> {
97
98 protected List<ContextSelector> targetSelector = new ArrayList<ContextSelector>();
99 protected List<ContextSelector> lookSelector = new ArrayList<ContextSelector>();
100 protected Projectiles projectiles;
101 protected WeaponryShooting weaponShooting;
102 protected FocusProvider lookFocus = new FocusProvider();
103 protected OrderedFocusProvider focus = new OrderedFocusProvider();
104 protected long logicIteration;
105 protected PerceptModule percepts;
106
107
108
109 protected BotParameters parameters;
110
111
112
113
114 private ConcurrentLinkedQueue<Action> actions = new ConcurrentLinkedQueue<Action>();
115
116 @Override
117 public void initializeController(UT2004Bot bot) {
118 super.initializeController(bot);
119
120
121 IAgentLogger logger = bot.getLogger();
122 UT2004AgentParameters parameters = bot.getParams();
123 if ((parameters instanceof BotParameters)) {
124 this.parameters = (BotParameters) parameters;
125 } else {
126 log.warning("Provided parameters were not a subclass of UnrealGoalParameters, using defaults.");
127 this.parameters = new BotParameters(logger);
128 }
129 Parameters defaults = BotParameters.getDefaults(logger);
130 this.parameters.assignDefaults(defaults);
131
132 }
133
134
135
136
137 protected void initializeModules(UT2004Bot bot) {
138 super.initializeModules(bot);
139
140 projectiles = new Projectiles(bot, info);
141 weaponShooting = new WeaponryShooting(bot, info, weaponry, weaponPrefs, shoot);
142
143
144 percepts = new PerceptModule(bot);
145
146 initializeWeaponShootings();
147 }
148
149
150
151
152 protected void initializeWeaponShootings() {
153 weaponShooting.addWeaponShooting(new LinkGunShooting(bot, info, shoot, weaponry));
154 weaponShooting.addWeaponShooting(new ShockRifleShooting(bot, info, shoot, weaponry, projectiles));
155 weaponShooting.addWeaponShooting(new MinigunShooting(bot, info, shoot, weaponry));
156 weaponShooting.addWeaponShooting(new FlakCannonShooting(bot, info, shoot, weaponry));
157 weaponShooting.addWeaponShooting(new ShieldGunShooting(bot, info, shoot, weaponry, projectiles, senses));
158 weaponShooting.addWeaponShooting(new BioRifleShooting(bot, info, shoot, weaponry));
159 weaponShooting.addWeaponShooting(new AssaultRifleShooting(bot, info, shoot, weaponry));
160 weaponShooting.addWeaponShooting(new RocketLauncherShooting(bot, info, shoot, weaponry));
161 weaponShooting.addWeaponShooting(new LigthningGunShooting(bot, info, shoot, weaponry));
162 weaponShooting.addWeaponShooting(new SniperRifleShooting(bot, info, shoot, weaponry));
163 }
164
165
166
167
168
169 @Override
170 public void finishControllerInitialization() {
171 super.finishControllerInitialization();
172
173
174
175
176 focus.add(weaponShooting.getFocus());
177 focus.add(lookFocus);
178 navigation.setFocus(focus);
179 }
180
181
182
183
184
185
186 @Override
187 public Initialize getInitializeCommand() {
188 assert parameters != null;
189
190
191 Initialize init = super.getInitializeCommand();
192 init.setDesiredSkill(parameters.getSkill());
193 init.setSkin(parameters.getSkin().getUnrealName());
194 init.setTeam(parameters.getTeam());
195 init.setShouldLeadTarget(parameters.shouldLeadTarget());
196 init.setLocation(parameters.getStartLocation());
197 init.setRotation(parameters.getStartRotation());
198
199
200
201
202 return init;
203
204 }
205
206
207
208
209
210
211 @Override
212 public void beforeFirstLogic() {
213 targetSelector.add(new NearestEnemy().setContext(this));
214 lookSelector.add(new NearestEnemy().setContext(this));
215
216 weaponPrefs.addGeneralPref(ItemType.SHOCK_RIFLE, false);
217 weaponPrefs.addGeneralPref(ItemType.ROCKET_LAUNCHER, true);
218 weaponPrefs.addGeneralPref(ItemType.FLAK_CANNON, true);
219 weaponPrefs.addGeneralPref(ItemType.SNIPER_RIFLE, true);
220 weaponPrefs.addGeneralPref(ItemType.LIGHTNING_GUN, true);
221 weaponPrefs.addGeneralPref(ItemType.MINIGUN, true);
222 weaponPrefs.addGeneralPref(ItemType.LINK_GUN, true);
223 weaponPrefs.addGeneralPref(ItemType.BIO_RIFLE, false);
224 weaponPrefs.addGeneralPref(ItemType.ASSAULT_RIFLE, true);
225 weaponPrefs.addGeneralPref(ItemType.ASSAULT_RIFLE, false);
226 weaponPrefs.addGeneralPref(ItemType.SHIELD_GUN, false);
227 weaponPrefs.addGeneralPref(ItemType.SHIELD_GUN, true);
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 @Override
259 public void logic() {
260 super.logic();
261
262
263 while (!actions.isEmpty()) {
264 actions.remove().execute();
265 }
266
267
268
269 ILocated shootSelected = null;
270 for (Selector<ILocated> selector : targetSelector) {
271 shootSelected = selector.select(players.getVisiblePlayers().values());
272 if (shootSelected != null) {
273 break;
274 }
275 }
276 weaponShooting.shoot(shootSelected);
277
278
279
280 ILocated lookSelected = null;
281 for (Selector<ILocated> selector : lookSelector) {
282 lookSelected = selector.select(players.getVisiblePlayers().values());
283 if (lookSelected != null) {
284 break;
285 }
286 }
287 lookFocus.setFocus(lookSelected);
288
289
290 if (!navigation.isNavigating()) {
291
292 if (focus.getLocation() != null) {
293 move.turnTo(focus.getLocation());
294 }
295
296 else {
297 move.turnHorizontal(30);
298 }
299 }
300
301 logicIteration++;
302
303
304 percepts.updatePercepts();
305
306 }
307
308
309
310
311
312
313
314 public void addAction(Action action) {
315 actions.add(action);
316 }
317
318
319
320
321
322
323 @AsAllPercepts
324 public Map<Method, Object> getAllPercepts() {
325 return percepts.getAllPercepts();
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 @AsAction(name = "navigate")
352 public void navigate(final UnrealIdOrLocation destination) {
353 log.info(String.format("navigate to %s called", destination));
354
355 addAction(new Action() {
356
357 @Override
358 public void execute() {
359 if (destination.isLocation()) {
360 log.info(String.format("navigate to %s executed", destination.getLocation()));
361 navigation.navigate(destination.getLocation());
362 return;
363 }
364
365 UnrealId id = destination.getId();
366
367 IWorldObject object = world.get(id);
368
369 if (object instanceof ILocated) {
370 navigation.navigate((ILocated) object);
371 log.info(String.format("navigate to %s executed", object));
372 return;
373 }
374
375 log.warning(String.format("failed to navigate to %s. Halting.", object));
376 navigation.stopNavigation();
377
378 }
379 });
380 }
381
382 @AsAction(name = "continue")
383 public void continueAction(final UnrealIdOrLocation destination) {
384 log.info(String.format("continue to %s called", destination));
385
386 addAction(new Action() {
387
388 @Override
389 public void execute() {
390 if (destination.isLocation()) {
391 log.info(String.format("continue to %s executed", destination.getLocation()));
392 navigation.setContinueTo(destination.getLocation());
393 return;
394 }
395
396 UnrealId id = destination.getId();
397
398 IWorldObject object = world.get(id);
399
400 if (object instanceof ILocated) {
401 navigation.setContinueTo((ILocated) object);
402 log.info(String.format("continue to %s executed", object));
403 return;
404 }
405
406 log.warning(String.format("failed to navigate to %s. Halting.", object));
407 navigation.stopNavigation();
408
409 }
410 });
411 }
412
413
414
415
416
417
418 @AsAction(name = "stop")
419 public void stop() {
420 log.info("stop called");
421
422 addAction(new Action() {
423 @Override
424 public void execute() {
425 log.info("stop executed");
426 navigation.stopNavigation();
427 }
428 });
429 }
430
431
432
433
434
435
436
437
438
439 @AsAction(name = "respawn")
440 public void respawn() {
441 log.info("respawn called");
442 addAction(new Action() {
443 @Override
444 public void execute() {
445 log.info("respawn executed");
446 bot.respawn();
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 @AsAction(name = "combo")
480 public void combo(final Combo combo) {
481 log.info("combo %s called", combo);
482
483 addAction(new Action() {
484 @Override
485 public void execute() {
486
487 if (info.isAdrenalineSufficient()) {
488 log.info("combo %s executed", combo);
489 body.getAction().startCombo(combo.toString());
490 } else {
491 log.warning("combo %s failed, insufficient adrenaline", combo);
492 }
493
494 }
495 });
496 }
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515 @AsAction(name = "dropWeapon")
516 public void dropWeapon() {
517 log.info("drop called");
518
519 addAction(new Action() {
520 @Override
521 public void execute() {
522 Weapon weapon = weaponry.getCurrentWeapon();
523
524 body.getAction().throwWeapon();
525
526 if (weapon == null) {
527 log.warning(String.format("Could not drop weapon. Not holding a weapon."));
528 } else if (weapon.getType() == ItemType.SHIELD_GUN || weapon.getType() == ItemType.TRANSLOCATOR) {
529 log.warning(String.format("Could not drop weapon %s", weapon));
530 } else {
531 log.info("drop %s executed", weapon);
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 @AsAction(name = "path")
569 public Percept path(NavPoint from, NavPoint to) {
570
571 log.info(String.format("path from %s to %s executed", from, to));
572
573 double distance = fwMap.getDistance(from, to);
574 List<NavPoint> navPoints = fwMap.getPath(from, to);
575 List<UnrealId> unrealIds = new ArrayList<UnrealId>(navPoints.size());
576 for (NavPoint n : navPoints) {
577 unrealIds.add(n.getId());
578 }
579 return new Percept(distance, unrealIds);
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 @AsAction(name = "shoot")
613 public void shoot(final SelectorList targets) {
614 log.info(String.format("target %s called", targets));
615
616 addAction(new Action() {
617
618 @Override
619 public void execute() {
620 log.info(String.format("target %s executed", targetSelector));
621
622 targetSelector = targets.setContext(UT2004BotBehavior.this);
623 }
624 });
625
626 }
627
628
629
630
631
632
633
634
635
636
637
638
639
640 public void stopShooting() {
641 shoot(new SelectorList());
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 @AsAction(name = "prefer")
681 public void prefer(final WeaponPrefList weaponList) {
682 log.info(String.format("prefer %s called", weaponList));
683
684 addAction(new Action() {
685
686 @Override
687 public void execute() {
688 weaponPrefs.clearAllPrefs();
689
690 for (WeaponPref pref : weaponList) {
691 weaponPrefs.addGeneralPref(pref.getWeapon(), pref.isPrimary());
692 }
693
694 log.info(String.format("prefer %s executed", weaponList));
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 @AsAction(name = "look")
730 public void look(final SelectorList targets) {
731 log.info(String.format("look %s called", targets));
732
733 addAction(new Action() {
734
735 @Override
736 public void execute() {
737 log.info(String.format("look %s executed", targets));
738
739 lookSelector = targets.setContext(UT2004BotBehavior.this);
740 }
741 });
742 }
743
744
745
746
747
748
749
750
751
752
753 @AsAction(name = "skip")
754 public void skip() {
755
756 }
757
758
759
760
761
762
763
764
765
766
767
768 @AsAction(name = "cheatAdrenaline")
769 public void cheatAdrenaline() {
770 getAct().act(new AddInventory().setType(ItemType.ADRENALINE_PACK.getName()));
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 @AsPercept(name = "navigation", filter = Type.ON_CHANGE)
800 public Percept navigation() {
801
802 return new Percept(navigation.getState().getFlag(), navigation.getCurrentTarget(), navigation.getContinueTo());
803 }
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823 @AsPercept(name = "self", filter = Type.ON_CHANGE)
824 public Percept self() {
825 return new Percept(info.getId(), info.getName(), Team.valueOf(info.getTeam()));
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 @AsPercept(name = "logic", filter = Type.ON_CHANGE)
852 public Percept logicIteration() {
853 return new Percept(logicIteration);
854 }
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874 @AsPercept(name = "orientation", filter = Type.ON_CHANGE)
875 public Percept orientation() {
876 return new Percept(info.getLocation(), info.getRotation(), info.getVelocity());
877 }
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899 @AsPercept(name = "status", filter = Type.ON_CHANGE)
900 public Percept status() {
901 return new Percept(info.getHealth(), info.getArmor(), info.getAdrenaline(), Combo.parseCombo(info.getSelf()
902 .getCombo()));
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 @AsPercept(name = "score", filter = Type.ON_CHANGE)
931 public Percept score() {
932 return new Percept(info.getKills(), info.getDeaths(), info.getSuicides());
933 }
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956 @AsPercept(name = "currentWeapon", filter = Type.ON_CHANGE)
957 public Percept currentWeapon() {
958 final Weapon weapon = weaponry.getCurrentWeapon();
959
960 if (weapon == null) {
961 return new Percept(new None(), FireMode.NONE);
962 }
963
964 return new Percept(weapon.getType(), FireMode.valueOf(info.isPrimaryShooting(), info.isSecondaryShooting()));
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 @AsPercept(name = "weapon", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
995 public Collection<Percept> weapon() {
996 Collection<Weapon> weapons = weaponry.getWeapons().values();
997 Collection<Percept> percepts = new ArrayList<Percept>(weapons.size());
998
999 for (Weapon w : weapons) {
1000 if (w.getType() == ItemType.SHIELD_GUN) {
1001
1002
1003
1004 percepts.add(new Percept(w.getType(), 1, w.getSecondaryAmmo()));
1005 } else {
1006 percepts.add(new Percept(w.getType(), w.getPrimaryAmmo(), w.getSecondaryAmmo()));
1007 }
1008 }
1009
1010 return percepts;
1011 }
1012
1013
1014
1015
1016 private List<Percept> fragged = new LinkedList<Percept>();
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026 private void fraggedEvent(final double time, final UnrealId killer, final UnrealId victem, final String weaponName) {
1027 fragged.add(new Percept(time, killer, victem, ItemType.getItemType(weaponName)));
1028 }
1029
1030
1031
1032
1033
1034
1035 @EventListener(eventClass = BotKilled.class)
1036 public void msgBotKilled(BotKilled msg) {
1037 fraggedEvent(msg.getSimTime(), msg.getKiller(), info.getId(), msg.getWeaponName());
1038 }
1039
1040
1041
1042
1043
1044
1045
1046 @EventListener(eventClass = PlayerKilled.class)
1047 public void msgPlayerKilled(PlayerKilled msg) {
1048 fraggedEvent(msg.getSimTime(), msg.getKiller(), msg.getId(), msg.getWeaponName());
1049 }
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072 @AsPercept(name = "fragged", multiplePercepts = true, filter = Type.ALWAYS, event = true)
1073 public List<Percept> fragged() {
1074 ArrayList<Percept> percepts = new ArrayList<Percept>(fragged);
1075 fragged.clear();
1076 return percepts;
1077 }
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100 @AsPercept(name = "navPoint", multiplePercepts = true, filter = Type.ONCE)
1101 public Collection<Percept> navPoint() {
1102
1103 Collection<NavPoint> navPoints = world.getAll(NavPoint.class).values();
1104 List<Percept> percepts = new ArrayList<Percept>(navPoints.size());
1105
1106 for (NavPoint p : navPoints) {
1107 percepts.add(new Percept(p.getId(), p.getLocation(), p.getOutgoingEdges().keySet()));
1108 }
1109
1110 return percepts;
1111 }
1112
1113 @AsPercept(name = "navPoint", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1114 public Collection<Percept> visibleNavPoint() {
1115 Collection<NavPoint> navPoints = world.getAll(NavPoint.class).values();
1116 List<Percept> percepts = new ArrayList<Percept>(navPoints.size());
1117
1118 for (NavPoint p : navPoints) {
1119 if (p.isVisible()) {
1120 percepts.add(new Percept(p.getId(), p.getLocation(), p.getOutgoingEdges().keySet()));
1121 }
1122 }
1123
1124 return percepts;
1125 }
1126
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
1153
1154
1155
1156
1157
1158
1159
1160 @AsPercept(name = "pickup", multiplePercepts = true, filter = Type.ONCE)
1161 public Collection<Percept> pickup() {
1162 Collection<Item> pickups = items.getKnownPickups().values();
1163 Collection<Percept> percepts = new ArrayList<Percept>(pickups.size());
1164
1165 for (Item item : pickups) {
1166 if (!item.isDropped()) {
1167 percepts.add(new Percept(item.getNavPoint().getId(), item.getType().getCategory(), item.getType()));
1168 }
1169 }
1170 return percepts;
1171 }
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192 @AsPercept(name = "base", multiplePercepts = true, filter = Type.ONCE)
1193 public List<Percept> base() {
1194 List<Percept> base = new ArrayList<Percept>(2);
1195
1196 Collection<NavPoint> navPoints = world.getAll(NavPoint.class).values();
1197
1198 NavPoint nav = DistanceUtils.getNearest(navPoints, game.getFlagBase(0));
1199 assert nav != null;
1200 base.add(new Percept(Team.RED, nav.getId()));
1201
1202 nav = DistanceUtils.getNearest(navPoints, game.getFlagBase(1));
1203 assert nav != null;
1204 base.add(new Percept(Team.BLUE, nav.getId()));
1205
1206 return base;
1207 }
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232 @AsPercept(name = "game", filter = Type.ON_CHANGE)
1233 public Percept game() {
1234 return new Percept(game.getGameType(), game.getMapName(), game.getTeamScoreLimit(), game.getRemainingTime());
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
1263
1264 @AsPercept(name = "teamScore", filter = Type.ON_CHANGE)
1265 public Percept teamScore() {
1266 return new Percept(game.getTeamScore(info.getTeam()), game.getTeamScore(1 - info.getTeam()));
1267 }
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296 @AsPercept(name = "flagState", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1297 public List<Percept> flagState() {
1298 List<Percept> percepts = new ArrayList<Percept>(2);
1299
1300 percepts.add(new Percept(Team.RED, FlagState.valueOfIgnoreCase(game.getFlag(Team.RED.id()).getState())));
1301 percepts.add(new Percept(Team.BLUE, FlagState.valueOfIgnoreCase(game.getFlag(Team.BLUE.id()).getState())));
1302
1303 return percepts;
1304 }
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342 @AsPercept(name = "item", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1343 public Collection<Percept> item() {
1344 Collection<Item> visibleItems = items.getVisibleItems().values();
1345 Collection<Percept> percepts = new ArrayList<Percept>(visibleItems.size());
1346
1347 for (Item item : visibleItems) {
1348 if (item.isDropped()) {
1349 percepts.add(new Percept(item.getId(), item.getType().getCategory(), item.getType(), item.getLocation()));
1350 } else {
1351 percepts.add(new Percept(item.getId(), item.getType().getCategory(), item.getType(), item
1352 .getNavPointId()));
1353 }
1354 }
1355
1356 return percepts;
1357 }
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389 @AsPercept(name = "flag", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1390 public Collection<Percept> flag() {
1391 Collection<FlagInfo> flags = game.getAllCTFFlagsCollection();
1392 Collection<Percept> percepts = new ArrayList<Percept>(flags.size());
1393
1394 for (FlagInfo flag : flags) {
1395 if (flag.isVisible())
1396 percepts.add(new Percept(Team.valueOf(flag.getTeam()), flag.getHolder(), flag.getLocation()));
1397 }
1398
1399 return percepts;
1400 }
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426 @AsPercept(name = "bot", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1427 public Collection<Percept> bot() {
1428 Collection<Player> visible = players.getVisiblePlayers().values();
1429 Collection<Percept> wrapped = new ArrayList<Percept>(visible.size());
1430
1431 for (Player p : visible) {
1432 wrapped.add(new Percept(p.getId(), p.getName(), Team.valueOf(p.getTeam()), p.getLocation(), ItemType
1433 .getItemType(p.getWeapon()), FireMode.valueOf(p.getFiring())));
1434 }
1435
1436 return wrapped;
1437 }
1438 }