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
25328145
Commit
25328145
authored
1 year ago
by
Fabian Heinrich
Browse files
Options
Downloads
Patches
Plain Diff
Added actual player movement, added collision with world bounds
parent
3f3344c3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2
Resolve "2D movement continuous"
Pipeline
#41189
failed
1 year ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
overcooked_simulator/overcooked_environment.py
+51
-5
51 additions, 5 deletions
overcooked_simulator/overcooked_environment.py
with
51 additions
and
5 deletions
overcooked_simulator/overcooked_environment.py
+
51
−
5
View file @
25328145
...
...
@@ -30,6 +30,8 @@ class Environment:
self
.
layout_path
=
Path
(
"
overcooked_simulator/layouts/basic.layout
"
)
self
.
counters
=
self
.
create_counters
(
self
.
layout_path
)
self
.
score
=
0
self
.
world_width
=
800
self
.
world_height
=
600
def
create_counters
(
self
,
layout_file
:
Path
):
"""
Creates layout of kitchen counters in the environment based on layout file.
...
...
@@ -55,7 +57,8 @@ class Environment:
counters
.
append
(
counter
)
current_x
+=
self
.
counter_side_length
elif
character
==
"
E
"
:
pass
current_x
+=
self
.
counter_side_length
current_y
+=
self
.
counter_side_length
return
counters
...
...
@@ -126,15 +129,45 @@ class Environment:
"""
pass
def
perform_movement
(
self
,
player
:
Player
,
action
):
def
perform_movement
(
self
,
player
:
Player
,
move_vector
:
np
.
array
):
"""
Moves a player in the direction specified in the action.action. If the player collides with a
counter or other player through this movement, then they are not moved.
(The extended code with the two ifs is for sliding movement at the counters, which feels a bit smoother.
This happens, when the player moves diagonally against the counters or world boundary.
This just checks if the single axis party of the movement could move the player and does so at a lower rate.)
The movement action is a unit 2d vector.
Args:
player: The player to move.
action: The Action which now contain
s a unit-2d-vector of the movement direction
move_vector: The movement vector which i
s a unit-2d-vector of the movement direction
"""
pass
old_pos
=
player
.
pos
.
copy
()
step
=
move_vector
*
player
.
move_dist
player
.
move
(
step
)
if
self
.
detect_collision
(
player
):
player
.
move_abs
(
old_pos
)
old_pos
=
player
.
pos
.
copy
()
step_sliding
=
step
.
copy
()
step_sliding
[
0
]
=
0
player
.
move
(
step_sliding
*
0.5
)
player
.
turn
(
step
)
if
self
.
detect_collision
(
player
):
player
.
move_abs
(
old_pos
)
old_pos
=
player
.
pos
.
copy
()
step_sliding
=
step
.
copy
()
step_sliding
[
1
]
=
0
player
.
move
(
step_sliding
*
0.5
)
player
.
turn
(
step
)
if
self
.
detect_collision
(
player
):
player
.
move_abs
(
old_pos
)
def
detect_collision
(
self
,
player
:
Player
):
"""
Detect collisions between the player and other players or counters.
...
...
@@ -144,7 +177,8 @@ class Environment:
Returns: True if the player is intersecting with any object in the environment.
"""
return
self
.
detect_player_collision
(
player
)
or
self
.
detect_collision_counters
(
player
)
return
(
self
.
detect_player_collision
(
player
)
or
self
.
detect_collision_counters
(
player
)
or
self
.
detect_collision_world_bounds
(
player
))
def
detect_player_collision
(
self
,
player
:
Player
):
"""
Detects collisions between the queried player and other players.
...
...
@@ -196,6 +230,18 @@ class Environment:
distance
=
np
.
linalg
.
norm
([
dx
,
dy
])
return
distance
<
player
.
radius
def
detect_collision_world_bounds
(
self
,
player
:
Player
):
"""
Checks for detections of the player and the world bounds.
Args:
player: The player which to not let escape the world.
Returns: True if the player touches the world bounds, False if not.
"""
collisions_lower
=
any
((
player
.
pos
-
player
.
radius
)
<
0
)
collisions_upper
=
any
((
player
.
pos
+
player
.
radius
)
>
[
self
.
world_width
,
self
.
world_height
])
return
collisions_lower
or
collisions_upper
def
step
(
self
):
"""
Performs a step of the environment. Affects time based events such as cooking or cutting things, orders
and timelimits.
...
...
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