1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package nl.tudelft.goal.ut3.agent;
21
22 import java.lang.reflect.Method;
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.logging.Level;
29
30 import nl.tudelft.goal.unreal.actions.Action;
31 import nl.tudelft.goal.unreal.actions.ActionQueue;
32 import nl.tudelft.goal.unreal.floydwarshall.SharedFloydWarshallMap;
33 import nl.tudelft.goal.unreal.messages.BotParameters;
34 import nl.tudelft.goal.unreal.messages.None;
35 import nl.tudelft.goal.unreal.messages.Percept;
36 import nl.tudelft.goal.unreal.messages.UnrealIdOrLocation;
37 import nl.tudelft.goal.unreal.util.Selector;
38 import nl.tudelft.goal.ut2004.util.Team;
39 import nl.tudelft.goal.ut3.actions.Look;
40 import nl.tudelft.goal.ut3.actions.Navigate;
41 import nl.tudelft.goal.ut3.actions.Prefer;
42 import nl.tudelft.goal.ut3.actions.Respawn;
43 import nl.tudelft.goal.ut3.actions.Shoot;
44 import nl.tudelft.goal.ut3.actions.Stop;
45 import nl.tudelft.goal.ut3.messages.FireMode;
46 import nl.tudelft.goal.ut3.messages.FlagState;
47 import nl.tudelft.goal.ut3.messages.SelectorList;
48 import nl.tudelft.goal.ut3.messages.WeaponPrefList;
49 import nl.tudelft.goal.ut3.selector.ContextSelector;
50 import nl.tudelft.goal.ut3.selector.NearestEnemy;
51 import nl.tudelft.pogamut.unreal.agent.module.sensor.Projectiles;
52 import nl.tudelft.pogamut.unreal.agent.module.shooting.WeaponryShooting;
53 import nl.tudelft.pogamut.unreal.agent.module.shooting.util.FocusProvider;
54 import nl.tudelft.pogamut.unreal.agent.module.shooting.util.OrderedFocusProvider;
55 import nl.tudelft.pogamut.ut3.agent.module.sensor.UT3Projectiles;
56 import nl.tudelft.pogamut.ut3.agent.module.shooting.weapon.BioRifleShooting;
57 import nl.tudelft.pogamut.ut3.agent.module.shooting.weapon.EnforcerShooting;
58 import nl.tudelft.pogamut.ut3.agent.module.shooting.weapon.FlakCannonShooting;
59 import nl.tudelft.pogamut.ut3.agent.module.shooting.weapon.ImpactHammerShooting;
60 import nl.tudelft.pogamut.ut3.agent.module.shooting.weapon.LinkGunShooting;
61 import nl.tudelft.pogamut.ut3.agent.module.shooting.weapon.RocketLauncherShooting;
62 import nl.tudelft.pogamut.ut3.agent.module.shooting.weapon.ShockRifleShooting;
63 import nl.tudelft.pogamut.ut3.agent.module.shooting.weapon.SniperRifleShooting;
64 import nl.tudelft.pogamut.ut3.agent.module.shooting.weapon.StingerMinigunShooting;
65 import cz.cuni.amis.pogamut.base.agent.navigation.IPathPlanner;
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.module.sensor.WeaponPrefs;
76 import cz.cuni.amis.pogamut.ut2004.agent.navigation.NavigationState;
77 import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004AStarPathPlanner;
78 import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004GetBackToNavGraph;
79 import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004Navigation;
80 import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004PathExecutor;
81 import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004RunStraight;
82 import cz.cuni.amis.pogamut.ut2004.agent.navigation.loquenavigator.LoqueNavigator;
83 import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004DistanceStuckDetector;
84 import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004PositionStuckDetector;
85 import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004TimeStuckDetector;
86 import cz.cuni.amis.pogamut.ut2004.agent.params.UT2004AgentParameters;
87 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
88 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotModuleController;
89 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType;
90 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.GetPath;
91 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Initialize;
92 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.BotKilled;
93 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.FlagInfo;
94 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Item;
95 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
96 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PathList;
97 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
98 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PlayerKilled;
99 import cz.cuni.amis.pogamut.ut2004.utils.UT2004BotRunner;
100 import cz.cuni.amis.pogamut.ut3.bot.impl.UT3BotModuleController;
101 import cz.cuni.amis.pogamut.ut3.communication.messages.UT3ItemType;
102 import cz.cuni.amis.utils.exception.PogamutException;
103 import eis.eis2java.annotation.AsAction;
104 import eis.eis2java.annotation.AsPercept;
105 import eis.eis2java.translation.Filter.Type;
106 import eis.eis2java.util.AllPerceptsModule;
107 import eis.eis2java.util.AllPerceptsProvider;
108 import eis.exceptions.EntityException;
109 import eis.exceptions.PerceiveException;
110 import nl.tudelft.pogamut.ut3.agent.module.shooting.weapon.SlowVolumeShooting;
111
112 @SuppressWarnings("rawtypes")
113 public class UT3BotBehavior extends UT3BotModuleController<UT2004Bot> implements
114 AllPerceptsProvider {
115
116 protected List<ContextSelector> targetSelector = new ArrayList<ContextSelector>();
117 protected List<ContextSelector> lookSelector = new ArrayList<ContextSelector>();
118 protected Projectiles projectiles;
119 protected WeaponryShooting weaponShooting;
120 protected FocusProvider lookFocus = new FocusProvider();
121 protected OrderedFocusProvider focus = new OrderedFocusProvider();
122 protected AllPerceptsModule percepts;
123
124
125
126 protected BotParameters parameters;
127
128
129
130
131
132
133
134 private static final int ACTION_QUEUE_SIZE = 8;
135
136
137
138
139 private ActionQueue actions = new ActionQueue(ACTION_QUEUE_SIZE);
140 protected long logicIteration;
141 protected long actionCount;
142
143 @Override
144 public void initializeController(UT2004Bot bot) {
145 super.initializeController(bot);
146
147
148 IAgentLogger logger = bot.getLogger();
149 UT2004AgentParameters parameters = bot.getParams();
150 if ((parameters instanceof BotParameters)) {
151 this.parameters = (BotParameters) parameters;
152 } else {
153 log.warning("Provided parameters were not a subclass of UnrealGoalParameters, using defaults.");
154 this.parameters = new BotParameters();
155 }
156 this.parameters.assignDefaults(BotParameters.getDefaults());
157 }
158
159
160
161
162 @Override
163 protected void initializeModules(UT2004Bot bot) {
164 super.initializeModules(bot);
165
166 projectiles = new UT3Projectiles(bot, info);
167 weaponShooting = new WeaponryShooting(bot, info, weaponry, weaponPrefs,
168 shoot);
169
170
171 try {
172 percepts = new AllPerceptsModule(this);
173 } catch (EntityException e) {
174 throw new PogamutException("Could not create percept module", e);
175 }
176
177 initializeWeaponShootings();
178 }
179
180
181
182
183 protected void initializeWeaponShootings() {
184
185 weaponShooting.addWeaponShooting(new LinkGunShooting(bot, info, shoot,
186 weaponry));
187 weaponShooting.addWeaponShooting(new ShockRifleShooting(bot, info,
188 shoot, weaponry, projectiles));
189 weaponShooting.addWeaponShooting(new StingerMinigunShooting(bot, info,
190 shoot, weaponry));
191 weaponShooting.addWeaponShooting(new FlakCannonShooting(bot, info,
192 shoot, weaponry));
193 weaponShooting.addWeaponShooting(new ImpactHammerShooting(bot, info,
194 shoot, weaponry));
195 weaponShooting.addWeaponShooting(new BioRifleShooting(bot, info, shoot,
196 weaponry));
197 weaponShooting.addWeaponShooting(new EnforcerShooting(bot, info, shoot,
198 weaponry));
199 weaponShooting.addWeaponShooting(new RocketLauncherShooting(bot, info,
200 shoot, weaponry));
201
202 weaponShooting.addWeaponShooting(new SniperRifleShooting(bot, info,
203 shoot, weaponry));
204
205 weaponShooting.addWeaponShooting(new SlowVolumeShooting(bot, info,
206 shoot, weaponry));
207 }
208
209
210
211
212
213
214
215
216
217
218 protected SharedFloydWarshallMap sfwMap;
219
220
221
222
223
224
225
226
227
228
229 @Override
230 protected void initializePathFinding(UT2004Bot bot) {
231 pathPlanner = new UT2004AStarPathPlanner(bot);
232 sfwMap = new SharedFloydWarshallMap(bot);
233 pathExecutor = new UT2004PathExecutor<ILocated>(bot, info, move,
234 new LoqueNavigator<ILocated>(bot, info, move, bot.getLog()),
235 bot.getLog());
236
237
238
239
240
241
242 pathExecutor.addStuckDetector(new UT2004TimeStuckDetector(bot, 3000,
243 100000));
244 pathExecutor.addStuckDetector(new UT2004PositionStuckDetector(bot));
245 pathExecutor.addStuckDetector(new UT2004DistanceStuckDetector(bot));
246
247 getBackToNavGraph = new UT2004GetBackToNavGraph(bot, info, move);
248 runStraight = new UT2004RunStraight(bot, info, move);
249 navigation = new UT2004Navigation(bot, pathExecutor, sfwMap,
250 getBackToNavGraph, runStraight);
251 }
252
253
254
255
256
257
258 @Override
259 public Initialize getInitializeCommand() {
260 assert parameters != null;
261
262
263 Initialize init = super.getInitializeCommand();
264 init.setDesiredSkill(parameters.getSkill());
265 init.setSkin(parameters.getSkin().getUnrealName());
266 init.setTeam(parameters.getTeam());
267 init.setShouldLeadTarget(parameters.shouldLeadTarget());
268
269 init.setLocation(parameters.getInitialLocation());
270 init.setRotation(parameters.getInitialRotation());
271
272 log.setLevel(this.parameters.getLogLevel());
273
274 return init;
275
276 }
277
278
279
280
281
282 @Override
283 public void finishControllerInitialization() {
284
285
286
287 focus.add(weaponShooting.getFocus());
288 focus.add(lookFocus);
289 navigation.setFocus(focus);
290
291
292 if (navBuilder.isUsed()) {
293 log.info("Navigation graph has been altered by 'navBuilder', triggering recomputation of Floyd-Warshall path matrix...");
294 Level oldLevel = sfwMap.getLog().getLevel();
295 sfwMap.getLog().setLevel(Level.FINER);
296 sfwMap.refreshPathMatrix();
297 sfwMap.getLog().setLevel(oldLevel);
298 }
299 }
300
301
302
303
304
305
306 private void addDeployablePreferences(WeaponPrefs weaponPrefs) {
307 weaponPrefs.addGeneralPref(UT3ItemType.SLOW_VOLUME, true);
308 weaponPrefs.addGeneralPref(UT3ItemType.EMP_MINE, true);
309 weaponPrefs.addGeneralPref(UT3ItemType.ENERGY_SHIELD, true);
310 weaponPrefs.addGeneralPref(UT3ItemType.LINK_GENERATOR, true);
311 weaponPrefs.addGeneralPref(UT3ItemType.SHAPED_CHARGE, true);
312 weaponPrefs.addGeneralPref(UT3ItemType.XRAY_VOLUME, true);
313 }
314
315
316
317
318
319 @Override
320 public void beforeFirstLogic() {
321 targetSelector.add(new NearestEnemy().setContext(this));
322 lookSelector.add(new NearestEnemy().setContext(this));
323
324 addDeployablePreferences(weaponPrefs);
325 weaponPrefs.addGeneralPref(UT3ItemType.REDEEMER, true);
326 weaponPrefs.addGeneralPref(UT3ItemType.SHOCK_RIFLE, true);
327 weaponPrefs.addGeneralPref(UT3ItemType.ROCKET_LAUNCHER, true);
328 weaponPrefs.addGeneralPref(UT3ItemType.STINGER_MINIGUN, true);
329 weaponPrefs.addGeneralPref(UT3ItemType.FLAK_CANNON, true);
330 weaponPrefs.addGeneralPref(UT3ItemType.LINK_GUN, false);
331 weaponPrefs.addGeneralPref(UT3ItemType.SNIPER_RIFLE, true);
332 weaponPrefs.addGeneralPref(UT3ItemType.BIO_RIFLE, true);
333 weaponPrefs.addGeneralPref(UT3ItemType.ENFORCER, true);
334 weaponPrefs.addGeneralPref(UT3ItemType.IMPACT_HAMMER, true);
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 @Override
365 public void logic() {
366 super.logic();
367
368
369 for (Action action : actions.drain()) {
370 action.execute();
371 actionCount++;
372 }
373
374
375
376 ILocated shootSelected = null;
377 for (Selector<ILocated> selector : targetSelector) {
378 shootSelected = selector.select(players.getVisiblePlayers()
379 .values());
380 if (shootSelected != null) {
381 break;
382 }
383 }
384
385 if (!UT3ItemType.isDeployable(weaponry.getCurrentWeapon().getType())) {
386 weaponShooting.shoot(shootSelected);
387 }
388
389
390
391
392
393
394
395
396
397 ILocated lookSelected = null;
398 for (Selector<ILocated> selector : lookSelector) {
399 lookSelected = selector
400 .select(players.getVisiblePlayers().values());
401 if (lookSelected != null) {
402 break;
403 }
404 }
405 lookFocus.setFocus(lookSelected);
406
407
408 if (!navigation.isNavigating()) {
409
410 if (focus.getLocation() != null) {
411 move.turnTo(focus.getLocation());
412 }
413 else {
414 move.turnHorizontal(30);
415 }
416 }
417
418 logicIteration++;
419
420
421 try {
422 percepts.updatePercepts();
423 } catch (PerceiveException e) {
424 throw new PogamutException("Could not update percepts", e);
425 }
426
427 }
428
429
430
431
432
433
434
435
436
437 public void addAction(Action action) throws InterruptedException {
438 actions.put(action);
439 }
440
441
442
443
444
445
446 public Map<Method, Object> getAllPercepts() {
447 return percepts.getAllPercepts();
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 @AsAction(name = "navigate")
473 public void navigate(final UnrealIdOrLocation destination)
474 throws InterruptedException {
475 log.fine(String.format("called navigate to %s", destination));
476
477 addAction(new Navigate() {
478 @Override
479 public void execute() {
480
481 ILocated object = destination.toILocated(world, info);
482
483 if (object == null) {
484 log.warning(String
485 .format("failed to navigate to %s. The object associated with this Id was not located in the world. Halting.",
486 destination));
487 navigation.stopNavigation();
488 return;
489 }
490
491 log.fine(String.format("executed navigate to %s", destination));
492 navigation.navigate(object);
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 @AsAction(name = "stop")
552 public void stop() throws InterruptedException {
553 log.fine("called stop");
554
555 addAction(new Stop() {
556 @Override
557 public void execute() {
558 log.info("executed stop");
559 navigation.stopNavigation();
560 }
561 });
562 }
563
564
565
566
567
568
569
570
571
572 @AsAction(name = "respawn")
573 public void respawn() throws InterruptedException {
574 log.fine("called respawn");
575 addAction(new Respawn() {
576 @Override
577 public void execute() {
578 log.info("executed respawn");
579 bot.respawn();
580 }
581 });
582 }
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600 @AsAction(name = "deploy")
601 public void deploy() throws InterruptedException {
602 log.fine("called deploy");
603
604 addAction(new nl.tudelft.goal.ut3.actions.Deploy() {
605 @Override
606 public void execute() {
607 if (UT3ItemType.isDeployable(weaponry.getCurrentWeapon()
608 .getType())) {
609 shoot.shoot();
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 @AsAction(name = "path")
645 public Percept path(UnrealIdOrLocation from, UnrealIdOrLocation to) {
646
647 ILocated toObject = to.toILocated(world, info);
648 ILocated fromObject = from.toILocated(world, info);
649
650 if (fromObject == null) {
651 throw new PogamutException(
652 String.format(
653 "Failed to compute path from %s to %s. The start was not located in the world.",
654 from, to), this);
655 }
656 if (toObject == null) {
657 throw new PogamutException(
658 String.format(
659 "Failed to compute path from %s to %s. The destination was not located in the world.",
660 from, to), this);
661 }
662
663
664 log.info(String.format("executed path from %s to %s", from, to));
665
666
667
668
669
670
671
672 Location fromLocation = fromObject.getLocation();
673 Location toLocation = toObject.getLocation();
674
675 NavPoint fromNav = DistanceUtils.getNearest(world
676 .getAll(NavPoint.class).values(), fromLocation);
677 NavPoint toNav = DistanceUtils.getNearest(world.getAll(NavPoint.class)
678 .values(), toLocation);
679
680 double distance = sfwMap.getDistance(fromNav, toNav);
681 List<NavPoint> navPoints = sfwMap.getPath(fromNav, toNav);
682 List<UnrealId> unrealIds = new ArrayList<UnrealId>(navPoints.size());
683 for (NavPoint n : navPoints) {
684 unrealIds.add(n.getId());
685 }
686 return new Percept(fromNav.getId(), toNav.getId(), distance, unrealIds);
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 @AsAction(name = "shoot")
721 public void shoot(final SelectorList targets) throws InterruptedException {
722 log.fine(String.format("called shoot %s", targets));
723
724 addAction(new Shoot() {
725 @Override
726 public void execute() {
727 targetSelector = targets.setContext(UT3BotBehavior.this);
728 log.info(String.format("executed shoot %s ", targetSelector));
729 }
730 });
731
732 }
733
734
735
736
737
738
739
740
741
742
743
744
745
746 @AsAction(name = "stopShooting")
747 public void stopShooting() throws InterruptedException {
748 shoot(new SelectorList());
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 @AsAction(name = "prefer")
788 public void prefer(final WeaponPrefList weaponList)
789 throws InterruptedException {
790 log.fine(String.format("called prefer %s", weaponList));
791
792 addAction(new Prefer() {
793 @Override
794 public void execute() {
795 weaponPrefs.clearAllPrefs();
796 addDeployablePreferences(weaponPrefs);
797
798 for (WeaponPref pref : weaponList) {
799 weaponPrefs.addGeneralPref(pref.getWeapon(),
800 pref.isPrimary());
801 }
802
803 log.info(String.format("executed prefer %s", weaponList));
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 @AsAction(name = "look")
840 public void look(final SelectorList targets) throws InterruptedException {
841 log.fine(String.format("called look %s", targets));
842
843 addAction(new Look() {
844 @Override
845 public void execute() {
846 log.info(String.format("executed look %s", targets));
847
848 lookSelector = targets.setContext(UT3BotBehavior.this);
849 }
850 });
851 }
852
853
854
855
856
857
858
859
860
861
862
863 @AsAction(name = "skip")
864 public void skip() {
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 @AsPercept(name = "logic", filter = Type.ON_CHANGE)
892 @Deprecated
893 public Percept logicIteration() {
894 return new Percept(logicIteration);
895 }
896
897 @AsPercept(name = "actionCount", filter = Type.ON_CHANGE)
898 @Deprecated
899 public Percept actionCount() {
900 return new Percept(actionCount);
901 }
902
903 @AsPercept(name = "armor", filter = Type.ON_CHANGE)
904 public Percept armor() {
905 return new Percept(info.getHelmetArmor(), info.getVestArmor(),
906 info.getThighpadArmor(), info.getShieldBeltArmor());
907 }
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927 @AsPercept(name = "self", filter = Type.ON_CHANGE)
928 public Percept self() {
929 return new Percept(info.getId(), info.getName(), Team.valueOf(info
930 .getTeam()));
931 }
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951 @AsPercept(name = "orientation", filter = Type.ON_CHANGE)
952 public Percept orientation() {
953 return new Percept(info.getLocation(), info.getRotation(),
954 info.getVelocity());
955 }
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974 @AsPercept(name = "status", filter = Type.ON_CHANGE)
975 public Percept status() {
976 return new Percept(info.getHealth(), info.getArmor(), 0, new None());
977 }
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004 @AsPercept(name = "score", filter = Type.ON_CHANGE)
1005 public Percept score() {
1006 return new Percept(info.getKills(), info.getDeaths(),
1007 info.getSuicides());
1008 }
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030 @AsPercept(name = "currentWeapon", filter = Type.ON_CHANGE)
1031 public Percept currentWeapon() {
1032 final Weapon weapon = weaponry.getCurrentWeapon();
1033
1034 if (weapon == null) {
1035 return new Percept(new None(), new None(), FireMode.NONE);
1036 }
1037 return new Percept(weapon.getType(), FireMode.valueOf(
1038 info.isPrimaryShooting(), info.isSecondaryShooting()));
1039 }
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062 @AsPercept(name = "weapon", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1063 public Collection<Percept> weapon() {
1064 Collection<Weapon> weapons = weaponry.getWeapons().values();
1065 Collection<Percept> percepts = new ArrayList<Percept>(weapons.size());
1066
1067 for (Weapon w : weapons) {
1068 if (!UT3ItemType.isDeployable(w.getType()))
1069
1070
1071 {
1072 percepts.add(new Percept(w.getType(), w.getPrimaryAmmo(), w
1073 .getSecondaryAmmo()));
1074 } else {
1075
1076
1077 weaponry.changeWeapon(w);
1078 }
1079 }
1080
1081 return percepts;
1082 }
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104 @AsPercept(name = "deployable", filter = Type.ON_CHANGE_NEG)
1105 public Collection<Percept> deployable() {
1106 Collection<Weapon> weapons = weaponry.getWeapons().values();
1107 Collection<Percept> percepts = new ArrayList<Percept>(weapons.size());
1108
1109 for (Weapon w : weapons) {
1110 if (UT3ItemType.isDeployable(w.getType())) {
1111 percepts.add(new Percept(w.getType()));
1112 }
1113 }
1114 return percepts;
1115 }
1116
1117
1118
1119 private List<Percept> fragged = new LinkedList<Percept>();
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129 private void fraggedEvent(final long time, final UnrealId killer,
1130 final UnrealId victem, final String damageType) {
1131
1132
1133 fragged.add(new Percept(time, killer, victem, damageType));
1134 }
1135
1136
1137
1138
1139
1140
1141 @EventListener(eventClass = BotKilled.class)
1142 public void msgBotKilled(BotKilled msg) {
1143 fraggedEvent(msg.getSimTime(), msg.getKiller(), info.getId(),
1144 msg.getWeaponName());
1145 }
1146
1147
1148
1149
1150
1151
1152 @EventListener(eventClass = PlayerKilled.class)
1153 public void msgPlayerKilled(PlayerKilled msg) {
1154 fraggedEvent(msg.getSimTime(), msg.getKiller(), msg.getId(),
1155 msg.getDamageType());
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 @AsPercept(name = "fragged", multiplePercepts = true, filter = Type.ALWAYS, event = true)
1181 public List<Percept> fragged() {
1182 ArrayList<Percept> percepts = new ArrayList<Percept>(fragged);
1183 fragged.clear();
1184 return percepts;
1185 }
1186
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 @AsPercept(name = "navigation", filter = Type.ON_CHANGE)
1213 public Percept navigation() {
1214 Percept p;
1215 NavigationState state = navigation.getState().getFlag();
1216 ILocated lt = navigation.getLastTarget();
1217 Object lastTarget;
1218
1219 if (lt == null) {
1220 lastTarget = new None();
1221 }
1222 else if (lt instanceof IWorldObject) {
1223 IWorldObject targetObject = (IWorldObject) navigation.getLastTarget();
1224 lastTarget = targetObject.getId();
1225 } else {
1226 lastTarget = lt.getLocation();
1227 }
1228 switch (state) {
1229 case PATH_COMPUTATION_FAILED:
1230 p = new Percept(state, lastTarget);
1231 break;
1232 case TARGET_REACHED:
1233 p = new Percept(state, lastTarget);
1234 break;
1235 case STOPPED:
1236 p = new Percept(state, new None());
1237 break;
1238 case STUCK:
1239 p = new Percept(state, lastTarget);
1240 break;
1241 case NAVIGATING:
1242 ILocated currentTarget = navigation.getCurrentTarget();
1243 if (currentTarget instanceof IWorldObject) {
1244 IWorldObject targetObject = (IWorldObject) navigation.getCurrentTarget();
1245 p = new Percept(state, targetObject.getId());
1246 } else {
1247 p = new Percept(state, currentTarget.getLocation());
1248 }
1249 break;
1250 default:
1251 p = new Percept(state, new None());
1252 break;
1253 }
1254
1255 return p;
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
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300 @AsPercept(name = "navPoint", multiplePercepts = true, filter = Type.ONCE)
1301 public Collection<Percept> navPoint() {
1302 Collection<NavPoint> navPoints = world.getAll(NavPoint.class).values();
1303 List<Percept> percepts = new ArrayList<Percept>(navPoints.size());
1304
1305 for (NavPoint p : navPoints) {
1306 percepts.add(new Percept(p.getId(), p.getLocation(), p
1307 .getOutgoingEdges().keySet()));
1308 }
1309
1310 return percepts;
1311 }
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329 @AsPercept(name = "pickup", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1330 public Collection<Percept> visiblePickup() {
1331 Collection<NavPoint> navPoints = world.getAll(NavPoint.class).values();
1332 List<Percept> percepts = new ArrayList<Percept>(navPoints.size());
1333
1334 for (NavPoint p : navPoints) {
1335 if (p.isVisible()) {
1336 percepts.add(new Percept(p.getId()));
1337 }
1338 }
1339
1340 return percepts;
1341 }
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376 @AsPercept(name = "pickup", multiplePercepts = true, filter = Type.ONCE)
1377 public Collection<Percept> pickup() {
1378 Collection<Item> pickups = items.getKnownPickups().values();
1379 Collection<Percept> percepts = new ArrayList<Percept>(pickups.size());
1380
1381 for (Item item : pickups) {
1382
1383
1384
1385 if (!item.isDropped() && item.getNavPoint() != null) {
1386
1387 ItemType.Category cat = item.getType().getCategory();
1388
1389 if (UT3ItemType.isDeployable(item.getType())) {
1390 cat = ItemType.Category.DEPLOYABLE;
1391 }
1392 percepts.add(new Percept(item.getNavPointId(), cat, item.getType()));
1393 }
1394 }
1395 return percepts;
1396 }
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418 @AsPercept(name = "base", multiplePercepts = true, filter = Type.ONCE)
1419 public Collection<Percept> base() {
1420
1421 Collection<FlagInfo> flags = game.getAllCTFFlagsCollection();
1422 Collection<Percept> percepts = new ArrayList<Percept>(flags.size());
1423 Collection<NavPoint> navPoints = world.getAll(NavPoint.class).values();
1424
1425 for (FlagInfo flag : flags) {
1426 Team team = Team.valueOf(flag.getTeam());
1427 NavPoint nav = DistanceUtils.getNearest(navPoints,
1428 game.getFlagBase(team.id()));
1429 percepts.add(new Percept(team, nav.getId()));
1430 }
1431
1432 return percepts;
1433
1434 }
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459 @AsPercept(name = "game", filter = Type.ON_CHANGE)
1460 public Percept game() {
1461 return new Percept(game.getGameType(),
1462 game.getMapName(), game.getTeamScoreLimit(),
1463 game.getRemainingTime());
1464 }
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494 @AsPercept(name = "teamScore", filter = Type.ON_CHANGE)
1495 public Percept teamScore() {
1496 return new Percept(game.getTeamScore(info.getTeam()),
1497 game.getTeamScore(1 - info.getTeam()));
1498 }
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527 @AsPercept(name = "flagState", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1528 public Collection<Percept> flagState() {
1529
1530 Collection<FlagInfo> flags = game.getAllCTFFlagsCollection();
1531 Collection<Percept> percepts = new ArrayList<Percept>(flags.size());
1532
1533 for (FlagInfo flag : flags) {
1534 percepts.add(new Percept(Team.valueOf(flag.getTeam()), FlagState
1535 .valueOfIgnoreCase(flag.getState())));
1536 }
1537
1538 return percepts;
1539
1540 }
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579 @AsPercept(name = "item", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1580 public Collection<Percept> item() {
1581 Collection<Item> visibleItems = items.getVisibleItems().values();
1582 Collection<Percept> percepts = new ArrayList<Percept>(
1583 visibleItems.size());
1584
1585 for (Item item : visibleItems) {
1586 ItemType.Category cat = item.getType().getCategory();
1587 if (UT3ItemType.isDeployable(item.getType())) {
1588 cat = ItemType.Category.DEPLOYABLE;
1589 }
1590
1591
1592
1593 if (item.isDropped() || item.getNavPointId() == null) {
1594 percepts.add(new Percept(item.getId(), cat, item.getType(),
1595 item.getLocation()));
1596 } else {
1597 percepts.add(new Percept(item.getId(), cat, item.getType(),
1598 item.getNavPointId()));
1599 }
1600 }
1601
1602 return percepts;
1603 }
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635 @AsPercept(name = "flag", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1636 public Collection<Percept> flag() {
1637
1638 Collection<FlagInfo> flags = game.getAllCTFFlagsCollection();
1639 Collection<Percept> percepts = new ArrayList<Percept>(flags.size());
1640
1641 for (FlagInfo flag : flags) {
1642 if (flag.isVisible()) {
1643 percepts.add(new Percept(Team.valueOf(flag.getTeam()), flag
1644 .getHolder(), flag.getLocation()));
1645 }
1646 }
1647
1648 return percepts;
1649 }
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676 @AsPercept(name = "bot", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1677 public Collection<Percept> bot() {
1678 Collection<Player> visible = players.getVisiblePlayers().values();
1679 Collection<Percept> wrapped = new ArrayList<Percept>(visible.size());
1680
1681 for (Player p : visible) {
1682 wrapped.add(new Percept(p.getId(), p.getName(), Team.valueOf(p
1683 .getTeam()), p.getLocation(), UT3ItemType.getItemType(p
1684 .getWeapon()), FireMode.valueOf(p.getFiring())));
1685 }
1686
1687 return wrapped;
1688 }
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733 @AsPercept(name = "powerup", multiplePercepts = true, filter = Type.ON_CHANGE)
1734 public Collection<Percept> powerup() {
1735 Collection<Percept> percepts = new ArrayList<Percept>();
1736
1737 if (info.hasPowerUp()) {
1738 percepts.add(new Percept(
1739 UT3ItemType.getItemType(info.getPowerUp()), info
1740 .getPowerUpTime()));
1741 } else {
1742 percepts.add(new Percept(new None(), 0.0));
1743 }
1744
1745 return percepts;
1746 }
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766 @AsPercept(name = "slowVolume", filter = Type.ON_CHANGE)
1767 public Percept slowvolume() {
1768 List<UnrealId> slowVolumeNavPoints = visibility.getVisibleVolumeNavPoints(UT3ItemType.SLOW_VOLUME_CONTENT);
1769 return new Percept(slowVolumeNavPoints);
1770 }
1771 }