def add_card(self, state): possible_cards = self.adding_card_options(state.table) if possible_cards: card_to_add = choose_min_card(possible_cards, state.trump_card.suit) return self.add_card_helper(card_to_add, state) self.no_cards_msg(state)
def attack(self, state): possible_cards = self.get_attack_options(state.table) if len(state.deck.get_cards()) == 0: if len(possible_cards) == 0: return None attack_card = self.minmax_agent.get_action(state) if attack_card is None: attack_card = choose_min_card(possible_cards, state.trump_card.suit) return self.attack_helper(attack_card, state) if len(possible_cards) == 0: return None attack_card = choose_min_card(possible_cards, state.trump_card.suit) return self.attack_helper(attack_card, state)
def defend(self, state): possible_cards = self.get_defence_options(state.table, state.trump_card.suit) if possible_cards: defence_card = choose_min_card(possible_cards, state.trump_card.suit) return self.defence_helper(defence_card, state) self.no_defence(state)
def attack(self, state): if len(state.deck.playerCards) == 0: possible_cards = self.get_attack_options(state.table) if len(possible_cards) == 0: return None attack_card = random.choice(possible_cards) return self.attack_helper(attack_card, state) possible_cards = self.get_attack_options(state.table) if len(possible_cards) == 0: return None attack_card = choose_min_card(possible_cards, state.trump_card.suit) return self.attack_helper(attack_card, state)
def add_card(self, state): if len(state.deck.playerCards) == 0: if self.adding_card_options(state.table): card_to_add = random.choice( self.adding_card_options(state.table)) return self.add_card_helper(card_to_add, state) self.no_cards_msg(state) possible_cards = self.adding_card_options(state.table) if possible_cards: card_to_add = choose_min_card(possible_cards, state.trump_card.suit) return self.add_card_helper(card_to_add, state) self.no_cards_msg(state)
def defend(self, state): possible_cards = self.get_defence_options(state.table, state.trump_card.suit) if len(state.deck.cards) == 0: if possible_cards: defence_card = self.minmax_agent.get_action(state) if defence_card is None: defence_card = choose_min_card(possible_cards, state.trump_card.suit) if defence_card is not None: return self.defence_helper(defence_card, state) self.no_defence(state) return self.q_learning_defence(possible_cards, state)
def defend(self, state): possible_cards = self.get_defence_options(state.table, state.trump_card.suit) if len(state.deck.playerCards) == 0: if possible_cards: defence_card = random.choice( self.get_defence_options(state.table, state.trump_card.suit)) return self.defence_helper(defence_card, state) self.no_defence(state) if possible_cards: defence_card = choose_min_card(possible_cards, state.trump_card.suit) return self.defence_helper(defence_card, state) self.no_defence(state)
def add_card(self, state): if len(state.deck.get_cards()) == 0: possible_cards = self.adding_card_options(state.table) if possible_cards: card_to_add = self.minmax_agent.get_action(state) if card_to_add is not None: self.add_card_helper(card_to_add, state) self.no_cards_msg(state) possible_cards = self.adding_card_options(state.table) if possible_cards: card_to_add = choose_min_card(possible_cards, state.trump_card.suit) return self.add_card_helper(card_to_add, state) self.no_cards_msg(state)
def getFeatures(self, state, action): features = Util.Counter() trump_suit = state.trump_card.suit player_hand = state.current_player.get_cards() amount_cards = len(state.current_player.get_cards()) suit_dict = self.get_suit_dict(player_hand) features["amount_trump"] = sum(1 for card in player_hand if card.suit == trump_suit) / \ amount_cards if amount_cards != 0 else 0 features["mean_number"] = sum(card.number for card in player_hand) / amount_cards features["variance_number"] = sum((features["mean_number"] - card.number) ** 2 for card in player_hand) / \ amount_cards variance_mean = sum(suit_dict.values()) / 4 features["variance_suit"] = sum((variance_mean - num_suit)**2 for num_suit in suit_dict.values()) / 4 features["cards_diff"] = ( len(state.current_player.get_opponent(state).get_cards()) - len(state.current_player.get_cards())) / 36 features["is_card_minimum"] = 1 if action == choose_min_card( state.current_player.options(state.table, state.trump_card.suit), state.trump_card.suit) else 0 if len(state.deck.get_cards()) < 6: features["cards_on_hand"] = -amount_cards / ( 36 * (len(state.deck.get_cards()) + 1)) if len(state.deck.get_cards()) == 0: opponent_hand = state.current_player.get_opponent( state).get_cards() self_suit_means = self.get_suit_means(player_hand) opponent_suit_means = self.get_suit_means(opponent_hand) features["amount_trump_opponent"] = -sum(1 for card in opponent_hand if card.suit == trump_suit) / \ len(opponent_hand) if len(opponent_hand) != 0 else 0 hearts_mean_diff = self_suit_means[0] - opponent_suit_means[0] spades_mean_diff = self_suit_means[1] - opponent_suit_means[1] diamnods_mean_diff = self_suit_means[2] - opponent_suit_means[2] clubs_mean_diff = self_suit_means[3] - opponent_suit_means[3] features["suits_means_diff"] = ( hearts_mean_diff + spades_mean_diff + diamnods_mean_diff + clubs_mean_diff) / 4 self_trumps = [ card.number for card in player_hand if card.suit == trump_suit ] enemy_trumps = [ card.number for card in opponent_hand if card.suit == trump_suit ] highest_self_trump = max( self_trumps) if len(self_trumps) != 0 else 0 highest_enemy_trump = max( enemy_trumps) if len(enemy_trumps) != 0 else 0 features[ "highest_trump"] = 1 if highest_self_trump > highest_enemy_trump else -1 return features
def attack(self, state): possible_cards = self.get_attack_options(state.table) if len(possible_cards) == 0: return None attack_card = choose_min_card(possible_cards, state.trump_card.suit) return self.attack_helper(attack_card, state)