Skip to content

Commit 32989c0

Browse files
committed
Update Navigate Medical Room and Restore Health
1 parent 697a4b3 commit 32989c0

File tree

3 files changed

+63
-30
lines changed

3 files changed

+63
-30
lines changed

CucumberTester/src/main/kotlin/bdd/iv4XR/state/SeScenarioState.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package bdd.iv4XR.state
33
import environments.SeAgentState
44
import environments.SeEnvironment
55
import eu.iv4xr.framework.mainConcepts.TestAgent
6+
import spaceEngineers.controller.SpaceEngineers
67

78
class SeScenarioState {
8-
var agentId: String? = null
9+
var agentId: String = SpaceEngineers.DEFAULT_AGENT_ID
910
var seEnvironment: SeEnvironment? = null
1011
var seAgentState: SeAgentState? = null
1112
var testAgent: TestAgent? = null

CucumberTester/src/main/kotlin/bdd/iv4XR/steps/SeScenarioStepsDefinition.kt

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import spaceEngineers.controller.SpaceEngineers
1818
import spaceEngineers.controller.SpaceEngineersTestContext
1919
import spaceEngineers.iv4xr.goal.GoalBuilder
2020
import spaceEngineers.iv4xr.goal.TacticLib
21+
import spaceEngineers.model.Vec3F
22+
import spaceEngineers.model.extensions.allBlocks
2123
import java.io.File
2224
import java.nio.file.Paths
2325
import kotlin.test.assertTrue
@@ -26,15 +28,19 @@ class SeScenarioStepsDefinition {
2628

2729
private val seScenarioState: SeScenarioState = SeScenarioState()
2830

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}")
3037
fun agentLoadsScenario(worldId: String) {
31-
seScenarioState.agentId = SpaceEngineers.DEFAULT_AGENT_ID
3238
val context = SpaceEngineersTestContext()
3339

3440
// Create a controller instance of the SpaceEngineers interface.
3541
val controllerWrapper =
3642
ContextControllerWrapper(
37-
spaceEngineers = JvmSpaceEngineersBuilder.default().localhost(seScenarioState.agentId!!),
43+
spaceEngineers = JvmSpaceEngineersBuilder.default().localhost(seScenarioState.agentId),
3844
context = context
3945
)
4046

@@ -57,15 +63,15 @@ class SeScenarioStepsDefinition {
5763
Thread.sleep(1000)
5864

5965
// Create the iv4XR test agent
60-
seScenarioState.seAgentState = SeAgentState(agentId = seScenarioState.agentId!!)
66+
seScenarioState.seAgentState = SeAgentState(agentId = seScenarioState.agentId)
6167
val dataCollector = TestDataCollector()
6268
seScenarioState.testAgent = TestAgent(seScenarioState.agentId, "goal solving agent")
6369
.attachState(seScenarioState.seAgentState)
6470
.attachEnvironment(seScenarioState.seEnvironment)
6571
.setTestDataCollector(dataCollector)
6672
}
6773

68-
@Given("the agent observes the block type {string}.")
74+
@Given("the agent observes the block {string}")
6975
fun agentObservesBlock(blockType: String) {
7076
val goalStructure: GoalStructure = SEQ(
7177
GoalBuilder().blockOfTypeExists(
@@ -78,21 +84,24 @@ class SeScenarioStepsDefinition {
7884
assertTrue(status.success())
7985
}
8086

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+
8392
val goalStructure: GoalStructure = SEQ(
8493
GoalBuilder().navigateNearToBlock(
8594
blockType,
86-
distance,
87-
tactic = TacticLib().groundedNavigationNearToBlock(blockType, distance) { it.maxPosition },
95+
closestDistance,
96+
tactic = TacticLib().navigateToBlock(blockType, closestDistance, distancePathTolerance)
8897
)
8998
)
9099

91100
val status = executeGoal(goalStructure)
92101
assertTrue(status.success())
93102
}
94103

95-
@When("the agent aims the block type {string}.")
104+
@When("the agent aims the block {string}")
96105
fun agentAimsTheBlock(blockType: String) {
97106
val goalStructure: GoalStructure = SEQ(
98107
GoalBuilder().aimToBlock(
@@ -105,7 +114,7 @@ class SeScenarioStepsDefinition {
105114
assertTrue(status.success())
106115
}
107116

108-
@When("the agent removes the helmet {long} milliseconds.")
117+
@When("the agent removes the helmet {long} milliseconds")
109118
fun agentRemovesHelmet(milliseconds: Long) {
110119
val goalStructure: GoalStructure = SEQ(
111120
GoalBuilder().agentHealthIsBelow(
@@ -118,7 +127,7 @@ class SeScenarioStepsDefinition {
118127
assertTrue(status.success())
119128
}
120129

121-
@When("the agent activates the helmet.")
130+
@When("the agent activates the helmet")
122131
fun agentActivatesHelmet() {
123132
val goalStructure: GoalStructure = SEQ(
124133
GoalBuilder().alwaysSolved(
@@ -130,7 +139,7 @@ class SeScenarioStepsDefinition {
130139
assertTrue(status.success())
131140
}
132141

133-
@When("the agent continuously uses the terminal {long} milliseconds.")
142+
@When("the agent uses the terminal {long} milliseconds")
134143
fun agentContinuouslyUses(milliseconds: Long) {
135144
val goalStructure: GoalStructure = SEQ(
136145
GoalBuilder().alwaysSolved(
@@ -142,7 +151,21 @@ class SeScenarioStepsDefinition {
142151
assertTrue(status.success())
143152
}
144153

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}")
146169
fun agentHealthBelow(percentage: Double) {
147170
val goalStructure: GoalStructure = SEQ(
148171
GoalBuilder().agentHealthIsBelow(
@@ -155,7 +178,7 @@ class SeScenarioStepsDefinition {
155178
assertTrue(status.success())
156179
}
157180

158-
@Then("the agent health is above {double} percentage.")
181+
@Then("the agent health is above {double}")
159182
fun agentHealthAbove(percentage: Double) {
160183
val goalStructure: GoalStructure = SEQ(
161184
GoalBuilder().agentHealthIsAbove(
@@ -168,10 +191,19 @@ class SeScenarioStepsDefinition {
168191
assertTrue(status.success())
169192
}
170193

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+
171203
private fun executeGoal(goalStructure: GoalStructure):ProgressStatus{
172204
seScenarioState.testAgent?.setGoal(goalStructure)
173205
var i = 0
174-
while (goalStructure.status.inProgress() && i <= 5) {
206+
while (goalStructure.status.inProgress() && i <= 20) {
175207
seScenarioState.testAgent?.update()
176208
println("*** $i, ${seScenarioState.seAgentState?.worldmodel?.agentId} @${seScenarioState.seAgentState?.worldmodel?.position}")
177209
i++
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
Feature: Navigate Medical Room and Restore Health
22

33
Background:
4-
Given the agent loads the world "LoneSurvivor_SpaceShip".
4+
Given the agent-id is 'se0'
5+
And the agent loads the world 'LoneSurvivor_SpaceShip'
56

6-
Scenario Outline: The agent navigates to the medical room and restores is health
7-
Given the agent observes the block type "<blockType>".
8-
When the agent navigates to the 2x2 block type "<blockType>" with a maximum <distance>.
9-
When the agent aims the block type "<blockType>".
10-
When the agent removes the helmet <wait> milliseconds.
11-
Then the agent health is below <minimum> percentage.
7+
Scenario: The agent navigates to the medical room and restores is health
8+
Given the agent observes the block 'LargeMedicalRoom'
129

13-
When the agent activates the helmet.
14-
When the agent continuously uses the terminal <wait> milliseconds.
15-
Then the agent health is above <maximum> percentage.
10+
When the agent navigates to the block 'LargeMedicalRoom'
11+
And the agent aims the block 'LargeMedicalRoom'
12+
Then the maximum distance to the block 'LargeMedicalRoom' is 5
1613

17-
Examples:
18-
| blockType | distance | wait | minimum | maximum |
19-
| LargeMedicalRoom | 7 | 5000 | 90.00 | 99.99 |
14+
When the agent removes the helmet 5000 milliseconds
15+
And the agent activates the helmet
16+
Then the agent health is below 90.00
17+
18+
When the agent uses the terminal 5000 milliseconds
19+
Then the agent health is above 99.99

0 commit comments

Comments
 (0)