hlynurd / open-mtg

A python implementation of Magic: The Gathering with an AI that plays it using Monte Carlo move evaluation.
MIT License
140 stars 32 forks source link

MCTS shuffle is wrong #7

Open Meerkov opened 6 years ago

Meerkov commented 6 years ago

https://github.com/hlynurd/open-mtg/blob/8ad261f255859e90a93c446551911278eeec3cae/mcts.py#L74

# the mcts rollouts don't randomize cards that have been seen with Index
        indexed_cards_in_deck = []
        # print("mcts print: %s" % (state.players))

        if len(state.players[k].deck) > 0:
            while len(state.players[k].deck) > 0 and state.players[k].deck[-1].deck_location_known:
                indexed_cards_in_deck.append(state.players[k].deck.pop())
        for indexed_card in indexed_cards_in_deck:
            state.players[k].deck.append(indexed_card)
# and "imagine" a scenario for the opponent - this assumes knowledge of opponent decklist!

state.players[k].shuffle_deck()

This currently looks at my deck, finds the cards that are indexed, puts them in "indexed_cards_in_deck". Then it takes "indexed_cards_in_deck" and puts them BACK into my deck.

Then it shuffles the deck.

This code doesn't do anything.

Meerkov commented 6 years ago

More specifically, it just hurts the AI because it will not actually know the location of the cards it should.

state.players[k].shuffle_deck() should be 4 lines up.

hlynurd commented 6 years ago

+1, this MCTS needs to remember what it knows after casting Index