1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package nl.tudelft.goal.ut3.environment;
18
19 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
20 import cz.cuni.amis.pogamut.ut3.communication.messages.UT3ItemType;
21 import eis.iilang.Function;
22 import eis.iilang.Identifier;
23 import eis.iilang.Numeral;
24 import eis.iilang.Percept;
25 import nl.tudelft.goal.unreal.messages.UnrealIdOrLocation;
26 import static nl.tudelft.goal.ut3.environment.AbstractEnvironmentTests.testBot;
27 import nl.tudelft.goal.ut3.messages.FireMode;
28 import nl.tudelft.goal.ut3.messages.SelectorList;
29 import nl.tudelft.goal.ut3.selector.WorldObject;
30 import org.junit.Test;
31 import static org.junit.Assert.*;
32
33
34
35
36
37
38 public class SelfPerceptTests extends AbstractEnvironmentTests {
39
40
41
42
43 @Test
44 public void selfTest() {
45 for(Percept p : startupPercepts) {
46 if(p.getName().equals("self")) {
47 assertTrue(p.getParameters().size() == 3);
48
49 assertEquals(new Identifier(BOT_NAME), p.getParameters().get(1));
50 assertEquals(new Identifier(BOT_TEAM.name().toLowerCase()), p.getParameters().get(2));
51 }
52 }
53 }
54
55
56
57
58
59 @Test
60 public void orientationStandStillTest() {
61 for(Percept p : startupPercepts) {
62 if(p.getName().equals("orientation")) {
63
64 assertTrue(p.getParameters().size() == 3);
65 Function noneLocation = new Function("location", new Numeral(0.0), new Numeral(0.0), new Numeral(0.0));
66 assertFalse(p.getParameters().get(0).equals(noneLocation));
67 }
68 }
69 }
70
71
72
73
74
75
76 @Test
77 public void statusTest() {
78 for(Percept p : startupPercepts) {
79 if(p.getName().equals("status")) {
80
81
82 assertTrue(p.getParameters().size() == 4);
83 assertEquals(new Numeral(100), p.getParameters().get(0));
84 assertEquals(new Numeral(0), p.getParameters().get(1));
85 }
86 }
87 }
88
89
90
91
92 @Test
93 public void scoreTest() {
94
95
96 for(Percept p : startupPercepts) {
97 if(p.getName().equals("score")) {
98 assertTrue(p.getParameters().size() == 3);
99 assertEquals(new Numeral(0), p.getParameters().get(0));
100 assertEquals(new Numeral(0), p.getParameters().get(1));
101 assertEquals(new Numeral(0), p.getParameters().get(2));
102 }
103 }
104 }
105
106
107
108
109 @Test
110 public void currentWeaponTest() {
111 for(Percept p : startupPercepts) {
112 if(p.getName().equals("currentWeapon")) {
113 assertTrue(p.getParameters().size() == 2);
114 assertEquals(new Identifier("enforcer"), p.getParameters().get(0));
115 assertEquals(new Identifier(FireMode.NONE.name().toLowerCase()), p.getParameters().get(1));
116 }
117 }
118 }
119
120
121
122
123 @Test
124 public void weaponTest() {
125 boolean enforcer = false, impact_hammer = false;
126
127 for(Percept p : startupPercepts) {
128 if(p.getName().equals("weapon")) {
129 assertTrue(p.getParameters().size() == 3);
130
131
132 if(p.getParameters().get(0).equals(new Identifier("enforcer"))) {
133 enforcer = true;
134 assertEquals(new Numeral(50), p.getParameters().get(1));
135 assertEquals(new Numeral(50), p.getParameters().get(2));
136 }
137
138 else if(p.getParameters().get(0).equals(new Identifier("impact_hammer"))) {
139 impact_hammer = true;
140 assertEquals(new Numeral(0), p.getParameters().get(1));
141 assertEquals(new Numeral(0), p.getParameters().get(2));
142 }
143 else {
144
145
146 }
147 }
148 }
149 assertTrue(enforcer);
150 assertTrue(impact_hammer);
151 }
152
153
154
155
156
157 @Test
158 public void testSuicideAttempt() throws InterruptedException
159 {
160 testBot.getWeaponPrefs().clearAllPrefs();
161 testBot.getWeaponPrefs().addGeneralPref(UT3ItemType.ROCKET_LAUNCHER, true);
162 testBot.navigate(new UnrealIdOrLocation(UnrealId.get("UTWeaponLocker_Content_0")));
163 Thread.sleep(3000);
164
165 SelectorList selectorList = new SelectorList();
166 selectorList.add(new WorldObject(UnrealId.get("UTWeaponLocker_Content_0")));
167 testBot.shoot(selectorList);
168
169 Thread.sleep(3000);
170 assertTrue(testBot.getInfo().getHealth() < 100);
171 assertEquals(17, testBot.getWeaponry().getAmmo(UT3ItemType.ROCKET_LAUNCHER));
172 }
173 }