diff --git a/backend/static/bot/runner.py b/backend/static/bot/runner.py index 014379f..f583cc1 100755 --- a/backend/static/bot/runner.py +++ b/backend/static/bot/runner.py @@ -17,7 +17,7 @@ def execute(cmd): def connect(host, port, id): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, port)) - s.sendall(f"{id}\n".encode("utf8")) + s.sendall(f"{json.dumps(id)}\n".encode("utf8")) return s def handle_input(it, socket): @@ -30,13 +30,15 @@ def main(): help='The bot\'s ID') parser.add_argument('--host', default="localhost", help='What host to connect to') - parser.add_argument('--port', '-p', default=9142, type=int, + parser.add_argument('--port', '-p', default=6666, type=int, help='What port to connect to') + parser.add_argument('--name', '-n', + help='Who are you?') parser.add_argument('arguments', nargs=argparse.REMAINDER, help='How to run the bot') args = parser.parse_args() - sock = connect(args.host, args.port, args.id) + sock = connect(args.host, args.port, {"id": int(args.id), "name": args.name}) f = sock.makefile("rw") it = execute(args.arguments) @@ -47,10 +49,15 @@ def main(): line = f.readline() content = "Nothing" while line: + print(line) content = json.loads(line) if content["type"] == "game_state": stdin.write(json.dumps(content["content"])+"\n") stdin.flush() + if content["type"] == "player_action": + if content["content"]["type"] == "parse_error": + sys.stderr.write(content["content"]["value"] + '\n') + sys.stderr.flush() line = f.readline() print(content) diff --git a/client/game_start.json b/client/game_start.json index 7a8d5d8..a83020d 100644 --- a/client/game_start.json +++ b/client/game_start.json @@ -1,2 +1,2 @@ -{"nop":2,"name":"Bexit","map":"maps/hex.json","max_turns":200} +{"nop":3,"name":"It stole my heart","map":"maps/love.json","max_turns":2000} diff --git a/client/run.sh b/client/run.sh index 761b1b1..8b4dad1 100755 --- a/client/run.sh +++ b/client/run.sh @@ -1,4 +1,4 @@ #!/bin/bash echo "Using token $1" -python runner.py --host ${HOST:-localhost} -p 9142 -i $1 python simple.py +python runner.py -n simple.py --host ${HOST:-localhost} -p 9142 -i $1 python simple.py diff --git a/client/runner.py b/client/runner.py index c3c18f9..f583cc1 100755 --- a/client/runner.py +++ b/client/runner.py @@ -32,7 +32,7 @@ def main(): help='What host to connect to') parser.add_argument('--port', '-p', default=6666, type=int, help='What port to connect to') - parser.add_argument('--name', '-n', default="Silvius", + parser.add_argument('--name', '-n', help='Who are you?') parser.add_argument('arguments', nargs=argparse.REMAINDER, help='How to run the bot')