@@ -18,6 +18,8 @@ import spaceEngineers.controller.SpaceEngineers
18
18
import spaceEngineers.controller.SpaceEngineersTestContext
19
19
import spaceEngineers.iv4xr.goal.GoalBuilder
20
20
import spaceEngineers.iv4xr.goal.TacticLib
21
+ import spaceEngineers.model.Vec3F
22
+ import spaceEngineers.model.extensions.allBlocks
21
23
import java.io.File
22
24
import java.nio.file.Paths
23
25
import kotlin.test.assertTrue
@@ -26,15 +28,19 @@ class SeScenarioStepsDefinition {
26
28
27
29
private val seScenarioState: SeScenarioState = SeScenarioState ()
28
30
29
- @Given(" the agent loads the world {string}." )
31
+ @Given(" the agent-id is {string}" )
32
+ fun agentId (agentId : String ) {
33
+ seScenarioState.agentId = agentId
34
+ }
35
+
36
+ @Given(" the agent loads the world {string}" )
30
37
fun agentLoadsScenario (worldId : String ) {
31
- seScenarioState.agentId = SpaceEngineers .DEFAULT_AGENT_ID
32
38
val context = SpaceEngineersTestContext ()
33
39
34
40
// Create a controller instance of the SpaceEngineers interface.
35
41
val controllerWrapper =
36
42
ContextControllerWrapper (
37
- spaceEngineers = JvmSpaceEngineersBuilder .default().localhost(seScenarioState.agentId!! ),
43
+ spaceEngineers = JvmSpaceEngineersBuilder .default().localhost(seScenarioState.agentId),
38
44
context = context
39
45
)
40
46
@@ -57,15 +63,15 @@ class SeScenarioStepsDefinition {
57
63
Thread .sleep(1000 )
58
64
59
65
// Create the iv4XR test agent
60
- seScenarioState.seAgentState = SeAgentState (agentId = seScenarioState.agentId!! )
66
+ seScenarioState.seAgentState = SeAgentState (agentId = seScenarioState.agentId)
61
67
val dataCollector = TestDataCollector ()
62
68
seScenarioState.testAgent = TestAgent (seScenarioState.agentId, " goal solving agent" )
63
69
.attachState(seScenarioState.seAgentState)
64
70
.attachEnvironment(seScenarioState.seEnvironment)
65
71
.setTestDataCollector(dataCollector)
66
72
}
67
73
68
- @Given(" the agent observes the block type {string}. " )
74
+ @Given(" the agent observes the block {string}" )
69
75
fun agentObservesBlock (blockType : String ) {
70
76
val goalStructure: GoalStructure = SEQ (
71
77
GoalBuilder ().blockOfTypeExists(
@@ -78,21 +84,24 @@ class SeScenarioStepsDefinition {
78
84
assertTrue(status.success())
79
85
}
80
86
81
- @When(" the agent navigates to the 2x2 block type {string} with a maximum {float}." )
82
- fun agentNavigatesTo2x2Block (blockType : String , distance : Float ) {
87
+ @When(" the agent navigates to the block {string}" )
88
+ fun agentNavigatesToBlock (blockType : String ) {
89
+ val closestDistance = if (is1x1Block(blockType)) 3f else 5f
90
+ val distancePathTolerance = if (is1x1Block(blockType)) 1.2f else 3f
91
+
83
92
val goalStructure: GoalStructure = SEQ (
84
93
GoalBuilder ().navigateNearToBlock(
85
94
blockType,
86
- distance ,
87
- tactic = TacticLib ().groundedNavigationNearToBlock (blockType, distance) { it.maxPosition },
95
+ closestDistance ,
96
+ tactic = TacticLib ().navigateToBlock (blockType, closestDistance, distancePathTolerance)
88
97
)
89
98
)
90
99
91
100
val status = executeGoal(goalStructure)
92
101
assertTrue(status.success())
93
102
}
94
103
95
- @When(" the agent aims the block type {string}. " )
104
+ @When(" the agent aims the block {string}" )
96
105
fun agentAimsTheBlock (blockType : String ) {
97
106
val goalStructure: GoalStructure = SEQ (
98
107
GoalBuilder ().aimToBlock(
@@ -105,7 +114,7 @@ class SeScenarioStepsDefinition {
105
114
assertTrue(status.success())
106
115
}
107
116
108
- @When(" the agent removes the helmet {long} milliseconds. " )
117
+ @When(" the agent removes the helmet {long} milliseconds" )
109
118
fun agentRemovesHelmet (milliseconds : Long ) {
110
119
val goalStructure: GoalStructure = SEQ (
111
120
GoalBuilder ().agentHealthIsBelow(
@@ -118,7 +127,7 @@ class SeScenarioStepsDefinition {
118
127
assertTrue(status.success())
119
128
}
120
129
121
- @When(" the agent activates the helmet. " )
130
+ @When(" the agent activates the helmet" )
122
131
fun agentActivatesHelmet () {
123
132
val goalStructure: GoalStructure = SEQ (
124
133
GoalBuilder ().alwaysSolved(
@@ -130,7 +139,7 @@ class SeScenarioStepsDefinition {
130
139
assertTrue(status.success())
131
140
}
132
141
133
- @When(" the agent continuously uses the terminal {long} milliseconds. " )
142
+ @When(" the agent uses the terminal {long} milliseconds" )
134
143
fun agentContinuouslyUses (milliseconds : Long ) {
135
144
val goalStructure: GoalStructure = SEQ (
136
145
GoalBuilder ().alwaysSolved(
@@ -142,7 +151,21 @@ class SeScenarioStepsDefinition {
142
151
assertTrue(status.success())
143
152
}
144
153
145
- @Then(" the agent health is below {double} percentage." )
154
+ @Then(" the maximum distance to the block {string} is {float}" )
155
+ fun agentMaximumDistanceToBlock (blockType : String , goalDistance : Float ) {
156
+ val goalStructure: GoalStructure = SEQ (
157
+ GoalBuilder ().navigateNearToBlock(
158
+ blockType,
159
+ goalDistance,
160
+ tactic = TacticLib ().doNothing()
161
+ ),
162
+ )
163
+
164
+ val status = executeGoal(goalStructure)
165
+ assertTrue(status.success())
166
+ }
167
+
168
+ @Then(" the agent health is below {double}" )
146
169
fun agentHealthBelow (percentage : Double ) {
147
170
val goalStructure: GoalStructure = SEQ (
148
171
GoalBuilder ().agentHealthIsBelow(
@@ -155,7 +178,7 @@ class SeScenarioStepsDefinition {
155
178
assertTrue(status.success())
156
179
}
157
180
158
- @Then(" the agent health is above {double} percentage. " )
181
+ @Then(" the agent health is above {double}" )
159
182
fun agentHealthAbove (percentage : Double ) {
160
183
val goalStructure: GoalStructure = SEQ (
161
184
GoalBuilder ().agentHealthIsAbove(
@@ -168,10 +191,19 @@ class SeScenarioStepsDefinition {
168
191
assertTrue(status.success())
169
192
}
170
193
194
+ private fun is1x1Block (blockType : String ):Boolean {
195
+ for (block in seScenarioState.seEnvironment?.controller?.observer?.observeBlocks()?.allBlocks!! ) {
196
+ if (blockType in block.definitionId.toString()) {
197
+ return block.size == Vec3F (1 ,1 ,1 )
198
+ }
199
+ }
200
+ return false
201
+ }
202
+
171
203
private fun executeGoal (goalStructure : GoalStructure ):ProgressStatus {
172
204
seScenarioState.testAgent?.setGoal(goalStructure)
173
205
var i = 0
174
- while (goalStructure.status.inProgress() && i <= 5 ) {
206
+ while (goalStructure.status.inProgress() && i <= 20 ) {
175
207
seScenarioState.testAgent?.update()
176
208
println (" *** $i , ${seScenarioState.seAgentState?.worldmodel?.agentId} @${seScenarioState.seAgentState?.worldmodel?.position} " )
177
209
i++
0 commit comments