forked from StanfordPL/stoke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
57 lines (40 loc) · 1.09 KB
/
client.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import socket
import random
class RandomAgent:
def act(self):
return random.randint(0, 2)
class StokeEnv:
def __init__(self):
pass
def reset(self):
pass
def _recv_all(self):
ret = ""
while True:
response = self.sock.recv(1024).decode()
if not response:
break
ret += response
return ret
def step(self, action):
print("***ACTION***")
print(action)
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.connect(('localhost', 8080))
self.sock.sendall((str(action) + "\n").encode())
ret = self._recv_all()
self.sock.close()
print("***OBSERVATON*** ")
print(ret)
return ret
def close(self):
self.sock.close()
if __name__ == "__main__":
# docker.exec_run("stoke_server start")
env = StokeEnv()
env.reset()
agent = RandomAgent()
for i in range(10):
action = agent.act()
env.step(action)
env.close()