change runner.py + index page to reflect this change

This commit is contained in:
ajuvercr 2020-04-02 15:29:49 +02:00
parent e0405bc33b
commit 390d4a01ab
3 changed files with 4 additions and 69 deletions

View file

@ -1,66 +0,0 @@
#! /usr/bin/env python
import socket, sys, subprocess, argparse, io, threading, json
def execute(cmd):
popen = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True)
yield(popen.stdin)
for stdout_line in iter(popen.stdout.readline, "\n"):
yield stdout_line
popen.stdout.close()
return_code = popen.wait()
if return_code:
raise subprocess.CalledProcessError(return_code, cmd)
def connect(host, port, id):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.sendall(f"{json.dumps(id)}\n".encode("utf8"))
return s
def handle_input(it, socket):
for line in it:
socket.sendall(line.encode('utf8'))
def main():
parser = argparse.ArgumentParser(description='Run MOZAIC bot')
parser.add_argument('--id', '-i', required=True,
help='The bot\'s ID')
parser.add_argument('--host', default="localhost",
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',
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, {"id": int(args.id), "name": args.name})
f = sock.makefile("rw")
it = execute(args.arguments)
stdin = next(it)
threading.Thread(target=lambda: handle_input(it, sock), daemon=True).start()
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)
if __name__ == "__main__":
main()

View file

@ -0,0 +1 @@
../../../client/runner.py

View file

@ -54,7 +54,7 @@
<p>Build a bot! All information about the planetwars game, <a target="_blank" href="https://docs.google.com/presentation/d/1YXr7IsmEiBpRwgAoFPqsjFoKoyXOv9LAhPbsambGX70/edit?usp=sharing">please visit</a> for input output format etc. You can find an example bot <a href="bot/simple.py">here</a>.</p>
<p>Optionally, you can create your own custom with the mapbuilder</p>
<p>Start a game instance in the lobby, don't forget to name it, watching the visualization afterwars is the only way to know who won atm.</p>
<p>Start up your bot and connect to the game instance. In the lobby you will see keys corresponding to players in the game. You can use <a href="bot/runner.py">the botrunner</a> to run your bot, with the command <span style="font-style: italic;">python runner.py --host mozaic.zeus.gent -i {your key} {The command to start you bot}</span>.
<p>Start up your bot and connect to the game instance. In the lobby you will see keys corresponding to players in the game. You can use <a href="bot/runner.py">the botrunner</a> to run your bot, with the command <span style="font-style: italic;">python runner.py --host mozaic.zeus.gent -n {your name} -i {your key} {The command to start you bot}</span>.
<p>Invite friends!</p>
<p>Bash your friends because you have the superior bot, according to the visualizer</p>
</div>

View file

@ -30,9 +30,9 @@ 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=6666, type=int,
parser.add_argument('--port', '-p', default=9142, type=int,
help='What port to connect to')
parser.add_argument('--name', '-n',
parser.add_argument('--name', '-n', required=True,
help='Who are you?')
parser.add_argument('arguments', nargs=argparse.REMAINDER,
help='How to run the bot')