diff --git a/cooperative_cuisine/__init__.py b/cooperative_cuisine/__init__.py index e3bd8db959d95c7964ed58ec041e2577f2561113..9b2382267bd2306cf0a5e0daf5b5c061dd5f2f05 100644 --- a/cooperative_cuisine/__init__.py +++ b/cooperative_cuisine/__init__.py @@ -124,7 +124,7 @@ action = Action( action = Action( player="0", action_type=ActionType.PUT, - action_data="pickup", + action_data=None, ) # --- interact --- action = Action( diff --git a/cooperative_cuisine/action.py b/cooperative_cuisine/action.py index bb94a9369ddb0293464715fbb19f7edcbbdebb1f..1bc0c19fe2dd5db7bce753f76f4f3986a1a1d5b9 100644 --- a/cooperative_cuisine/action.py +++ b/cooperative_cuisine/action.py @@ -2,7 +2,6 @@ from __future__ import annotations import dataclasses from enum import Enum -from typing import Literal from numpy import typing as npt @@ -12,9 +11,8 @@ class ActionType(Enum): MOVEMENT = "movement" """move the agent.""" - PUT = "pickup" + PICK_UP_DROP = "pick_up_drop" """interaction type 1, e.g., for pickup or drop off.""" - # TODO change value to put INTERACT = "interact" """interaction type 2, e.g., for progressing. Start and stop interaction via `keydown` and `keyup` actions.""" @@ -36,7 +34,7 @@ class Action: """Id of the player.""" action_type: ActionType """Type of the action to perform. Defines what action data is valid.""" - action_data: npt.NDArray[float] | list[float] | InterActionData | Literal["pickup"] + action_data: npt.NDArray[float] | list[float] | InterActionData | None """Data for the action, e.g., movement vector or start and stop interaction.""" duration: float | int = 0 """Duration of the action (relevant for movement)""" @@ -47,5 +45,5 @@ class Action: def __post_init__(self): if isinstance(self.action_type, str): self.action_type = ActionType(self.action_type) - if isinstance(self.action_data, str) and self.action_data != "pickup": + if isinstance(self.action_data, str): self.action_data = InterActionData(self.action_data) diff --git a/cooperative_cuisine/configs/agents/random_agent.py b/cooperative_cuisine/configs/agents/random_agent.py index f2208817bbdc55b0942c2c18a6bc8b65e235ec9f..3b1b5832b32f74367582d93846681e7d9562b1b0 100644 --- a/cooperative_cuisine/configs/agents/random_agent.py +++ b/cooperative_cuisine/configs/agents/random_agent.py @@ -188,8 +188,8 @@ async def agent(): "action": dataclasses.asdict( Action( args.player_id, - ActionType.PUT, - "pickup", + ActionType.PICK_UP_DROP, + None, ), dict_factory=custom_asdict_factory, ), diff --git a/cooperative_cuisine/environment.py b/cooperative_cuisine/environment.py index 8f29213a50abf5aaf43ae06b0c7ef5b8c5fa49c3..4d562582f3522680bc3e588ffe58d93e174c87c3 100644 --- a/cooperative_cuisine/environment.py +++ b/cooperative_cuisine/environment.py @@ -339,7 +339,7 @@ class Environment: else: counter = get_closest(player.facing_point, self.counters) if player.can_reach(counter): - if action.action_type == ActionType.PUT: + if action.action_type == ActionType.PICK_UP_DROP: player.put_action(counter) self.hook(ACTION_PUT, action=action, counter=counter) elif action.action_type == ActionType.INTERACT: diff --git a/cooperative_cuisine/pygame_2d_vis/__init__.py b/cooperative_cuisine/pygame_2d_vis/__init__.py index c5a1185e214dc7d99eb02ebc704666bfbfa44041..a90ff6d13ec4e4d4db946e9733135caf52a77f9a 100644 --- a/cooperative_cuisine/pygame_2d_vis/__init__.py +++ b/cooperative_cuisine/pygame_2d_vis/__init__.py @@ -12,13 +12,13 @@ The keys for the control of the players are: ### Player 1: - Movement: `W`, `A`, `S`, `D`, -- Pickup: `E` +- Pickup/Drop off: `E` - Interact: `F` - Swap Players (if configured): `SPACE` ### Player 2: - Movement: `⬆`, `⬅`, `⬇`, `➡` (arrow keys) -- Pickup: `I` +- Pickup/Drop off: `I` - Interact: `O` - Swap Players (if configured): `P` diff --git a/cooperative_cuisine/pygame_2d_vis/gui.py b/cooperative_cuisine/pygame_2d_vis/gui.py index 15856bb9b153f9d5f852e34e2a98f214bbad8703..cab7dc8e7c33a8521eaa125cc5bd18c033aa7036 100644 --- a/cooperative_cuisine/pygame_2d_vis/gui.py +++ b/cooperative_cuisine/pygame_2d_vis/gui.py @@ -313,7 +313,7 @@ class PyGameGUI: for key_set in self.key_sets: current_player_name = str(key_set.current_player) if event.key == key_set.pickup_key and event.type == pygame.KEYDOWN: - action = Action(current_player_name, ActionType.PUT, "pickup") + action = Action(current_player_name, ActionType.PICK_UP_DROP, None) self.send_action(action) if event.key == key_set.interact_key: @@ -349,7 +349,7 @@ class PyGameGUI: joysticks[key_set.joystick].get_button(0) and event.type == pygame.JOYBUTTONDOWN ): - action = Action(current_player_name, ActionType.PUT, "pickup") + action = Action(current_player_name, ActionType.PICK_UP_DROP, None) self.send_action(action) # interact = Button X <-> 2 diff --git a/cooperative_cuisine/reinforcement_learning/gym_env.py b/cooperative_cuisine/reinforcement_learning/gym_env.py index 465701fe70ee1771f07e1fe1636744cef7864e0e..93fc02aa7fe9406c1bac73c17ce0d1211a247f08 100644 --- a/cooperative_cuisine/reinforcement_learning/gym_env.py +++ b/cooperative_cuisine/reinforcement_learning/gym_env.py @@ -73,7 +73,7 @@ def get_env_action(player_id, simple_action, duration): case SimpleActionSpace.Put: return Action( player_id, - ActionType.PUT, + ActionType.PICK_UP_DROP, InterActionData.START, duration, ) diff --git a/tests/test_start.py b/tests/test_start.py index ae0121ec0daefb6cbff0bb13292cabc8e453dfc1..fec31349ac50c39f3d02019c66f1a7f802389a33 100644 --- a/tests/test_start.py +++ b/tests/test_start.py @@ -164,7 +164,7 @@ def test_pickup(env_config, layout_config, item_info): move_down = Action("1", ActionType.MOVEMENT, np.array([0, -1]), duration=1) move_up = Action("1", ActionType.MOVEMENT, np.array([0, 1]), duration=1) - pick = Action("1", ActionType.PUT, "pickup") + pick = Action("1", ActionType.PICK_UP_DROP, None) env.perform_action(move_down) env.step(timedelta(seconds=1)) @@ -226,7 +226,7 @@ def test_processing(env_config, layout_config, item_info): player.holding = tomato move = Action("1", ActionType.MOVEMENT, np.array([0, -1]), duration=1) - pick = Action("1", ActionType.PUT, "pickup") + pick = Action("1", ActionType.PICK_UP_DROP, None) env.perform_action(move) env.step(timedelta(seconds=1))