From 7c31d0acb7585752eda08d80f3cec3d52d5dd615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Schr=C3=B6der?= <fschroeder@techfak.uni-bielefeld.de> Date: Tue, 5 Mar 2024 14:35:13 +0100 Subject: [PATCH] Update PUT action to PICK_UP_DROP The ActionType.PUT has been replaced with ActionType.PICK_UP_DROP across all instances in the codebase. This change aligns the action name with its actual function, making the action more intuitive and the code easier to understand. This update also includes minor modifications in comments and function arguments to reflect the new action name. --- cooperative_cuisine/__init__.py | 2 +- cooperative_cuisine/action.py | 8 +++----- cooperative_cuisine/configs/agents/random_agent.py | 4 ++-- cooperative_cuisine/environment.py | 2 +- cooperative_cuisine/pygame_2d_vis/__init__.py | 4 ++-- cooperative_cuisine/pygame_2d_vis/gui.py | 4 ++-- cooperative_cuisine/reinforcement_learning/gym_env.py | 2 +- tests/test_start.py | 4 ++-- 8 files changed, 14 insertions(+), 16 deletions(-) diff --git a/cooperative_cuisine/__init__.py b/cooperative_cuisine/__init__.py index e3bd8db9..9b238226 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 bb94a936..1bc0c19f 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 f2208817..3b1b5832 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 8f29213a..4d562582 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 c5a1185e..a90ff6d1 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 15856bb9..cab7dc8e 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 465701fe..93fc02aa 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 ae0121ec..fec31349 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)) -- GitLab