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
31b1d3f3
Commit
31b1d3f3
authored
6 months ago
by
Fabian Heinrich
Browse files
Options
Downloads
Patches
Plain Diff
Refactoring
parent
88a65c54
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!110
V1.2.0 changes
,
!106
Visual layout selection
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cooperative_cuisine/pygame_2d_vis/generate_layout_thumbnail.py
+22
-32
22 additions, 32 deletions
...rative_cuisine/pygame_2d_vis/generate_layout_thumbnail.py
with
22 additions
and
32 deletions
cooperative_cuisine/pygame_2d_vis/g
rid
.py
→
cooperative_cuisine/pygame_2d_vis/g
enerate_layout_thumbnail
.py
+
22
−
32
View file @
31b1d3f3
import
uuid
from
pprint
import
pprint
import
matplotlib.pyplot
as
plt
import
numpy
as
np
import
yaml
from
collections
import
defaultdict
from
cooperative_cuisine
import
ROOT_DIR
from
cooperative_cuisine.counter_factory
import
convert_words_to_chars
from
cooperative_cuisine.items
import
ItemInfo
,
ItemType
from
cooperative_cuisine.pygame_2d_vis.drawing
import
Visualizer
from
cooperative_cuisine.items
import
ItemType
dummy_env_config_path
=
ROOT_DIR
/
"
configs
"
/
"
dummy_environment_config.yaml
"
with
open
(
dummy_env_config_path
)
as
c
:
dummy_env_config
=
yaml
.
load
(
c
,
Loader
=
yaml
.
FullLoader
)
character_map
=
dummy_env_config
[
"
layout_chars
"
]
character_map
=
convert_words_to_chars
(
character_map
)
counter_set
=
{
"
Counter
"
,
"
PlateDispenser
"
,
"
CuttingBoard
"
,
"
Trashcan
"
,
"
ServingWindow
"
,
"
Sink
"
,
"
SinkAddon
"
}
def
layout_thumbnail
(
layout_path
,
vis
,
max_size
,
item_lookup
):
with
open
(
layout_path
)
as
file
:
layout
=
file
.
read
()
colors
=
defaultdict
(
lambda
:
0
)
v
=
list
(
set
(
character_map
.
values
()))
idx_free
=
v
.
index
(
"
Free
"
)
zero
=
v
[
0
]
v
[
0
]
=
"
Free
"
v
[
idx_free
]
=
zero
colors
.
update
({
c
:
i
for
i
,
c
in
enumerate
(
v
)})
grid
=
[]
counter
=
[]
player
=
[]
...
...
@@ -42,7 +29,7 @@ def layout_thumbnail(layout_path, vis, max_size, item_lookup):
continue
for
y
,
char
in
enumerate
(
line
.
strip
()):
t
=
character_map
[
char
]
row
.
append
(
colors
[
t
]
)
row
.
append
(
0
)
match
t
:
case
"
Agent
"
:
player
.
append
([
float
(
y
),
float
(
x
)])
...
...
@@ -56,18 +43,18 @@ def layout_thumbnail(layout_path, vis, max_size, item_lookup):
image
=
np
.
array
(
grid
).
T
def
map_t
(
t
):
if
t
in
{
"
C
ounter
"
,
"
PlateDispenser
"
,
"
CuttingBoard
"
,
"
Trashcan
"
,
"
ServingWindow
"
,
"
Sink
"
,
"
SinkAddon
"
}
:
if
t
in
c
ounter
_set
:
return
t
if
t
in
item_lookup
:
i
=
item_lookup
[
t
]
if
i
.
type
==
ItemType
.
Equipment
and
i
.
equipment
:
return
i
.
equipment
.
name
if
i
.
type
==
ItemType
.
Ingredient
:
return
t
+
"
Dispenser
"
return
f
"
{
t
}
Dispenser
"
return
"
Counter
"
def
map_t_occupied
(
t
):
if
t
in
{
"
C
ounter
"
,
"
PlateDispenser
"
,
"
CuttingBoard
"
,
"
Trashcan
"
,
"
ServingWindow
"
,
"
Sink
"
,
"
SinkAddon
"
}
:
if
t
in
c
ounter
_set
:
return
None
if
t
in
item_lookup
:
i
=
item_lookup
[
t
]
...
...
@@ -75,23 +62,26 @@ def layout_thumbnail(layout_path, vis, max_size, item_lookup):
return
{
"
category
"
:
"
ItemCookingEquipment
"
,
"
type
"
:
t
,
"
content_list
"
:
[],
"
content_ready
"
:
None
,
"
active_effects
"
:
[]}
if
i
.
type
==
ItemType
.
Ingredient
:
return
{
"
category
"
:
"
Item
"
,
"
type
"
:
t
,
"
content_list
"
:
[],
"
content_ready
"
:
None
,
"
active_effects
"
:
[]}
return
{
"
category
"
:
"
Item
"
,
"
type
"
:
t
,
"
active_effects
"
:
[]}
return
None
state
=
{
"
players
"
:
[
{
"
id
"
:
str
(
i
),
"
pos
"
:
p
,
"
facing_direction
"
:
[
0
,
1
],
"
holding
"
:
None
,
"
current_nearest_counter_pos
"
:
None
,
{
"
id
"
:
str
(
i
),
"
pos
"
:
p
,
"
facing_direction
"
:
[
0
,
1
],
"
holding
"
:
None
,
"
current_nearest_counter_pos
"
:
None
,
"
current_nearest_counter_id
"
:
None
}
for
i
,
p
in
enumerate
(
player
)],
"
counters
"
:
[{
"
id
"
:
uuid
.
uuid4
().
hex
,
"
pos
"
:
pos
,
"
orientation
"
:
[
0
,
1
],
"
type
"
:
map_t
(
t
),
"
occupied_by
"
:
map_t_occupied
(
t
),
"
active_effects
"
:
[]}
for
pos
,
t
in
counter
],
"
kitchen
"
:
{
"
width
"
:
image
.
shape
[
0
],
"
height
"
:
image
.
shape
[
1
]},
"
counters
"
:
[{
"
id
"
:
uuid
.
uuid4
().
hex
,
"
pos
"
:
pos
,
"
orientation
"
:
[
0
,
1
],
"
type
"
:
map_t
(
t
),
"
occupied_by
"
:
map_t_occupied
(
t
),
"
active_effects
"
:
[]}
for
pos
,
t
in
counter
],
"
kitchen
"
:
{
"
width
"
:
image
.
shape
[
0
],
"
height
"
:
image
.
shape
[
1
]},
}
# im = viz.get_state_image(grid_size=32, state=state).transpose((1, 0, 2))
grid_size
=
max_size
/
max
(
state
[
"
kitchen
"
][
"
width
"
],
state
[
"
kitchen
"
][
"
height
"
])
grid_size
=
int
(
max_size
//
max
(
state
[
"
kitchen
"
][
"
width
"
],
state
[
"
kitchen
"
][
"
height
"
]))
vis
.
set_grid_size
(
grid_size
)
surf
=
vis
.
draw_gamescreen
(
state
,
[])
return
surf
# plt.imshow(im)
# plt.show()
return
vis
.
draw_gamescreen
(
state
,
[])
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