Skip to content

Commit 79b714e

Browse files
committed
restoring uuagent tests so they work again
1 parent 0d3e02e commit 79b714e

File tree

22 files changed

+13766
-13963
lines changed

22 files changed

+13766
-13963
lines changed

JvmClient/src/jvmMain/java/onlineTestCaseGenerator/Solver.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package onlineTestCaseGenerator;
22

3-
import eu.iv4xr.framework.mainConcepts.Iv4xrAgentState;
43
import eu.iv4xr.framework.mainConcepts.TestAgent;
54
import eu.iv4xr.framework.spatial.Vec3;
65
import nl.uu.cs.aplib.mainConcepts.GoalStructure;
@@ -17,7 +16,7 @@ public class Solver {
1716

1817
public GoalStructure use(TestAgent agent, String Type){
1918
if(Type.contains("Door")){
20-
return UUGoalLib.interacted(agent);
19+
return UUGoalLib.doorInteracted(agent);
2120
}else if (Type.contains("Assembler")){
2221
return SEQ(UUGoalLib.targetBlockOK(agent, e ->
2322
Type.equals(e.getStringProperty("blockType"))

JvmClient/src/jvmMain/java/uuspaceagent/PrintInfos.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static String showWOMAgent(WorldModel wm) {
6565
var info = wm.elements.get(wm.agentId) ;
6666
z.append(", hdir:" + info.properties.get("orientationForward")) ;
6767
z.append(", vdir:" + info.properties.get("orientationUp")) ;
68-
z.append(", health:" + info.properties.get("healthRatio")) ;
68+
z.append(", health:" + info.properties.get("health")) ;
6969
z.append(", jet:" + info.properties.get("jetpackRunning")) ;
7070
return z.toString() ;
7171
}

JvmClient/src/jvmMain/java/uuspaceagent/UUGoalLib.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,21 @@ public static Function<UUSeAgentState,GoalStructure> closeToPosition(TestAgent a
155155
}
156156

157157

158+
/**
159+
* Equip a tool in location k of tool-bar-0
160+
*/
161+
public static GoalStructure toolEquiped(int k) {
162+
return lift("Tool equiped",
163+
action("equip a tool").do1((UUSeAgentState state) -> {
164+
state.env().equip(new ToolbarLocation(k,0));
165+
return true ;
166+
})
167+
) ;
168+
}
169+
/**
170+
* Equip grinder, assuming it is put in location-0 of the tool-bar-0.
171+
* @return
172+
*/
158173
public static GoalStructure grinderEquiped() {
159174
return lift("Grinder equiped",
160175
action("equip grinder").do1((UUSeAgentState state) -> {
@@ -164,9 +179,12 @@ public static GoalStructure grinderEquiped() {
164179
) ;
165180
}
166181

182+
/**
183+
* Unequip-tool (so switching to bare-hand).
184+
*/
167185
public static GoalStructure barehandEquiped() {
168-
return lift("Grinder equiped",
169-
action("equip grinder").do1((UUSeAgentState state) -> {
186+
return lift("Barehand equiped",
187+
action("equip barehand").do1((UUSeAgentState state) -> {
170188
state.env().equip(new ToolbarLocation(0,9));
171189
return true ;
172190
})
@@ -212,6 +230,7 @@ public static GoalStructure targetBlockOK(TestAgent agent, Predicate<WorldEntity
212230
Tactic success = action("success").do1((UUSeAgentState state) -> true).lift() ;
213231

214232
return SEQ(
233+
// hmm... why should we equip a tool if we just want to check the state of a bloc??
215234
grinderEquiped(),
216235
goal("target entity passes a check")
217236
.toSolve(b -> true)
@@ -314,7 +333,9 @@ public static boolean findItemPredicate(UUSeAgentState st, String blockType){
314333
if(blocks.size()>0) return false;
315334
return true ;
316335
}
317-
public static GoalStructure interacted(TestAgent agent) {
336+
337+
338+
public static GoalStructure doorInteracted(TestAgent agent) {
318339

319340
return DEPLOY(agent, (UUSeAgentState state) -> {
320341

@@ -330,8 +351,8 @@ public static GoalStructure interacted(TestAgent agent) {
330351
})
331352
.withTactic(
332353
SEQ(
333-
UUTacticLib.interacted( state,targetBlock)
334-
,UUTacticLib.observe(state,targetBlock)
354+
UUTacticLib.doorInteracted( state,targetBlock)
355+
,UUTacticLib.observeIfBlockIsOpen(state,targetBlock)
335356
)
336357
)
337358
.lift() ;

JvmClient/src/jvmMain/java/uuspaceagent/UUTacticLib.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,12 @@ public static List<DPos3> smoothenPath(List<DPos3> path) {
460460
* Interact with an object like door
461461
* @param state
462462
*/
463-
public static Tactic interacted(UUSeAgentState state, Block targetBlock) {
463+
public static Tactic doorInteracted(UUSeAgentState state, Block targetBlock) {
464464
return action("Interacting")
465465
.do1((UUSeAgentState st) -> {
466466
UseObjectExtensions useUtil = new UseObjectExtensions(state.env().getController().getSpaceEngineers()) ;
467467
useUtil.openIfNotOpened((DoorBase) targetBlock);
468-
var checkIsOpen = SEBlockFunctions.findWorldEntity(st.worldmodel,targetBlock.getId()) ;
469-
var isOpen = checkIsOpen.getProperty("isOpen").toString();
470-
if(isOpen.equals("true")) return null;
471-
return true;
468+
return null ;
472469
})
473470
.on((UUSeAgentState st) -> {
474471
if (st.worldmodel ==null) return null ;
@@ -485,12 +482,11 @@ public static Tactic interacted(UUSeAgentState state, Block targetBlock) {
485482
// useUtil.openIfNotOpened((DoorBase) targetBlock);
486483
// }
487484

488-
public static Tactic observe(UUSeAgentState state, Block targetBlock){
485+
public static Tactic observeIfBlockIsOpen(UUSeAgentState state, Block targetBlock){
489486
return action("Interacting").do1((UUSeAgentState st) -> {
490-
var checkIsOpen = SEBlockFunctions.findWorldEntity(state.worldmodel,targetBlock.getId()) ;
491-
var isOpen = checkIsOpen.getProperty("isOpen").toString();
492-
if(isOpen.equals("true")) return true;
493-
return false;
487+
var target = SEBlockFunctions.findWorldEntity(state.worldmodel,targetBlock.getId()) ;
488+
var isOpen = target.getProperty("isOpen").toString();
489+
return "true".equals(isOpen) ;
494490
})
495491
.lift();
496492
}

JvmClient/src/jvmTest/java/onlineTestCaseGenerator/Test_ChainPattern.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void test_navigate_and_grind() throws InterruptedException {
8080
20f,
8181
0.1f))
8282
,
83-
UUGoalLib.interacted(agent),
83+
UUGoalLib.doorInteracted(agent),
8484
//look for the second assembler
8585
DEPLOY(agent, UUGoalLib.closeTo(agent,
8686
"BasicAssembler",

JvmClient/src/jvmTest/java/spaceEngineers/iv4xr/Test_SimpleInteractionsWithSE.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,16 @@ public void test_env_interactions() throws InterruptedException {
128128
console(">> velo:" + obs.velocity) ;
129129

130130
int i = 0 ;
131-
while(i<20) {
131+
while(i<40) {
132132
//obs = theEnv.moveForward(5f) ;
133-
obs = theEnv.moveForward() ;
133+
//obs = theEnv.moveForward() ;
134134
if (i<20) {
135+
// rotating the engineer's orientation:
135136
theEnv.getController().getCharacter().moveAndRotate(new Vec3F(0,0,0), new Vec2F(0,20),0,1) ;
136137
}
137138
else {
138-
theEnv.getController().getCharacter().moveAndRotate(new Vec3F(0,0,-36), new Vec2F(0,0),0,1) ;
139+
// making it walks (in this case backward):
140+
theEnv.getController().getCharacter().moveAndRotate(new Vec3F(0,0,1), new Vec2F(0,0),0,1) ;
139141
}
140142
obs = theEnv.observe() ;
141143
primObs = theEnv.getController().getObserver().observe() ;

JvmClient/src/jvmTest/java/uuspaceagent/Coba_moveToward_and_yTurnToward.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ public void test_2DMoveTo2() throws InterruptedException {
7171

7272
console("#### to x+");
7373
state.updateState(state.agentId);
74-
Vec3 destination = new Vec3(10.2f,-5f,54.14f) ;
74+
Vec3 destination = new Vec3(11.5f,-5f,54.14f) ;
7575
moveTo(state, destination) ;
7676

7777
console("#### Moving to z-:");
7878
state.updateState(state.agentId);
79-
destination = new Vec3(10.2f,-5f,53.14f) ;
79+
destination = new Vec3(10.2f,-5f,52.15f) ;
8080
moveTo(state, destination) ;
8181
}
8282

JvmClient/src/jvmTest/java/uuspaceagent/Test_Flying.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public void test_flying_to_some_location() throws InterruptedException {
4545
console("*** start test...") ;
4646
//Thread.sleep(5000);
4747
//Vec3 dest = new Vec3(10,-5,30) ;
48-
Vec3 dest = new Vec3(10,5,53.7f) ;
49-
//Vec3 dest = new Vec3(25,-5,60) ;
48+
//Vec3 dest = new Vec3(10,5,53.7f) ;
49+
Vec3 dest = new Vec3(25,-5,60) ;
5050
//Vec3 dest = new Vec3(10,3,56) ;
5151
var agentAndState = deployAgent();
5252
var agent = agentAndState.fst ;

JvmClient/src/jvmTest/java/uuspaceagent/Test_Goals.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
public class Test_Goals {
1818

19-
public Pair<TestAgent, UUSeAgentState> deployAgent() throws InterruptedException {
20-
var agentAndState = loadSE("myworld-3 with open door") ; // loadSE("myworld-3") ;
19+
public Pair<TestAgent, UUSeAgentState> deployAgent(String worldname) throws InterruptedException {
20+
var agentAndState = loadSE(worldname) ;
2121
TestAgent agent = agentAndState.fst ;
2222
UUSeAgentState state = agentAndState.snd ;
2323
Thread.sleep(1000);
@@ -48,32 +48,31 @@ public void test_close2Dto_GS1() throws InterruptedException {
4848
// agent's start position.
4949
console("*** start test...") ;
5050
Vec3 dest = new Vec3(19,-5,65) ;
51-
var agentAndState = deployAgent();
51+
var agentAndState = deployAgent("myworld-3");
5252
var agent = agentAndState.fst ;
5353
GoalStructure G = DEPLOYonce(agent, UUGoalLib.closeTo(dest)) ;
5454
test_Goal(agentAndState.fst, agentAndState.snd, G) ;
5555
G.printGoalStructureStatus();
5656
assertTrue(G.getStatus().success());
5757
}
5858

59-
@Test
59+
//@Test
6060
public void test_close2Dto_GS2() throws InterruptedException {
61-
// This is a position that is unreachable, so this goal should abort
61+
// This is a position that is unreachable with 2D-nav, so this goal should abort
6262
console("*** start test...") ;
6363
Vec3 dest = new Vec3(10,-5,40) ;
64-
var agentAndState = deployAgent();
64+
var agentAndState = deployAgent("myworld-3");
6565
var agent = agentAndState.fst ;
6666
GoalStructure G = DEPLOYonce(agent, UUGoalLib.closeTo(dest)) ;
6767
test_Goal(agentAndState.fst, agentAndState.snd, G) ;
6868
G.printGoalStructureStatus();
6969
assertTrue(G.getStatus().failed());
7070
}
7171

72-
@Test
72+
//@Test
7373
public void test_closeTo_Block_1() throws InterruptedException {
74-
// This is a position that is unreachable, so this goal should abort
7574
console("*** start test...") ;
76-
var agentAndState = deployAgent();
75+
var agentAndState = deployAgent("myworld-3 with open door X");
7776
var agent = agentAndState.fst ;
7877
GoalStructure G = DEPLOYonce(agent, UUGoalLib.closeTo(agentAndState.fst,
7978
"LargeBlockSlideDoor",
@@ -85,34 +84,32 @@ public void test_closeTo_Block_1() throws InterruptedException {
8584
assertTrue(G.getStatus().success());
8685
}
8786

88-
@Test
87+
//@Test
8988
public void test_closeTo_Block_2() throws InterruptedException {
90-
// This is a position that is unreachable, so this goal should abort
9189
console("*** start test...") ;
92-
var agentAndState = deployAgent();
90+
var agentAndState = deployAgent("myworld-3 with open door X");
9391
var agent = agentAndState.fst ;
9492
GoalStructure G = DEPLOYonce(agent, UUGoalLib.closeTo(agentAndState.fst,
9593
"LargeBlockBatteryBlock",
9694
SEBlockFunctions.BlockSides.FRONT,
97-
20f,
95+
30f,
9896
0.5f));
9997
test_Goal(agentAndState.fst, agentAndState.snd, G) ;
10098
G.printGoalStructureStatus();
101-
assertTrue(G.getStatus().failed());
99+
assertTrue(G.getStatus().success());
102100
}
103101

104-
@Test
102+
//@Test
105103
public void test_navigate_and_grind() throws InterruptedException {
106-
// This is a position that is unreachable, so this goal should abort
107104
console("*** start test...") ;
108-
var agentAndState = deployAgent();
105+
var agentAndState = deployAgent("myworld-3 with open door X");
109106
TestAgent agent = agentAndState.fst ;
110107
agent.setTestDataCollector(new TestDataCollector()) ;
111108

112109
GoalStructure G = SEQ(DEPLOYonce(agent, UUGoalLib.closeTo(agent,
113110
"LargeBlockBatteryBlock",
114111
SEBlockFunctions.BlockSides.FRONT,
115-
20f,
112+
30f,
116113
0.5f)),
117114
UUGoalLib.targetBlockOK(agent, e ->
118115
"LargeBlockBatteryBlock".equals(e.getStringProperty("blockType"))

JvmClient/src/jvmTest/java/uuspaceagent/Test_GrindingWithId.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
public class Test_GrindingWithId {
1818

1919
public Pair<TestAgent, UUSeAgentState> deployAgent() throws InterruptedException {
20-
var agentAndState = loadSE("world-3 blocks") ; // loadSE("myworld-3") ;
20+
var agentAndState = loadSE("myworld-3 with open door") ; // loadSE("world-3 blocks") ; //
2121
TestAgent agent = agentAndState.fst ;
2222
UUSeAgentState state = agentAndState.snd ;
2323
Thread.sleep(1000);
@@ -53,13 +53,13 @@ public void test_navigate_and_grind() throws InterruptedException {
5353
GoalStructure G = SEQ(
5454

5555
DEPLOYonce(agent, UUGoalLib.closeToPosition(agent,
56-
"BasicAssembler",
56+
"LargeBlockBatteryBlock",
5757
SEBlockFunctions.BlockSides.FRONT,
5858
new Vec3(3.75f,-5f,-6.75f),
59-
20f,
59+
100f,
6060
0.5f)),
6161
UUGoalLib.targetBlockOK(agent, e ->
62-
"BasicAssembler".equals(e.getStringProperty("blockType"))
62+
"LargeBlockBatteryBlock".equals(e.getStringProperty("blockType"))
6363
&& (float) e.getProperty("integrity") == (float) e.getProperty("maxIntegrity"),
6464
false
6565
),

0 commit comments

Comments
 (0)