Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Cooperative Cuisine Environment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Social Cognitive Systems
CoCoSy
Cooperative Cuisine Environment
Commits
c3e71240
Commit
c3e71240
authored
1 year ago
by
Fabian Heinrich
Browse files
Options
Downloads
Patches
Plain Diff
Test for player registration and simulator frequency timing
parent
b764c1eb
No related branches found
No related tags found
1 merge request
!1
Issue #6 Base simulator class and methods
Pipeline
#41144
failed
1 year ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
overcooked_simulator/main.py
+2
-2
2 additions, 2 deletions
overcooked_simulator/main.py
overcooked_simulator/simulation_runner.py
+5
-3
5 additions, 3 deletions
overcooked_simulator/simulation_runner.py
tests/test_start.py
+43
-4
43 additions, 4 deletions
tests/test_start.py
with
50 additions
and
9 deletions
overcooked_simulator/main.py
+
2
−
2
View file @
c3e71240
from
player
import
Player
import
sys
from
simulation_runner
import
Simulator
from
overcooked_environment
import
Environment
def
main
():
simulator
=
Simulator
()
simulator
=
Simulator
(
Environment
,
300
)
simulator
.
register_player
(
Player
(
"
p1
"
,
[
100
,
200
]))
simulator
.
register_player
(
Player
(
"
p2
"
,
[
200
,
100
]))
...
...
This diff is collapsed.
Click to expand it.
overcooked_simulator/simulation_runner.py
+
5
−
3
View file @
c3e71240
...
...
@@ -17,13 +17,13 @@ class Simulator(Thread):
sim.start()
"""
def
__init__
(
self
):
def
__init__
(
self
,
env_class
:
type
,
frequency
:
int
):
self
.
finished
:
bool
=
False
self
.
step_frequency
:
float
=
300
self
.
step_frequency
:
int
=
frequency
self
.
prefered_sleeptime_ns
:
float
=
1e9
/
self
.
step_frequency
self
.
env
:
Environment
=
E
nv
ironment
()
self
.
env
=
e
nv
_class
()
super
().
__init__
()
...
...
@@ -59,6 +59,7 @@ class Simulator(Thread):
return
self
.
env
.
get_state_json
()
def
register_player
(
self
,
player
:
Player
):
print
(
f
"
Added player
{
player
.
name
}
to the game.
"
)
"""
Adds a player to the environment.
Args:
...
...
@@ -98,4 +99,5 @@ class Simulator(Thread):
def
stop
(
self
):
"""
Stops the simulator
"""
print
(
"
Stopping the simulation.
"
)
self
.
finished
=
True
This diff is collapsed.
Click to expand it.
tests/test_start.py
+
43
−
4
View file @
c3e71240
from
overcooked_simulator.simulation_runner
import
Simulator
from
overcooked_simulator.player
import
Player
from
overcooked_simulator.overcooked_environment
import
Environment
,
Action
import
numpy
as
np
import
time
def
test_dummy
():
assert
"
overcooked
"
.
startswith
(
"
over
"
),
"
overcooked does not start with
'
over
'"
def
test_player_registration
():
def
test_failure
():
assert
False
,
"
What does happen now?
"
sim
=
Simulator
()
p1
=
Player
(
"
player
"
,
np
.
array
([
0
,
0
]))
sim
.
register_player
(
p1
)
assert
len
(
sim
.
env
.
players
)
!=
0
assert
len
(
sim
.
env
.
players
)
==
1
p2
=
Player
(
"
player
"
,
np
.
array
([
100
,
100
]))
sim
.
register_player
(
p2
)
assert
len
(
sim
.
env
.
players
)
==
2
sim
.
start
()
sim
.
stop
()
def
test_simulator_frequency
():
class
TestEnv
:
def
__init__
(
self
):
self
.
c
=
0
def
step
(
self
):
self
.
c
+=
1
frequency
=
1000
running_time_seconds
=
5
sim
=
Simulator
(
TestEnv
,
frequency
)
sim
.
start
()
time
.
sleep
(
running_time_seconds
)
sim
.
stop
()
accepted_tolerance
=
0.04
lower
=
frequency
*
running_time_seconds
*
(
1
-
accepted_tolerance
)
upper
=
frequency
*
running_time_seconds
*
(
1
+
accepted_tolerance
)
assert
sim
.
env
.
c
>
lower
and
sim
.
env
.
c
<
upper
,
"
Timing error in the environment at 1000hz
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment