Exemplo n.º 1
0
    def find_maxval_spell_sequence(player):
        # sim land in play
        # really need available mana
        from mtgmonte import mtgutils

        land_in_play = player.get_cards_in_play(["Land"])
        nonland_in_hand = player.get_cards_in_hand(["Land"], invert=True)

        land_list = land_in_play
        spell_list = nonland_in_hand

        max_avail_cmc = mtgutils.get_max_avail_cmc(land_list, deck=player.deck)
        cmc_feasible_sequences = mtgutils.get_cmc_feasible_sequences(spell_list, max_avail_cmc)

        if len(cmc_feasible_sequences) == 0:
            sequence = []
            value = 0
        else:
            mana_combos = mtgutils.possible_mana_combinations(land_list, player.deck)
            flags = [mtgutils.can_cast(spell_sequence, mana_combos) for spell_sequence in cmc_feasible_sequences]
            feasible_sequences = ut.compress(cmc_feasible_sequences, flags)
            if len(feasible_sequences) == 0:
                sequence = []
                value = 0
            else:
                # Find best value in feasible solutions
                value_list = [sum([card.get_goldfish_value() for card in combo]) for combo in feasible_sequences]
                index = ut.list_argmax(value_list)
                sequence = feasible_sequences[index]
                value = len(sequence)
        return sequence, value
Exemplo n.º 2
0
 def choose_targets(effects, card, player, valid_targets_list, target_values_list):
     targets_list = []
     effect_value = 0
     for effect, valid_targets, values in zip(effects, valid_targets_list, target_values_list):
         # TODO: Make Intelligent Choice
         # TODO: Disllow casting if targeted spells with illegal targets
         if len(valid_targets) == 0:
             raise Exception("Illegal targets, fail to find should be None")
         idx = ut.list_argmax(values)
         targets_list += [valid_targets[idx]]
         effect_value += values[idx]
     return targets_list, effect_value
Exemplo n.º 3
0
    def play_land(player, method="brute1"):
        r"""
        Returns:
            list: value_list

        CommandLine:
            cd ~/code/mtgmonte
            python -m mtgmonte.mtgmonte --test-play_land
            python -m mtgmonte.mtgmonte --exec-play_land --cmd

        Example:
            >>> # ENABLE_DOCTEST
            >>> from mtgmonte.mtgmonte import *  # NOQA
            >>> decklist_text, mydiff = testdata_deck()
            >>> deck = mtgobjs.load_list(decklist_text, mydiff)
            >>> player = Player(deck)
            >>> rng = np.random
            >>> rng = np.random.RandomState(2)
            >>> player.reset(rng=rng)
            >>> player.initial_draw()
            >>> player.print_state()
            >>> # player.draw_cards(10)
            >>> #[player.play_land(method='naive') for _ in range(3)]
            >>> for tx in range(4):
            >>>     player.untap_step()
            >>>     player.draw_step()
            >>>     player.main_phase1_step()
            >>>     player.print_state()

            # >>> # ----
            # >>> player.play_land()
            # >>> player.print_state()
        """
        if player.verbose >= 1:
            print("+ --- Play Land")

        # Choose best land to play
        land_in_hand = player.get_cards_in_hand(["Land"])
        if len(land_in_hand) == 0:
            if player.verbose >= 2:
                print("Missed land drop")
            return
        else:
            if method == "naive":
                value_list = []
                for land in land_in_hand:
                    if player.turn == 1:
                        if "tap" in land.heuristic_types:
                            value_list += [2]
                        else:
                            value_list += [1]
                    else:
                        value_list += [1]
            elif method == "brute1":
                # See what is the maximum value over all possible lands
                value_list = []
                for land in land_in_hand:
                    future_player = player.copy()
                    future_player.verbose = 0
                    land_ = player.deck.reflect_card_list([land], future_player.deck)[0]
                    future_player.play_card_from_hand(land_)
                    # For now just several turns in the future in a greedy fashion.
                    # Turn this into a dynamic program later
                    total_value = 0
                    for tx in range(4):
                        sequence, value = future_player.find_maxval_spell_sequence()
                        turn_modifier = np.log(2) / np.log(2 + tx)
                        [future_player.play_card_from_hand(card) for card in sequence]
                        future_player.untap_step()
                        total_value += value * turn_modifier
                    # print('total_value = %r' % (total_value,))
                    value_list.append(total_value)
                print("\nChecking value land drops: %r" % (dict(zip(land_in_hand, value_list)),))

            idx = ut.list_argmax(value_list)
            land = land_in_hand[idx]
            player.play_card_from_hand(land)
        if player.verbose >= 3:
            player.print_state()

        """