update bot scripts

This commit is contained in:
ajuvercr 2020-04-02 14:52:48 +02:00
parent 463a40c3fb
commit e0405bc33b
4 changed files with 13 additions and 6 deletions

View file

@ -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)

View file

@ -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}

View file

@ -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

View file

@ -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')