Skip to content
Snippets Groups Projects
Commit 7c31d0ac authored by Florian Schröder's avatar Florian Schröder
Browse files

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.
parent 4bdc6212
No related branches found
No related tags found
No related merge requests found
Pipeline #47851 passed
......@@ -124,7 +124,7 @@ action = Action(
action = Action(
player="0",
action_type=ActionType.PUT,
action_data="pickup",
action_data=None,
)
# --- interact ---
action = Action(
......
......@@ -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)
......@@ -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,
),
......
......@@ -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:
......
......@@ -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`
......
......@@ -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
......
......@@ -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,
)
......
......@@ -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))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment