def schedule(cls, game):
        # Only two players
        candidates = game.submission_set.filter(
            active=True, user__is_active=True).order_by("count")

        if len(candidates) < 2:
            print "Insufficient candidates"
            yield Scheduler.Task()

        for i in range(RUN_COUNT):
            for player1 in candidates:
                for player2 in candidates:
                    if player1.user == player2.user: continue

                    players = [player1, player2]

                    yield Scheduler.GameRunTask(game.cls, *players)
Beispiel #2
0
    def schedule(cls, game):
        while True:
            # Only two players
            candidates = game.submission_set.filter(active=True, user__is_active = True).order_by("count")

            if len(candidates) < 2:
                print "Insufficient candidates"
                yield Scheduler.Task()

            # Choose min candidate
            player1 = candidates[0]

            # And play against everyone else
            for player2 in candidates:
                if player1.user == player2.user: continue

                players = [player1, player2]
                yield Scheduler.GameRunTask(game.cls, *players)

                players = [player2, player1]
                yield Scheduler.GameRunTask(game.cls, *players)
    def schedule(cls, game):
        while True:
            # Only two players
            candidates = game.submission_set.filter(
                active=True, user__is_active=True).order_by("count")

            # If no candidates, just return a 'waste-time' task
            if len(candidates) < 2:
                print "Insufficient candidates"
                yield Scheduler.Task()
                continue

            player1 = candidates[0]
            candidates_ = [c for c in candidates[1:] if c.user != player1.user]
            players = [player1, random.choice(candidates_)]

            # Choose a start position at random
            random.shuffle(players)

            print "%s chosen from %d candidates" % (players, len(candidates))

            yield Scheduler.GameRunTask(game.cls, *players)