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.concurrent.ConcurrentLinkedQueue;
30
31 import nl.tudelft.goal.unreal.messages.BotParameters;
32 import nl.tudelft.goal.unreal.messages.Parameters;
33 import nl.tudelft.goal.unreal.util.Selector;
34 import nl.tudelft.goal.ut2004.messages.Action;
35 import nl.tudelft.goal.ut2004.messages.Combo;
36 import nl.tudelft.goal.ut2004.messages.FireMode;
37 import nl.tudelft.goal.ut2004.messages.FlagState;
38 import nl.tudelft.goal.ut2004.messages.None;
39 import nl.tudelft.goal.ut2004.messages.Percept;
40 import nl.tudelft.goal.ut2004.messages.SelectorList;
41 import nl.tudelft.goal.ut2004.messages.UnrealIdOrLocation;
42 import nl.tudelft.goal.ut2004.messages.WeaponPrefList;
43 import nl.tudelft.goal.ut2004.selector.ContextSelector;
44 import nl.tudelft.goal.ut2004.selector.NearestEnemy;
45 import nl.tudelft.goal.ut2004.util.Team;
46 import nl.tudelft.pogamut.ut2004.agent.module.sensor.Projectiles;
47 import nl.tudelft.pogamut.ut2004.agent.module.shooting.WeaponryShooting;
48 import nl.tudelft.pogamut.ut2004.agent.module.shooting.util.FocusProvider;
49 import nl.tudelft.pogamut.ut2004.agent.module.shooting.util.OrderedFocusProvider;
50 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.AssaultRifleShooting;
51 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.BioRifleShooting;
52 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.FlakCannonShooting;
53 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.LigthningGunShooting;
54 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.LinkGunShooting;
55 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.MinigunShooting;
56 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.RocketLauncherShooting;
57 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.ShieldGunShooting;
58 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.ShockRifleShooting;
59 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.SniperRifleShooting;
60 import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.EventListener;
61 import cz.cuni.amis.pogamut.base.communication.worldview.object.IWorldObject;
62 import cz.cuni.amis.pogamut.base.utils.logging.IAgentLogger;
63 import cz.cuni.amis.pogamut.base.utils.math.DistanceUtils;
64 import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
65 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
66 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
67 import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Weapon;
68 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.WeaponPref;
69 import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004DistanceStuckDetector;
70 import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004PositionStuckDetector;
71 import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004TimeStuckDetector;
72 import cz.cuni.amis.pogamut.ut2004.agent.params.UT2004AgentParameters;
73 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
74 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotModuleController;
75 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType;
76 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.AddInventory;
77 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Initialize;
78 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.BotKilled;
79 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.FlagInfo;
80 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Item;
81 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
82 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
83 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PlayerKilled;
84 import cz.cuni.amis.pogamut.ut2004.utils.UT2004BotRunner;
85 import cz.cuni.amis.utils.exception.PogamutException;
86 import eis.eis2java.annotation.AsAction;
87 import eis.eis2java.annotation.AsPercept;
88 import eis.eis2java.translation.Filter.Type;
89 import eis.eis2java.util.AllPerceptsModule;
90 import eis.eis2java.util.AllPerceptsProvider;
91 import eis.exceptions.EntityException;
92 import eis.exceptions.PerceiveException;
93
94 @SuppressWarnings("rawtypes")
95 public class UT2004BotBehavior extends UT2004BotModuleController<UT2004Bot> implements AllPerceptsProvider {
96
97 protected List<ContextSelector> targetSelector = new ArrayList<ContextSelector>();
98 protected List<ContextSelector> lookSelector = new ArrayList<ContextSelector>();
99 protected Projectiles projectiles;
100 protected WeaponryShooting weaponShooting;
101 protected FocusProvider lookFocus = new FocusProvider();
102 protected OrderedFocusProvider focus = new OrderedFocusProvider();
103 protected long logicIteration;
104 protected AllPerceptsModule percepts;
105
106
107
108 protected BotParameters parameters;
109
110
111
112
113 private ConcurrentLinkedQueue<Action> actions = new ConcurrentLinkedQueue<Action>();
114
115 @Override
116 public void initializeController(UT2004Bot bot) {
117 super.initializeController(bot);
118
119
120 IAgentLogger logger = bot.getLogger();
121 UT2004AgentParameters parameters = bot.getParams();
122 if ((parameters instanceof BotParameters)) {
123 this.parameters = (BotParameters) parameters;
124 } else {
125 log.warning("Provided parameters were not a subclass of UnrealGoalParameters, using defaults.");
126 this.parameters = new BotParameters(logger);
127 }
128 Parameters defaults = BotParameters.getDefaults(logger);
129 this.parameters.assignDefaults(defaults);
130
131 }
132
133
134
135
136 protected void initializeModules(UT2004Bot bot) {
137 super.initializeModules(bot);
138
139 projectiles = new Projectiles(bot, info);
140 weaponShooting = new WeaponryShooting(bot, info, weaponry, weaponPrefs, shoot);
141
142
143 try {
144 percepts = new AllPerceptsModule(this);
145 } catch (EntityException e) {
146 throw new PogamutException("Could not create percept module", e);
147 }
148
149 initializeWeaponShootings();
150 }
151
152
153
154
155 protected void initializeWeaponShootings() {
156 weaponShooting.addWeaponShooting(new LinkGunShooting(bot, info, shoot, weaponry));
157 weaponShooting.addWeaponShooting(new ShockRifleShooting(bot, info, shoot, weaponry, projectiles));
158 weaponShooting.addWeaponShooting(new MinigunShooting(bot, info, shoot, weaponry));
159 weaponShooting.addWeaponShooting(new FlakCannonShooting(bot, info, shoot, weaponry));
160 weaponShooting.addWeaponShooting(new ShieldGunShooting(bot, info, shoot, weaponry, projectiles, senses));
161 weaponShooting.addWeaponShooting(new BioRifleShooting(bot, info, shoot, weaponry));
162 weaponShooting.addWeaponShooting(new AssaultRifleShooting(bot, info, shoot, weaponry));
163 weaponShooting.addWeaponShooting(new RocketLauncherShooting(bot, info, shoot, weaponry));
164 weaponShooting.addWeaponShooting(new LigthningGunShooting(bot, info, shoot, weaponry));
165 weaponShooting.addWeaponShooting(new SniperRifleShooting(bot, info, shoot, weaponry));
166 }
167
168
169
170
171
172 @Override
173 public void finishControllerInitialization() {
174 super.finishControllerInitialization();
175
176
177
178
179 focus.add(weaponShooting.getFocus());
180 focus.add(lookFocus);
181 navigation.setFocus(focus);
182 }
183
184
185
186
187
188
189 @Override
190 public Initialize getInitializeCommand() {
191 assert parameters != null;
192
193
194 Initialize init = super.getInitializeCommand();
195 init.setDesiredSkill(parameters.getSkill());
196 init.setSkin(parameters.getSkin().getUnrealName());
197 init.setTeam(parameters.getTeam());
198 init.setShouldLeadTarget(parameters.shouldLeadTarget());
199
200 init.setLocation(parameters.getInitialLocation());
201 init.setRotation(parameters.getInitialRotation());
202
203
204
205 return init;
206
207 }
208
209
210
211
212
213
214 @Override
215 public void beforeFirstLogic() {
216 targetSelector.add(new NearestEnemy().setContext(this));
217 lookSelector.add(new NearestEnemy().setContext(this));
218
219 weaponPrefs.addGeneralPref(ItemType.SHOCK_RIFLE, false);
220 weaponPrefs.addGeneralPref(ItemType.ROCKET_LAUNCHER, true);
221 weaponPrefs.addGeneralPref(ItemType.FLAK_CANNON, true);
222 weaponPrefs.addGeneralPref(ItemType.SNIPER_RIFLE, true);
223 weaponPrefs.addGeneralPref(ItemType.LIGHTNING_GUN, true);
224 weaponPrefs.addGeneralPref(ItemType.MINIGUN, true);
225 weaponPrefs.addGeneralPref(ItemType.LINK_GUN, true);
226 weaponPrefs.addGeneralPref(ItemType.BIO_RIFLE, false);
227 weaponPrefs.addGeneralPref(ItemType.ASSAULT_RIFLE, true);
228 weaponPrefs.addGeneralPref(ItemType.ASSAULT_RIFLE, false);
229 weaponPrefs.addGeneralPref(ItemType.SHIELD_GUN, false);
230 weaponPrefs.addGeneralPref(ItemType.SHIELD_GUN, true);
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 @Override
262 public void logic() {
263 super.logic();
264
265
266 while (!actions.isEmpty()) {
267 actions.remove().execute();
268 }
269
270
271
272 ILocated shootSelected = null;
273 for (Selector<ILocated> selector : targetSelector) {
274 shootSelected = selector.select(players.getVisiblePlayers().values());
275 if (shootSelected != null) {
276 break;
277 }
278 }
279 weaponShooting.shoot(shootSelected);
280
281
282
283 ILocated lookSelected = null;
284 for (Selector<ILocated> selector : lookSelector) {
285 lookSelected = selector.select(players.getVisiblePlayers().values());
286 if (lookSelected != null) {
287 break;
288 }
289 }
290 lookFocus.setFocus(lookSelected);
291
292
293 if (!navigation.isNavigating()) {
294
295 if (focus.getLocation() != null) {
296 move.turnTo(focus.getLocation());
297 }
298
299 else {
300 move.turnHorizontal(30);
301 }
302 }
303
304 logicIteration++;
305
306
307 try {
308 percepts.updatePercepts();
309 } catch (PerceiveException e) {
310 throw new PogamutException("Could not update percepts", e);
311 }
312
313 }
314
315
316
317
318
319
320
321 public void addAction(Action action) {
322 actions.add(action);
323 }
324
325
326
327
328
329
330 public Map<Method, Object> getAllPercepts() {
331 return percepts.getAllPercepts();
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 @AsAction(name = "navigate")
358 public void navigate(final UnrealIdOrLocation destination) {
359 log.info(String.format("navigate to %s called", destination));
360
361 addAction(new Action() {
362
363 @Override
364 public void execute() {
365 if (destination.isLocation()) {
366 log.info(String.format("navigate to %s executed", destination.getLocation()));
367 navigation.navigate(destination.getLocation());
368 return;
369 }
370
371 UnrealId id = destination.getId();
372
373 IWorldObject object = world.get(id);
374
375 if (object instanceof ILocated) {
376 navigation.navigate((ILocated) object);
377 log.info(String.format("navigate to %s executed", object));
378 return;
379 }
380
381 log.warning(String.format("failed to navigate to %s. Halting.", object));
382 navigation.stopNavigation();
383
384 }
385 });
386 }
387
388 @AsAction(name = "continue")
389 public void continueAction(final UnrealIdOrLocation destination) {
390 log.info(String.format("continue to %s called", destination));
391
392 addAction(new Action() {
393
394 @Override
395 public void execute() {
396 if (destination.isLocation()) {
397 log.info(String.format("continue to %s executed", destination.getLocation()));
398 navigation.setContinueTo(destination.getLocation());
399 return;
400 }
401
402 UnrealId id = destination.getId();
403
404 IWorldObject object = world.get(id);
405
406 if (object instanceof ILocated) {
407 navigation.setContinueTo((ILocated) object);
408 log.info(String.format("continue to %s executed", object));
409 return;
410 }
411
412 log.warning(String.format("failed to continue to %s. Halting.", object));
413 navigation.stopNavigation();
414
415 }
416 });
417 }
418
419
420
421
422
423
424 @AsAction(name = "stop")
425 public void stop() {
426 log.info("stop called");
427
428 addAction(new Action() {
429 @Override
430 public void execute() {
431 log.info("stop executed");
432 navigation.stopNavigation();
433 }
434 });
435 }
436
437
438
439
440
441
442
443
444
445 @AsAction(name = "respawn")
446 public void respawn() {
447 log.info("respawn called");
448 addAction(new Action() {
449 @Override
450 public void execute() {
451 log.info("respawn executed");
452 bot.respawn();
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 @AsAction(name = "combo")
486 public void combo(final Combo combo) {
487 log.info("combo %s called", combo);
488
489 addAction(new Action() {
490 @Override
491 public void execute() {
492
493 if (info.isAdrenalineSufficient()) {
494 log.info("combo %s executed", combo);
495 body.getAction().startCombo(combo.toString());
496 } else {
497 log.warning("combo %s failed, insufficient adrenaline", combo);
498 }
499
500 }
501 });
502 }
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521 @AsAction(name = "dropWeapon")
522 public void dropWeapon() {
523 log.info("drop called");
524
525 addAction(new Action() {
526 @Override
527 public void execute() {
528 Weapon weapon = weaponry.getCurrentWeapon();
529
530 body.getAction().throwWeapon();
531
532 if (weapon == null) {
533 log.warning(String.format("Could not drop weapon. Not holding a weapon."));
534 } else if (weapon.getType() == ItemType.SHIELD_GUN || weapon.getType() == ItemType.TRANSLOCATOR) {
535 log.warning(String.format("Could not drop weapon %s", weapon));
536 } else {
537 log.info("drop %s executed", weapon);
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 @AsAction(name = "path")
575 public Percept path(NavPoint from, NavPoint to) {
576
577 log.info(String.format("path from %s to %s executed", from, to));
578
579 double distance = fwMap.getDistance(from, to);
580 List<NavPoint> navPoints = fwMap.getPath(from, to);
581 List<UnrealId> unrealIds = new ArrayList<UnrealId>(navPoints.size());
582 for (NavPoint n : navPoints) {
583 unrealIds.add(n.getId());
584 }
585 return new Percept(distance, unrealIds);
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 @AsAction(name = "shoot")
619 public void shoot(final SelectorList targets) {
620 log.info(String.format("target %s called", targets));
621
622 addAction(new Action() {
623
624 @Override
625 public void execute() {
626 log.info(String.format("target %s executed", targetSelector));
627
628 targetSelector = targets.setContext(UT2004BotBehavior.this);
629 }
630 });
631
632 }
633
634
635
636
637
638
639
640
641
642
643
644
645
646 public void stopShooting() {
647 shoot(new SelectorList());
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 @AsAction(name = "prefer")
687 public void prefer(final WeaponPrefList weaponList) {
688 log.info(String.format("prefer %s called", weaponList));
689
690 addAction(new Action() {
691
692 @Override
693 public void execute() {
694 weaponPrefs.clearAllPrefs();
695
696 for (WeaponPref pref : weaponList) {
697 weaponPrefs.addGeneralPref(pref.getWeapon(), pref.isPrimary());
698 }
699
700 log.info(String.format("prefer %s executed", weaponList));
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 @AsAction(name = "look")
736 public void look(final SelectorList targets) {
737 log.info(String.format("look %s called", targets));
738
739 addAction(new Action() {
740
741 @Override
742 public void execute() {
743 log.info(String.format("look %s executed", targets));
744
745 lookSelector = targets.setContext(UT2004BotBehavior.this);
746 }
747 });
748 }
749
750
751
752
753
754
755
756
757
758
759 @AsAction(name = "skip")
760 public void skip() {
761
762 }
763
764
765
766
767
768
769
770
771
772
773 @AsAction(name = "cheatAdrenaline")
774 public void cheatAdrenaline() {
775 getAct().act(new AddInventory().setType(ItemType.ADRENALINE_PACK.getName()));
776 }
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798 @AsPercept(name = "self", filter = Type.ON_CHANGE)
799 public Percept self() {
800 return new Percept(info.getId(), info.getName(), Team.valueOf(info.getTeam()));
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 @AsPercept(name = "logic", filter = Type.ON_CHANGE)
827 public Percept logicIteration() {
828 return new Percept(logicIteration);
829 }
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849 @AsPercept(name = "orientation", filter = Type.ON_CHANGE)
850 public Percept orientation() {
851 return new Percept(info.getLocation(), info.getRotation(), info.getVelocity());
852 }
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874 @AsPercept(name = "status", filter = Type.ON_CHANGE)
875 public Percept status() {
876 return new Percept(info.getHealth(), info.getArmor(), info.getAdrenaline(), Combo.parseCombo(info.getSelf().getCombo()));
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 @AsPercept(name = "score", filter = Type.ON_CHANGE)
905 public Percept score() {
906 return new Percept(info.getKills(), info.getDeaths(), info.getSuicides());
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 = "currentWeapon", filter = Type.ON_CHANGE)
931 public Percept currentWeapon() {
932 final Weapon weapon = weaponry.getCurrentWeapon();
933
934 if (weapon == null) {
935 return new Percept(new None(), FireMode.NONE);
936 }
937
938 return new Percept(weapon.getType(), FireMode.valueOf(info.isPrimaryShooting(), info.isSecondaryShooting()));
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 @AsPercept(name = "weapon", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
969 public Collection<Percept> weapon() {
970 Collection<Weapon> weapons = weaponry.getWeapons().values();
971 Collection<Percept> percepts = new ArrayList<Percept>(weapons.size());
972
973 for (Weapon w : weapons) {
974 if (w.getType() == ItemType.SHIELD_GUN) {
975
976
977
978 percepts.add(new Percept(w.getType(), 1, w.getSecondaryAmmo()));
979 } else {
980 percepts.add(new Percept(w.getType(), w.getPrimaryAmmo(), w.getSecondaryAmmo()));
981 }
982 }
983
984 return percepts;
985 }
986
987
988
989
990 private List<Percept> fragged = new LinkedList<Percept>();
991
992
993
994
995
996
997
998
999
1000 private void fraggedEvent(final double time, final UnrealId killer, final UnrealId victem, final String weaponName) {
1001 fragged.add(new Percept(time, killer, victem, ItemType.getItemType(weaponName)));
1002 }
1003
1004
1005
1006
1007
1008
1009 @EventListener(eventClass = BotKilled.class)
1010 public void msgBotKilled(BotKilled msg) {
1011 fraggedEvent(msg.getSimTime(), msg.getKiller(), info.getId(), msg.getWeaponName());
1012 }
1013
1014
1015
1016
1017
1018
1019
1020 @EventListener(eventClass = PlayerKilled.class)
1021 public void msgPlayerKilled(PlayerKilled msg) {
1022 fraggedEvent(msg.getSimTime(), msg.getKiller(), msg.getId(), msg.getWeaponName());
1023 }
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046 @AsPercept(name = "fragged", multiplePercepts = true, filter = Type.ALWAYS, event = true)
1047 public List<Percept> fragged() {
1048 ArrayList<Percept> percepts = new ArrayList<Percept>(fragged);
1049 fragged.clear();
1050 return percepts;
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 @AsPercept(name = "navigation", filter = Type.ON_CHANGE)
1079 public Percept navigation() {
1080 ILocated currentTarget = navigation.getCurrentTarget();
1081
1082
1083 if (currentTarget == null) {
1084 return new Percept(navigation.getState().getFlag(), new None());
1085 }
1086
1087
1088 if (currentTarget instanceof IWorldObject) {
1089 IWorldObject targetObject = (IWorldObject) navigation.getCurrentTarget();
1090 return new Percept(navigation.getState().getFlag(), targetObject.getId());
1091 }
1092
1093
1094 return new Percept(navigation.getState().getFlag(), currentTarget.getLocation());
1095 }
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118 @AsPercept(name = "navPoint", multiplePercepts = true, filter = Type.ONCE)
1119 public Collection<Percept> navPoint() {
1120 Collection<NavPoint> navPoints = world.getAll(NavPoint.class).values();
1121 List<Percept> percepts = new ArrayList<Percept>(navPoints.size());
1122
1123 for (NavPoint p : navPoints) {
1124 percepts.add(new Percept(p.getId(), p.getLocation(), p.getOutgoingEdges().keySet()));
1125 }
1126
1127 return percepts;
1128 }
1129
1130 @AsPercept(name = "navPoint", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1131 public Collection<Percept> visibleNavPoint() {
1132 Collection<NavPoint> navPoints = world.getAll(NavPoint.class).values();
1133 List<Percept> percepts = new ArrayList<Percept>(navPoints.size());
1134
1135 for (NavPoint p : navPoints) {
1136 if (p.isVisible()) {
1137 percepts.add(new Percept(p.getId(), p.getLocation(), p.getOutgoingEdges().keySet()));
1138 }
1139 }
1140
1141 return percepts;
1142 }
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177 @AsPercept(name = "pickup", multiplePercepts = true, filter = Type.ONCE)
1178 public Collection<Percept> pickup() {
1179 Collection<Item> pickups = items.getKnownPickups().values();
1180 Collection<Percept> percepts = new ArrayList<Percept>(pickups.size());
1181
1182 for (Item item : pickups) {
1183 if (!item.isDropped()) {
1184 percepts.add(new Percept(item.getNavPoint().getId(), item.getType().getCategory(), item.getType()));
1185 }
1186 }
1187 return percepts;
1188 }
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209 @AsPercept(name = "base", multiplePercepts = true, filter = Type.ONCE)
1210 public List<Percept> base() {
1211 List<Percept> base = new ArrayList<Percept>(2);
1212
1213 Collection<NavPoint> navPoints = world.getAll(NavPoint.class).values();
1214
1215 NavPoint nav = DistanceUtils.getNearest(navPoints, game.getFlagBase(0));
1216 assert nav != null;
1217 base.add(new Percept(Team.RED, nav.getId()));
1218
1219 nav = DistanceUtils.getNearest(navPoints, game.getFlagBase(1));
1220 assert nav != null;
1221 base.add(new Percept(Team.BLUE, nav.getId()));
1222
1223 return base;
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 @AsPercept(name = "game", filter = Type.ON_CHANGE)
1250 public Percept game() {
1251 return new Percept(game.getGameType(), game.getMapName(), game.getTeamScoreLimit(), game.getRemainingTime());
1252 }
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281 @AsPercept(name = "score", filter = Type.ON_CHANGE)
1282 public Percept teamScore() {
1283 return new Percept(game.getTeamScore(info.getTeam()), game.getTeamScore(1 - info.getTeam()));
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
1310
1311
1312
1313 @AsPercept(name = "flagState", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1314 public List<Percept> flagState() {
1315 List<Percept> percepts = new ArrayList<Percept>(2);
1316
1317 percepts.add(new Percept(Team.RED, FlagState.valueOfIgnoreCase(game.getFlag(Team.RED.id()).getState())));
1318 percepts.add(new Percept(Team.BLUE, FlagState.valueOfIgnoreCase(game.getFlag(Team.BLUE.id()).getState())));
1319
1320 return percepts;
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
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359 @AsPercept(name = "item", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1360 public Collection<Percept> item() {
1361 Collection<Item> visibleItems = items.getVisibleItems().values();
1362 Collection<Percept> percepts = new ArrayList<Percept>(visibleItems.size());
1363
1364 for (Item item : visibleItems) {
1365 if (item.isDropped()) {
1366 percepts.add(new Percept(item.getId(), item.getType().getCategory(), item.getType(), item.getLocation()));
1367 } else {
1368 percepts.add(new Percept(item.getId(), item.getType().getCategory(), item.getType(), item.getNavPointId()));
1369 }
1370 }
1371
1372 return percepts;
1373 }
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405 @AsPercept(name = "flag", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1406 public Collection<Percept> flag() {
1407 Collection<FlagInfo> flags = game.getAllCTFFlagsCollection();
1408 Collection<Percept> percepts = new ArrayList<Percept>(flags.size());
1409
1410 for (FlagInfo flag : flags) {
1411 if (flag.isVisible())
1412 percepts.add(new Percept(Team.valueOf(flag.getTeam()), flag.getHolder(), flag.getLocation()));
1413 }
1414
1415 return percepts;
1416 }
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442 @AsPercept(name = "bot", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1443 public Collection<Percept> bot() {
1444 Collection<Player> visible = players.getVisiblePlayers().values();
1445 Collection<Percept> wrapped = new ArrayList<Percept>(visible.size());
1446
1447 for (Player p : visible) {
1448 wrapped.add(new Percept(p.getId(), p.getName(), Team.valueOf(p.getTeam()), p.getLocation(),
1449 ItemType.getItemType(p.getWeapon()), FireMode.valueOf(p.getFiring())));
1450 }
1451
1452 return wrapped;
1453 }
1454 }