Esempio n. 1
0
        def simulate_win_rate(in_hand_cards,
                              bold_better_list=[],
                              iterate=self.win_rate_sim_iterate):
            win_count = 0
            _remain_card = list(range(0, 52))
            for x in shared_cards:
                _remain_card.pop(_remain_card.index(x))
            for x in in_hand_cards:
                _remain_card.pop(_remain_card.index(x))

            # iterate, simulate unguessed players' cards, shared cards
            for i in range(iterate):
                _remain_card_sim = _remain_card.copy()
                other_players_cards_sim = []

                random.shuffle(_remain_card_sim)
                for _bold_better in bold_better_list:
                    player_cards = random.choice(_bold_better.card_guess)
                    other_players_cards_sim.append(player_cards)
                    for x in player_cards:
                        if x in _remain_card_sim:
                            _remain_card_sim.pop(_remain_card_sim.index(x))

                for player in range(alive_players_num - len(bold_better_list)):
                    player_cards = []
                    player_cards.append(_remain_card_sim.pop())
                    player_cards.append(_remain_card_sim.pop())
                    # player_hand = Hand(player_cards)
                    other_players_cards_sim.append(player_cards)

                shared_cards_sim = shared_cards.copy()
                my_cards_sim = in_hand_cards.copy()
                random.shuffle(_remain_card_sim)
                while len(shared_cards_sim) < 5:
                    shared_cards_sim.append(_remain_card_sim.pop())
                my_cards_shared_cards_sim = my_cards_sim + shared_cards_sim
                # my_hand = Hand(my_cards_sim)

                win = 0
                even = 0
                assert (alive_players_num == len(other_players_cards_sim))
                survive = True
                for other_player_cards_sim in other_players_cards_sim:
                    compare = judge_two(
                        other_player_cards_sim + shared_cards_sim,
                        my_cards_shared_cards_sim)
                    if compare == 0:
                        even += 1
                    if compare == -1:
                        survive = False
                    if compare == 1:
                        win += 1
                if win == alive_players_num:
                    win_count += 1
                # if even, counted as
                elif survive == True:
                    win_count += 1 / (even + 1)

            win_rate = win_count / iterate
            return win_rate
def pickable_simulate_win_rate(guess_card_, iterate=22, alive_players_num=5):
    in_hand_cards = guess_card_.cards
    win_count = 0
    shared_cards = guess_card_.shared_cards
    _remain_card = list(range(0, 52))
    for x in shared_cards:
        _remain_card.pop(_remain_card.index(x))
    for x in in_hand_cards:
        _remain_card.pop(_remain_card.index(x))

    # iterate, simulate unguessed players' cards, shared cards
    for i in range(iterate):
        _remain_card_sim = _remain_card.copy()
        other_players_cards_sim = []

        random.shuffle(_remain_card_sim)

        for player in range(alive_players_num):
            player_cards = []
            player_cards.append(_remain_card_sim.pop())
            player_cards.append(_remain_card_sim.pop())
            # player_hand = Hand(player_cards)
            other_players_cards_sim.append(player_cards)

        shared_cards_sim = shared_cards.copy()
        my_cards_sim = in_hand_cards.copy()
        random.shuffle(_remain_card_sim)
        while len(shared_cards_sim) < 5:
            shared_cards_sim.append(_remain_card_sim.pop())

        my_cards_shared_cards_sim = my_cards_sim + shared_cards_sim
        # my_hand = Hand(my_cards_sim)

        win = 0
        even = 0
        assert (alive_players_num == len(other_players_cards_sim))
        survive = True
        for other_player_cards_sim in other_players_cards_sim:
            compare = judge_two(other_player_cards_sim + shared_cards_sim,
                                my_cards_shared_cards_sim)
            if compare == 0:
                even += 1
            if compare == -1:
                survive = False
            if compare == 1:
                win += 1
        if win == alive_players_num:
            win_count += 1
        # if even, counted as
        elif survive == True:
            win_count += 1 / (even + 1)

    win_rate = win_count / iterate
    guess_card_.win_rate = win_rate
    return guess_card_
    def simulate_win_rate(inhand_cards, other_player_cards=[], iterate=1000):
        win_count = 0
        _remain_card = list(range(0, 52))
        for x in shared_cards:
            _remain_card.pop(_remain_card.index(x))
        for x in inhand_cards:
            _remain_card.pop(_remain_card.index(x))

        for i in range(iterate):
            heap = _remain_card.copy()
            other_player_cards_sim = []

            random.shuffle(heap)
            for player in range(len(other_player_cards)):
                player_cards = random.choice(other_player_cards[player])
                other_player_cards_sim.append(player_cards)
                for x in player_cards:
                    if x in heap:
                        heap.pop(heap.index(x))

            for player in range(len(alive_players) - len(other_player_cards)):
                player_cards = []
                player_cards.append(heap.pop())
                player_cards.append(heap.pop())
                # player_hand = Hand(player_cards)
                other_player_cards_sim.append(player_cards)

            shared_cards_sim = shared_cards.copy()
            my_cards_sim = inhand_cards.copy()
            random.shuffle(heap)
            while len(shared_cards_sim) < 5:
                shared_cards_sim.append(heap.pop())
            my_cards_sim = my_cards_sim + shared_cards_sim
            # my_hand = Hand(my_cards_sim)
            # other_player = []

            score = 0
            even = 0
            assert (len(alive_players) == len(other_player_cards_sim))
            for player in range(len(alive_players)):
                compare = judge_two(
                    my_cards_sim,
                    other_player_cards_sim[player] + shared_cards_sim)
                if compare == 0:
                    even += 1
                score += compare
            if score == -len(alive_players):
                win_count += 1
            if even == alive_players:
                win_count += 0.5

        win_rate = win_count / iterate
        return win_rate
Esempio n. 4
0
	def simulate_win_rate(inhand_cards, other_player_cards = []):
		win_count = 0
		_remain_card = list(range(0, 52))
		for x in shared_cards:
			_remain_card.pop(remain_card.index(x))
		for x in inhand_cards:
			_remain_card.pop(remain_card.index(x))

		for i in range(1000):
			score = 0
			for player in range(len(alive_players)):
				player_cards = []
				if len(other_player_cards) == 0:
					player_cards.append(heap.pop())
					player_cards.append(heap.pop())
					player_cards = player_cards
					# player_hand = Hand(player_cards)
					other_player_cards.append(player_cards)

				else:
					pass
					# player_hand = other_player_cards[player].

			shared_cards_sim = shared_cards
			my_cards_sim = inhand_cards
			heap = remain_card[:]
			random.shuffle(heap)
			while len(shared_cards_sim) < 5:
				shared_cards_sim.append(heap.pop())
			my_cards_sim = my_cards_sim + shared_cards
			# my_hand = Hand(my_cards_sim)
			# other_player = []


			score += judge_two(my_cards_sim, player_cards)
			if score == -len(alive_players):
				win_count += 1

		win_rate = win_count / 1000

		return win_rate
Esempio n. 5
0
        def rank_with_shared_card(hand_cards1, hand_cards2):

            result = judge_two(
                list(hand_cards1) + _shared_cards,
                list(hand_cards2) + _shared_cards)
            return result