Esempio n. 1
0
    def run(self):
        """
        Server start
        """
        while True:
            stacks = self.get_stacks()
            if not stacks:
                sleep(60)
                continue

            for stack in stacks:
                result = Robot.run(stack)
                self.send_result({'stack': stack, 'result': result})
Esempio n. 2
0
async def main():
    opts = Options(sys.argv)

    r = Robot(**opts.args())
    try:
        if opts.id is None:
            """Create new game if id was not specified"""

            opts.id = await r.newgame()
        else:
            """Check if game exists"""

            if opts.id != await r.checkgame(opts.id):
                print('Game id miss-matched', file=sys.stderr)
                sys.exit(2)

    except Exception as e:
        print(f'Failed to acquire game: {e}')
        sys.exit(3)

    if opts.robots:
        rbs = [r]
        wrk = [ensure_future(r.run(pnum=opts.autoplay))]

        await sleep(0.2)  # Leader process should be able to reset game

        for i in range(1, opts.robots):
            r = Robot(uri=opts.site, idx=i, id=opts.id)
            rbs.append(r)
            wrk.append(ensure_future(r.run()))

        await gather(*wrk)
        results(wrk[0].result(), [r.pname for r in rbs],
                [r.id_prefix for r in rbs])
    else:
        res = await r.run(pnum=opts.autoplay)
        results(res)