Esempio n. 1
0
def move(request, user_id, move_id):
    player = Recipient.getRecipient(int(user_id))
    print(player)
    mechanic = Mechanics.get_mechanic(int(move_id))
    response = mechanic.execute_move(player)
    # Determine if state should change (all players on same move # or time out or done)
    return HttpResponse(json.dumps({"state" : player.game_state(),
                                    "players" : Recipient.active_players,
                                    "donorPool" : int(Mechanics.donor_pool * 100),
                                    "formerPatients" : Recipient.former_patients,
                                    "result" : response}, default=lambda o: o.__dict__, ensure_ascii=False),
                        content_type = "application/json")
Esempio n. 2
0
    def end_day(cls):
        Mechanics.new_day()
        for player in Recipient.active_players:
            player.new_day()
        # anyone left?
        if len(Recipient.active_players) == 0:
            return
        # allocate organ
        factor = Mechanics.donor_pool * max(5, len(Recipient.active_players))/30.0
        if (random.random() <= factor):
            # sort recipients by recipientListImpact
            cls.sort_recipients()
            # HACK: tickets over first 5: 10, 6, 4, 2, 1 = 23
            ticket = random.randrange(23)
            if ticket < 10:
                selection = cls.active_players[0]
            elif len(Recipient.active_players) < 2:
                return
            elif ticket < 16:
                selection = cls.active_players[1]
            elif len(Recipient.active_players) < 3:
                return
            elif ticket < 20:
                selection = cls.active_players[2]
            elif len(Recipient.active_players) < 4:
                return
            elif ticket < 22:
                selection = cls.active_players[3]
            elif len(Recipient.active_players) < 5:
                return
            else:
                selection = cls.active_players[4]
            
            Recipient.former_patients.append(selection)
            Recipient.active_players.remove(selection)

            if (random.random() < selection.rejectionProbability):
                selection.status = 'transplant-dead'
            else:
                selection.status = 'transplant-healed'