-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay.py
51 lines (43 loc) · 1.31 KB
/
play.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
import time
import json
from websocket import create_connection
import variables
from utils import init_logger
import logging
from agent import takeAction
import sys
import traceback
ws = ""
def doListen():
try:
global ws
ws = create_connection(variables.url)
ws.send(json.dumps({
"eventName": "join",
"data": {
"playerName": variables.player_name,
"playerNumber": variables.player_number,
"token": variables.token
}
}))
while True:
result = ws.recv()
msg = json.loads(result)
takeAction(ws, msg)
except Exception as e:
logging.error(e)
logging.error(traceback.format_exc())
doListen()
if __name__ == '__main__':
init_logger()
logging.debug('arg:{} len:{}'.format(sys.argv,len(sys.argv)))
if len(sys.argv) == 5:
variables.player_name=sys.argv[1]
variables.player_number=sys.argv[2]
variables.token=sys.argv[3]
variables.url=sys.argv[4]
logging.debug('player_name:{} player_number:{} token:{} url:{}'.format(variables.player_name,variables.player_number,variables.token,variables.url))
try:
doListen()
except KeyboardInterrupt:
logging.error("Exit by keyboard")