Example #1
0
    def get_legal_actions(self):
        self.play_treasures()
        coins = self.coins

        cards_purchasable = dominion_utils.get_purchaseable_cards(self, coins, self.kingdom)

        return cards_purchasable
Example #2
0
    def buy_phase(self):
        assert self.num_buys >= 0
        if self.num_buys == 0:
            # "None" is not pass - to skip a buy would be Card(-1)
            return None

        self.play_treasures()

        purchaseable_cards = dominion_utils.get_purchaseable_cards(
            self, self.coins, self.kingdom)

        max_action = None
        max_action_val = float("-inf")

        for e in purchaseable_cards:
            state_features = dominion_utils.state_features(
                self, self.kingdom, e)
            action_val = self.model(state_features)

            print(e.name, action_val.item())

            if action_val > max_action_val:
                max_action = e
                max_action_val = action_val

        assert max_action is not None

        # max_action = dominion_utils.force_buy(9, self, max_action)

        dominion_utils.buy_card(self, max_action, self.kingdom)

        return max_action
Example #3
0
    def gain_card_up_to(self, limit):
        # todo use buy policy to choose which to gain
        # todo eventually make this its own policy? or at least update q values based on this choice
        # todo make this a dominion_util function we can call in both dominion_agent.py and agent.py

        gainable = dominion_utils.get_purchaseable_cards(self, limit, self.kingdom, True)
        card_to_gain = random.choice(gainable)
        dominion_utils.gain_card(self, card_to_gain, self.kingdom)
Example #4
0
    def buy_phase(self):
        self.play_treasures()
        coins = self.coins

        cards_purchasable = dominion_utils.get_purchaseable_cards(
            self, coins, self.kingdom)

        bought_card = random.choice(cards_purchasable)
        dominion_utils.buy_card(self, bought_card, self.kingdom)
Example #5
0
def get_purchaseable_cards():
    global kingdom, person, agent
    person.play_treasures()
    purchaseable_cards = dominion_utils.get_purchaseable_cards(
        person, person.coins, kingdom)
    purchaseable_cards_data = dominion_utils.serialize_cards(
        purchaseable_cards)

    data = {
        "purchaseable": purchaseable_cards_data,
        "in_play": dominion_utils.serialize_cards(person.in_play),
        "hand": dominion_utils.serialize_cards(person.hand),
        "num_coins": person.coins
    }
    resp = Response(json.dumps(data), status=200, mimetype='application/json')
    return resp
Example #6
0
    def __init__(self, type, person, props=None):
        self.gain_card_limit = None
        self.gainable_cards = []
        self.new_handsize = None
        self.reminaing = 0

        self.type = type
        if type == 1:
            # Gain card up to
            self.gain_card_limit = props["gain_card_limit"]
            self.gainable_cards = dominion_utils.get_purchaseable_cards(
                person, self.gain_card_limit, person.kingdom, True)
            self.remaining = 1
            # todo add None option
        elif type == 2:
            # Discard down to
            self.new_handsize = props["handsize"]
            self.remaining = len(person.hand) - self.new_handsize
Example #7
0
 def gain_card_up_to(self, limit):
     gainable = dominion_utils.get_purchaseable_cards(
         self, limit, self.kingdom, True)
     card_to_gain = random.choice(gainable)
     dominion_utils.gain_card(self, card_to_gain, self.kingdom)