66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
from pprint import pprint
|
|
from desktop_env.envs.desktop_env import DesktopEnv, Action, MouseClick
|
|
|
|
def get_human_action():
|
|
"""
|
|
Prompts the human player for an action and returns a structured action.
|
|
"""
|
|
print("\nAvailable actions:", [action.name for action in Action])
|
|
action_type = None
|
|
while action_type not in [action.value for action in Action]:
|
|
action_type = Action[input("Enter the type of action: ".strip())].value
|
|
|
|
action = {"action_type": action_type}
|
|
|
|
if action_type == Action.CLICK.value or action_type == Action.MOUSE_DOWN.value or action_type == Action.MOUSE_UP.value:
|
|
print("\n Available clicks:", [action.name for action in MouseClick])
|
|
click_type = input("Enter click type: ")
|
|
action["click_type"] = MouseClick[click_type].value
|
|
|
|
if action_type == Action.MOUSE_MOVE.value:
|
|
x = int(input("Enter x-coordinate for mouse move: "))
|
|
y = int(input("Enter y-coordinate for mouse move: "))
|
|
action["x"] = x
|
|
action["y"] = y
|
|
|
|
if action_type == Action.KEY.value:
|
|
key = input("Enter the key to press: ")
|
|
action["key"] = [ord(c) for c in key]
|
|
|
|
if action_type == Action.TYPE.value:
|
|
text = input("Enter the text to type: ")
|
|
action["text"] = [ord(c) for c in text]
|
|
|
|
return action
|
|
|
|
|
|
def human_agent():
|
|
"""
|
|
Runs the Gym environment with human input.
|
|
"""
|
|
env = DesktopEnv(path_to_vm="/home/yuri/vmware/Ubuntu 64-bit/Ubuntu 64-bit.vmx",
|
|
username="user",
|
|
password="password",
|
|
host="192.168.7.128")
|
|
observation = env.reset()
|
|
done = False
|
|
|
|
while not done:
|
|
action = get_human_action()
|
|
observation, reward, done, info = env.step(action)
|
|
print("Observation:", observation)
|
|
print("Reward:", reward)
|
|
print("Info:", info)
|
|
|
|
print("================================\n")
|
|
|
|
if done:
|
|
print("The episode is done.")
|
|
break
|
|
|
|
env.close()
|
|
print("Environment closed.")
|
|
|
|
if __name__ == "__main__":
|
|
human_agent()
|