Esempio n. 1
0
    def finish(self):
        worldData = self.w.to_dict()
        worldData['id'] = self.game_id
        worldData['time'] = -1
        self.mc[self.game_id].update({}, worldData, upsert=True)
        print 'FINISHING'

        models = self.models
        testmode = self.testmode
        nrobots = self.nrobots
        procs = self.procs
        tournament = self.tournament

        alive = [model for model in models.values() if model.alive]
        if not testmode and len(alive)==1:
            model = alive[0]
            print 'WINNER:', model.name
            winner = model
            model._kills = nrobots-1
        elif not testmode:
            winner = None
            if self.rnd >= conf.maxtime*60:
                print 'Battle stopped after maximum time:', conf.maxtime, 'seconds.'
            else:
                print 'Battle stopped after', int(self.rnd/60), 'seconds.'
            print 'STILL ALIVE:'
            for model in alive:
                print '   ', model.name
        else:
            winner = None

        for robotname, model in models.items():
            print robotname, 'caused', model._damage_caused, 'damage'
            if robotname in procs:
                line = 'FINISH\n'
                proc = procs[robotname]
                proc.stdin.write(line)
                proc.stdin.flush()
                proc.stdin.close()
                proc.stdout.close()
                del procs[robotname]

            if winner is None and model.alive:
                model._kills = nrobots - len(alive)

            if model == winner:
                win = 1
            else:
                win = 0

            if not testmode:
                stats.update(model.kind, win, nrobots-1, model._kills,
                                model._damage_caused)

            if tournament is not None:
                stats.tournament_update(tournament, model.kind, model.name, win,
                                                nrobots-1, model._kills,
                                                model._damage_caused)
Esempio n. 2
0
    def finish(self):
        print 'FINISHING'

        models = self.models
        testmode = self.testmode
        ntanks = self.ntanks
        procs = self.procs
        tournament = self.tournament

        alive = [model for model in models.values() if model.alive]
        if not testmode and len(alive)==1:
            model = alive[0]
            print 'WINNER:', model.name
            winner = model
            model._kills = ntanks-1
        elif not testmode:
            winner = None
            if self.rnd >= conf.maxtime*60:
                print 'The battle finished after maximum time:', conf.maxtime, 'seconds.'
            else:
                print 'The battle finished after', int(self.rnd/60), 'seconds.'
            print 'STILL ALIVE:'
            for model in alive:
                print '   ', model.name
        else:
            winner = None

        for tankname, model in models.items():
            print tankname, 'caused', model._damage_caused, 'damage'
            if tankname in procs:
                line = 'FINISH\n'
                proc = procs[tankname]
                proc.stdin.write(line)
                proc.stdin.flush()
                proc.stdin.close()
                proc.stdout.close()
                del procs[tankname]

            if winner is None and model.alive:
                model._kills = ntanks - len(alive)

            if model == winner:
                win = 1
            else:
                win = 0

            if not testmode:
                stats.update(model.kind, win, ntanks-1, model._kills,
                                model._damage_caused)

            if tournament is not None:
                stats.tournament_update(tournament, model.kind, model.name, win,
                                                ntanks-1, model._kills,
                                                model._damage_caused)
Esempio n. 3
0
    def finish(self, update_stats=True):
        print 'FINISHING'
        if hasattr(self, '_FINISHED'):
            print 'ALREADY FINISHED'
            return
        self._FINISHED = True

        models = self.models
        testmode = self.testmode
        nrobots = self.nrobots
        procs = self.procs
        tournament = self.tournament

        alive = [model for model in models.values() if model.alive]
        if not testmode and len(alive)==1:
            model = alive[0]
            print 'WINNER:', model.name
            winner = model
            model._outlasted = nrobots-1
        elif not testmode:
            winner = None
            if self.rnd >= conf.maxtime*60:
                print 'Battle stopped after maximum time:', conf.maxtime, 'seconds.'
            else:
                print 'Battle stopped after', int(self.rnd/60), 'seconds.'
            print 'STILL ALIVE:'
            for model in alive:
                print '   ', model.name
        else:
            print 'Test mode ended'
            winner = None

        for robotname, model in models.items():
            print robotname, 'caused', model._damage_caused, 'damage'
            if robotname in procs:
                line = 'FINISH\n'
                proc = procs[robotname]
                proc.stdin.write(line)
                proc.stdin.flush()
                proc.stdin.close()
                proc.stdout.close()
                del procs[robotname]

            if winner is None and model.alive:
                model._outlasted = nrobots - len(alive)

            if model == winner:
                win = 1
            else:
                win = 0

            if update_stats and not testmode:
                stats.update(model.kind, win, nrobots-1, model._outlasted,
                                model._damage_caused, model._kills)

            if update_stats and tournament is not None:
                stats.tournament_update(tournament,
                                            model.kind, model.name, win,
                                            nrobots-1, model._outlasted,
                                            model._damage_caused,
                                            model._kills)