-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsocket_agent.py
More file actions
executable file
·42 lines (29 loc) · 1.14 KB
/
Copy pathsocket_agent.py
File metadata and controls
executable file
·42 lines (29 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Author: Gyan Tatiya
# Email: Gyan.Tatiya@tufts.edu
import json
import random
import socket
from env import SupermarketEnv
from utils import recv_socket_data
if __name__ == "__main__":
# Make the env
# env_id = 'Supermarket-v0'
# env = gym.make(env_id)
action_commands = ['NOP', 'NORTH', 'SOUTH', 'EAST', 'WEST', 'TOGGLE_CART', 'INTERACT']
print("action_commands: ", action_commands)
# Connect to Supermarket
HOST = '127.0.0.1'
PORT = 9000
sock_game = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock_game.connect((HOST, PORT))
while True:
# action = str(random.randint(0, 1))
# action += " " + random.choice(action_commands) # random action
# assume this is the only agent in the game
action = "0 " + "SOUTH"
print("Sending action: ", action)
sock_game.send(str.encode(action)) # send action to env
output = recv_socket_data(sock_game) # get observation from env
output = json.loads(output)
print("Observations: ", output["observation"])
print("Violations", output["violations"])