-
Notifications
You must be signed in to change notification settings - Fork 6
/
hg_agent.py
90 lines (84 loc) · 1.91 KB
/
hg_agent.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
import socket, random, time, json, sys
sys.stdout.write("INITIALIZING!!!!!")
print("INITIALIZING")
AGENT_HOST = "127.0.0.1"
AGENT_PORT = 9000
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((AGENT_HOST, AGENT_PORT))
command_stream = [
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move q",
"smooth_move q",
"smooth_turn 90",
"smooth_move w",
"smooth_move w",
"smooth_move e",
"smooth_move e",
"smooth_move e",
"smooth_move e",
"smooth_move e",
"smooth_move w",
"smooth_move d",
"smooth_move d",
"smooth_move d",
"smooth_move d",
"smooth_move d",
"smooth_move d",
"smooth_move d",
"smooth_move d",
"smooth_move d",
"smooth_move d",
"smooth_move d",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move w",
"smooth_move q",
"smooth_move w",
"smooth_move w",
"smooth_tilt down",
"smooth_move w",
"place_macguffin",
"smooth_move d",
"CHAT give up"
]
reset = False
while True:
for command in command_stream:
sock.send(str.encode(command + '\n'))
print(command)
BUFF_SIZE = 4096 # 4 KiB
data = b''
while True:
part = sock.recv(BUFF_SIZE)
data += part
if len(part) < BUFF_SIZE:
# either 0 or end of data
break
data_dict = json.loads(data)
print(data_dict)
time.sleep(0.02)
sock.close()
print("Socket closed")