示例#1
0
def parse(g, line):
    t = line.split("\t")
    if t[0][0] != "/":
        sync(g, t)
        return
    if t[0] == "/TICK":
        bot(g)
        send("/TOCK")
    elif t[0] == "/PRINT":
        log("\t".join(t[1:]))
    elif t[0] == "/RESULTS":
        galconZeroMcts.reportGameOver(g, int(t[4]))
        log("\t".join(t[1:]))
    elif t[0] == "/RESET":
        g.reset()
    elif t[0] == "/SET":
        if t[1] == "YOU":
            g.you = int(t[2])
        elif t[1] == "STATE":
            g.state = t[2]
    elif t[0] == "/USER":
        o = Item(
            n=int(t[1]),
            type="user",
            name=t[2],
            color=int(t[3], 16),
            team=int(t[4]),
            xid=int(t[5]),
            neutral=int(t[1]) == 1,  # TODO: this is probably unstable?
        )
        g.items[o.n] = o
    elif t[0] == "/PLANET":
        o = Item(
            n=int(t[1]),
            type="planet",
            owner=int(t[2]),
            ships=float(t[3]) / 100,
            x=float(t[4]) / 100,
            y=float(t[5]) / 100,
            production=float(t[6]) / 100,
            radius=float(t[7]) / 100,
            neutral=int(t[2]) == 1,  # TODO: this is probably unstable???
        )
        g.items[o.n] = o
    elif t[0] == "/FLEET":
        o = Item(
            n=int(t[1]),
            type="fleet",
            owner=int(t[2]),
            ships=float(t[3]) / 100,
            x=float(t[4]) / 100,
            y=float(t[5]) / 100,
            source=int(t[6]),
            target=int(t[7]),
            radius=float(t[8]) / 100,
            xid=int(t[9]),
        )
        g.items[o.n] = o
    elif t[0] == "/DESTROY":
        n = int(t[1])
        if n in g.items:
            del (g.items[n])
    elif t[0] == "/ERROR":
        log("\t".join(t[1:]))
    else:
        log("unhandled command: " + "\t".join(t))
示例#2
0
def commitAction(action):
    if action.actionType == SEND_ACTION:
        send("/SEND {} {} {}\n".format(action.percent,
                                       action.sourceN, action.targetN))
    elif action.actionType == REDIRECT_ACTION:
        send("/REDIR {} {}\n".format(action.sourceN, action.targetN))