def findLowestPointsCard(self, state): smallestRank = None possibleRanks = ["A", "10", "K", "Q", "J"] position = None moves = state.moves() if len(moves) > 0: for index, move in enumerate(moves): # Iterate through all the possible moves, and find the lowest value card in your hand # Check whether 'J' is in your hand, if so play the card if Deck.get_rank(moves[index][0]) == possibleRanks[4]: smallestRank = possibleRanks[4] position = index break # Otherwise check for a Queen, and keep on checking maybe the Jack will be found later elif Deck.get_rank(moves[index][0]) == possibleRanks[3]: smallestRank = possibleRanks[3] position = index # and so forth elif Deck.get_rank( moves[index][0] ) == possibleRanks[2] and smallestRank != possibleRanks[3]: smallestRank = possibleRanks[2] position = index elif Deck.get_rank(moves[index][0]) == possibleRanks[1] and smallestRank != possibleRanks[2] \ and smallestRank != possibleRanks[3]: smallestRank = possibleRanks[3] position = index elif Deck.get_rank(moves[index][0]) == possibleRanks[0] and smallestRank != possibleRanks[1] \ and smallestRank != possibleRanks[2] and smallestRank != possibleRanks[3]: smallestRank = possibleRanks[4] position = index return position
def findLowestCardOfSameSuit(self, state): lowestRank = None position = None # All possible moves moves = state.moves() # Opponents card suit opponentsCardSuit = Deck.get_suit(state.get_opponents_played_card()) moves_suit = [] # Get all the moves available with the same suit as opponent's played card suit for index, move in enumerate(moves): if moves[index][0] is not None and Deck.get_suit( moves[index][0]) == opponentsCardSuit: moves_suit.append(move) # Check your hand for same suit cards as opponent # If opponent's card rank is '10' check for lowest value card which is 'J' if len(moves_suit) > 0: for index, move in enumerate(moves_suit): if Deck.get_rank(moves_suit[index][0]) == "J" \ and Deck.get_suit(moves_suit[index][0]) == opponentsCardSuit: lowestRank = "J" break # otherwise check for the next lowest value which is 'Q' elif Deck.get_rank(moves_suit[index][0]) == "Q" \ and Deck.get_suit(moves_suit[index][0]) == opponentsCardSuit: lowestRank = "Q" # and so forth elif Deck.get_rank(moves_suit[index][0]) == "K" \ and Deck.get_suit(moves_suit[index][0]) == opponentsCardSuit \ and lowestRank != "Q": lowestRank = "K" # also this function will not play high value cards like '10' and 'A' # becaues in our strategy we are saving the high value card for future # possible cases when we could win the hand # If there is such a card with a smaller value than the opponent's # played card and of the same suit, return the index for index, move in enumerate(moves): if Deck.get_rank(moves[index][0]) == lowestRank \ and Deck.get_suit(moves[index][0]) == opponentsCardSuit: position = index break return position
def checkForMarriage(self, state): position = None moves = state.moves() chosen_suit = [] trumpSuit = state.get_trump_suit() queens = [] kings = [] # Get all queens and kings from the possible moves for index, move in enumerate(moves): if moves[index][0] is not None and Deck.get_rank( moves[index][0]) == "Q": queens.append(move[0]) elif moves[index][0] is not None and Deck.get_rank( moves[index][0]) == "K": kings.append(move[0]) isLooping = True if len(queens) and len(kings) > 0: for index, move in enumerate(queens): for index2, move2 in enumerate(kings): # if a Queen and a King of same suit has been found return the suit of that Queen # also first prioritize the Royal Marriage if Deck.get_suit(queens[index]) == Deck.get_suit(kings[index2]) \ and Deck.get_suit(queens[index]) == trumpSuit: chosen_suit = Deck.get_suit(queens[index]) # variable used to break out of a nested loop isLooping = False break elif Deck.get_suit(queens[index]) == Deck.get_suit( kings[index2]): chosen_suit = Deck.get_suit(queens[index]) isLooping = False break if isLooping == False: break # if such a Marriage exists in the possible moves return the index of that Queen for index, move in enumerate(moves): if moves[index][0] is not None \ and Deck.get_suit(moves[index][0]) == chosen_suit \ and Deck.get_rank(moves[index][0]) == "Q": position = index return position
def get_rank(card_index): """ Returns the rank of a card :param card_index: :return: """ return Deck.get_rank(card_index)
def kb_consistent(self, state, move): # type: (State, move) -> bool index = move[0] if (Deck.get_suit(index) == state.get_trump_suit()): return True if (Deck.get_rank(index) == "A"): return False kb = self.prepareKB(state) load.strategy_knowledge(kb) variable_string = "pc" + str(index) strategy_variable = Boolean(variable_string) kb.add_clause(~strategy_variable) return kb.satisfiable()
def kb_consistent(self, state, move): # type: (State, move) -> bool index = move[0] # If a card is chosen by the KB, it will be played, doesn't matter if it is a trump # This will be an extremely rare case, possibility of this happening is very low if (Deck.get_rank(index) == "A"): return False kb = self.prepareKB(state) load.strategy_knowledge(kb) variable_string = "pc" + str(index) strategy_variable = Boolean(variable_string) kb.add_clause(~strategy_variable) return kb.satisfiable()
def get_move(self, state): moves = state.moves() random.shuffle(moves) for move in moves: if not self.kb_consistent(state, move): # Plays the first move that makes the kb inconsistent. We do not take # into account that there might be other valid moves according to the strategy. # Uncomment the next line if you want to see that something happens. # print "Strategy Applied" print(str(Deck.get_rank(move[0]) + Deck.get_suit(move[0])), " has been played") #str(Deck.get_rank(move[0]) + Deck.get_suit(move[0])) return move # If no move that is entailed by the kb is found, play random move return random.choice(moves)
def findLowestPointsCardThatIsNotTrump(self, state): moves = state.moves() smallestRank = None possibleRanks = ["A", "10", "K", "Q", "J"] position = None trumpSuit = state.get_trump_suit() moves_not_trump_suit = [] # Get all trump suit moves available for index, move in enumerate(moves): if moves[index][0] is not None and Deck.get_suit( moves[index][0]) != trumpSuit: moves_not_trump_suit.append(move[0]) if len(moves_not_trump_suit) > 0: for index, move in enumerate(moves_not_trump_suit): # Iterate through all the possible moves, and # find the lowest value card in your hand that is also not a trump # Check whether 'J' is in your hand, if so play the card if Deck.get_rank( moves_not_trump_suit[index]) == possibleRanks[4]: smallestRank = possibleRanks[4] break # Otherwise check for a Queen, and keep on checking maybe the Jack will be found later elif Deck.get_rank( moves_not_trump_suit[index]) == possibleRanks[3]: smallestRank = possibleRanks[3] # and so forth elif Deck.get_rank(moves_not_trump_suit[index]) == possibleRanks[2] \ and smallestRank != possibleRanks[4] \ and smallestRank != possibleRanks[3]: smallestRank = possibleRanks[2] elif Deck.get_rank(moves_not_trump_suit[index]) == possibleRanks[1] \ and smallestRank != possibleRanks[4] \ and smallestRank != possibleRanks[3] \ and smallestRank != possibleRanks[2]: smallestRank = possibleRanks[1] elif Deck.get_rank(moves_not_trump_suit[index]) == possibleRanks[0] \ and smallestRank != possibleRanks[4] \ and smallestRank != possibleRanks[3] \ and smallestRank != possibleRanks[2] \ and smallestRank != possibleRanks[1]: smallestRank = possibleRanks[0] # Return the index of the smallest value card from all the possible moves that is also not a trump suit # if such a card is found return it's index otherwise return None for index, move in enumerate(moves): if moves[index][0] is not None and Deck.get_rank(moves[index][0]) == smallestRank \ and Deck.get_suit(moves[index][0]) != trumpSuit: position = index return position
def findNextSmallestCardOfSameSuit(self, state): highestRank = None position = None # All legal moves moves = state.moves() # Opponents card rank opponentsCardRank = Deck.get_rank(state.get_opponents_played_card()) # Opponents card suit opponentsCardSuit = Deck.get_suit(state.get_opponents_played_card()) moves_suit = [] # Get all the moves available with the same suit as opponent's played card suit for index, move in enumerate(moves): if moves[index][0] is not None and Deck.get_suit( moves[index][0]) == opponentsCardSuit: moves_suit.append(move) # If opponent's card rank is '10' check for 'A' and play it if len(moves_suit) > 0: if opponentsCardRank == "10": for index, move in enumerate(moves_suit): if Deck.get_rank(moves_suit[index][0]) == "A" \ and Deck.get_suit(moves_suit[index][0] == opponentsCardSuit): highestRank = "A" break # otherwise if the rank is 'K' look for '10' and play it else, look for 'A' and keep looking in the pack maybe '10' will be found later elif opponentsCardRank == "K": for index, move in enumerate(moves_suit): if Deck.get_rank(moves_suit[index][0]) == "10" \ and Deck.get_suit(moves_suit[index][0] == opponentsCardSuit): highestRank = "10" break elif opponentsCardRank == "Q": for index, move in enumerate(moves_suit): if Deck.get_rank(moves_suit[index][0]) == "K" \ and Deck.get_suit(moves_suit[index][0] == opponentsCardSuit): highestRank = "K" break elif opponentsCardRank == "J": for index, move in enumerate(moves_suit): if Deck.get_rank(moves_suit[index][0]) == "Q" \ and Deck.get_suit(moves_suit[index][0] == opponentsCardSuit): highestRank = "Q" position = index break elif Deck.get_rank(moves_suit[index][0]) == "K" \ and Deck.get_suit(moves_suit[index][0] == opponentsCardSuit): highestRank = "K" # After the card with the next smallest value, that wins the round, was found, play it for index, move in enumerate(moves): if Deck.get_rank(moves[index][0]) == highestRank \ and Deck.get_suit(moves[index][0]) == opponentsCardSuit: position = index break return position
def findLowestTrumpCard(self, state): lowestRank = None position = None moves = state.moves() # Opponents card rank opponentsCardRank = Deck.get_rank(state.get_opponents_played_card()) # Trump suit trumpSuit = state.get_trump_suit() moves_trump_suit = [] # Get all trump suit moves available for index, move in enumerate(moves): if moves[index][0] is not None and Deck.get_suit( moves[index][0]) == trumpSuit: moves_trump_suit.append(move) # Check your hand for same suit cards as opponent, more specifically the trump suit # If opponent's card rank is '10' check for 'A' and play it if len(moves_trump_suit) > 0: # if the opponents card Rank is of high value try to win if opponentsCardRank == "10" or opponentsCardRank == "A": for index, move in enumerate(moves_trump_suit): if moves_trump_suit[index][0] is not None and Deck.get_rank( moves_trump_suit[index][0]) == "J": lowestRank = "J" break elif moves_trump_suit[index][ 0] is not None and Deck.get_rank( moves_trump_suit[index][0]) == "Q": lowestRank = "Q" elif moves_trump_suit[index][0] is not None \ and Deck.get_rank(moves_trump_suit[index][0]) == "K" \ and lowestRank != "Q": lowestRank = "K" elif moves_trump_suit[index][0] is not None \ and Deck.get_rank(moves_trump_suit[index][0]) == "10" \ and lowestRank != "K" and lowestRank != "Q": lowestRank = "10" elif moves_trump_suit[index][0] is not None \ and Deck.get_rank(moves_trump_suit[index][0]) == "A" \ and lowestRank != "10" and lowestRank != "K" and lowestRank != "Q": lowestRank = "A" # else try to win with a small value trump card else: for index, move in enumerate(moves_trump_suit): if moves_trump_suit[index][0] is not None and Deck.get_rank( moves_trump_suit[index][0]) == "J": lowestRank = "J" break elif moves_trump_suit[index][ 0] is not None and Deck.get_rank( moves_trump_suit[index][0]) == "Q": lowestRank = "Q" elif moves_trump_suit[index][0] is not None \ and Deck.get_rank(moves_trump_suit[index][0]) == "K" \ and lowestRank != "Q": lowestRank = "K" # If there is such a card that could win the hand with the trump, return it's index otherwise None for index, move in enumerate(moves): if Deck.get_rank(moves[index][0]) == lowestRank and Deck.get_suit( moves[index][0]) == trumpSuit: position = index break return position
def get_move(self, state): # type: (State) -> Tuple[None, Any] """ Function that gets called every turn. This is where to implement the strategies. Be sure to make a legal move. Illegal moves, like giving an index of a card you don't own or proposing an illegal mariage, will lose you the game. TODO: add some more explanation :param State state: An object representing the gamestate. This includes a link to the states of all the cards, the trick and the points. :return: A tuple of integers or a tuple of an integer and None, indicating a move; the first indicates the card played in the trick, the second a potential spouse. """ if state.get_prev_trick()[0]: self.played_suits[Deck.get_suit(state.get_prev_trick()[0])] += 1 self.played_suits[Deck.get_suit(state.get_prev_trick()[1])] += 1 player_hand = state.hand() moves = state.moves() if state.get_phase() == 2: # enable god mode val, move = self.value(state) return move # leading trick if state.get_opponents_played_card() is None: # print("leading trick") # check trump swap: # (None, int): First element being None indicates a trump jack exchange, # second element is the index of that trump jack for move in moves: if move[0] is None and isinstance(move[1], int): # print("move: Trump swap") return move # check marriage: # (int, int) : first element as above, second element completes a marriage possible_marriages = get_possible_marriages(moves) # check royal marriage for move in possible_marriages: if Deck.get_suit(move[0]) == state.get_trump_suit(): # print("move: Royal marriage") return move # else return random marriage if exists if possible_marriages: # print("move: Normal marriage") return random.choice(possible_marriages) # analyse your suits and play best card # if I have a ace of a suit, it guarantees a win without a trump # if I have 3 or more of a suit, playing the highest is a reasonable bet non_trump_moves = get_non_trump_moves(state, moves) if non_trump_moves: # print("move: Smallest non-trump") moves_of_suit = [] for suit in ["H", "S", "D", "C"]: if get_moves_of_suit(moves, suit): moves_of_suit.append([ sorted(get_moves_of_suit(moves, suit), key=lambda x: x[0]), len(get_moves_of_suit(moves, suit)) + self.played_suits[suit] ]) # print(moves_of_suit) moves_of_suit = sorted(moves_of_suit, key=lambda x: x[1]) if (moves_of_suit[-1][1] >= 3 and moves_of_suit[-1][0][-1][0] % 5 > 2) or\ moves_of_suit[-1][0][-1][ 0] % 5 > 3 or moves_of_suit[-1][1] == 5: return moves_of_suit[-1][0][-1] return get_lowest_value_move(non_trump_moves) # print("move: Highest non-trump") # return get_highest_value_move(non_trump_moves) # play random # print("move: Random move") moves = sorted(moves, key=lambda x: x[0]) return moves[0] # following trick else: # print("following trick") played_card = state.get_opponents_played_card() # print("other card: ", end="") # print(played_card) played_card = (state.get_opponents_played_card(), None) pending = state.get_pending_points(state.whose_turn()) opponent_power = RANKS[Deck.get_rank(played_card[0])]( Deck.get_suit(played_card[0]) == state.get_trump_suit()) trick_value = opponent_power if opponent_power < 12 else opponent_power - 10 # print("Power oppo ", str(opponent_power)) winning_moves = [] losing_moves = [] for m in moves: if Deck.get_suit(m[0]) == Deck.get_suit( played_card[0]) or Deck.get_suit( m[0]) == state.get_trump_suit(): if RANKS[Deck.get_rank(m[0])](Deck.get_suit( m[0]) == state.get_trump_suit()) > opponent_power: winning_moves.append([ m, RANKS[Deck.get_rank(m[0])]( Deck.get_suit(m[0]) == state.get_trump_suit()) ]) continue losing_moves.append([ m, RANKS[Deck.get_rank( m[0])](Deck.get_suit(m[0]) == state.get_trump_suit()) ]) winning_moves = sorted(winning_moves, key=lambda x: x[1]) losing_moves = sorted(losing_moves, key=lambda x: x[1]) if winning_moves: for m in reversed(winning_moves): if trick_value + m[ 1] >= pending: # if we can win immediately, do so return m[0] return winning_moves[0][0] # print("Power mine ", str(losing_moves[0][1])) return losing_moves[0][0]
def print_card(card): rank = Deck.get_rank(card) suit = Deck.get_suit(card) print(str(rank + suit))
def print_hand(hand): for card in hand: print(str(Deck.get_rank(card) + Deck.get_suit(card)), end=' ') print()
def get_highest_value_move(moves): highest = moves[0] for move in moves: if Deck.get_rank(move[0]) > Deck.get_rank(highest[0]): highest = move return highest
def get_lowest_value_move(moves): smallest = moves[0] for move in moves: if Deck.get_rank(move[0]) < Deck.get_rank(smallest[0]): smallest = move return smallest
def get_move(self, state): # type: (State) -> Tuple[None, Any] """ Function that gets called every turn. This is where to implement the strategies. Be sure to make a legal move. Illegal moves, like giving an index of a card you don't own or proposing an illegal mariage, will lose you the game. TODO: add some more explanation :param State state: An object representing the gamestate. This includes a link to the states of all the cards, the trick and the points. :return: A tuple of integers or a tuple of an integer and None, indicating a move; the first indicates the card played in the trick, the second a potential spouse. """ print() player_id = state.whose_turn() print("points: " + str(state.get_points(player_id))) player_hand = state.hand() print(player_hand) print_hand(player_hand) moves = state.moves() # leading trick if state.get_opponents_played_card() is None: print("leading trick") # check trump swap: # (None, int): First element being None indicates a trump jack exchange, # second element is the index of that trump jack for move in moves: if move[0] is None and isinstance(move[1], int): print("move: Trump swap") return move # check marriage: # (int, int) : first element as above, second element completes a marriage possible_marriages = get_possible_marriages(moves) # check royal marriage for move in possible_marriages: if Deck.get_suit(move[0]) == state.get_trump_suit(): print("move: Royal marriage") return move # else return random marriage if exists if possible_marriages: print("move: Normal marriage") return random.choice(possible_marriages) # play lowest, non-trump jack # (int, None): first element indicates the index of the card that is placed down. non_trump_moves = get_non_trump_moves(state, moves) if non_trump_moves: print("move: Highest non-trump") return get_highest_value_move(non_trump_moves) #print("move: Highest non-trump") #return get_highest_value_move(non_trump_moves) # play random print("move: Random move") return random.choice(moves) # following trick else: print("following trick") played_card = state.get_opponents_played_card() print("other card: ", end="") print_card(played_card) # if high rank and non-trump if Deck.get_rank(played_card) == "10" or "A" and Deck.get_suit( played_card) != state.get_trump_suit(): trump_moves = get_trump_moves(state, moves) if trump_moves: print("reply: Smallest trump card") return get_lowest_value_move(trump_moves) # play higher same suit same_suit_moves = get_moves_of_suit(moves, Deck.get_suit(played_card)) if same_suit_moves: higher_value_move = get_higher_value_move( same_suit_moves, played_card) if higher_value_move: print("reply: Higher same suit ", end="") print_card(higher_value_move[0]) return higher_value_move # minimize loss non_trump_moves = get_non_trump_moves(state, moves) if non_trump_moves: print("reply: Smallest non-trump") return get_lowest_value_move(non_trump_moves) print("reply: Random move") return random.choice(moves)
def features(state): # type: (State) -> tuple[float, ...] """ Extract features from this state. Remember that every feature vector returned should have the same length. :param state: A state to be converted to a feature vector :return: A tuple of floats: a feature vector representing this state. """ feature_set = [] perspective = state.get_perspective() # Convert the card state array containing strings, to an array of integers. # The integers here just represent card state IDs. In a way they can be # thought of as arbitrary, as long as they are different from each other. perspective = [card if card != 'U' else (-1) for card in perspective] perspective = [card if card != 'S' else 0 for card in perspective] perspective = [card if card != 'P1H' else 1 for card in perspective] perspective = [card if card != 'P2H' else 2 for card in perspective] perspective = [card if card != 'P1W' else 3 for card in perspective] perspective = [card if card != 'P2W' else 4 for card in perspective] feature_set += perspective # Add player 1's points to feature set p1_points = state.get_points(1) feature_set.append(p1_points) feature_set.append(p1_points**2) feature_set.append(p1_points**3) # Add player 2's points to feature set p2_points = state.get_points(2) feature_set.append(p2_points) feature_set.append(p2_points**2) feature_set.append(p2_points**3) # Add player 1's pending points to feature set p1_pending_points = state.get_pending_points(1) feature_set.append(p1_pending_points) feature_set.append(p1_pending_points**2) feature_set.append(p1_pending_points**3) # Add plauer 2's pending points to feature set p2_pending_points = state.get_pending_points(2) feature_set.append(p2_pending_points) feature_set.append(p2_pending_points**2) feature_set.append(p2_pending_points**3) # Difference between points point_difference = abs(max(p1_points, p2_points) - min(p1_points, p2_points)) feature_set.append(point_difference) # Difference between pending points pending_point_difference = abs( max(p1_pending_points, p2_pending_points) - min(p1_pending_points, p2_pending_points)) feature_set.append(pending_point_difference) # Get trump suit trump_suit = state.get_trump_suit() # Convert trump suit to id and add to feature set # You don't need to add anything to this part suits = ["C", "D", "H", "S"] trump_suit_id = suits.index(trump_suit) feature_set.append(trump_suit_id) # Trump card ratio: cards = state.hand() trump_card_count = 0 for card in cards: if Deck.get_suit(cards[0]) == state.get_trump_suit(): trump_card_count += 1 if trump_card_count != 0: trump_card_count = (trump_card_count / len(state.hand())) * 100 feature_set.append(trump_card_count) # High ranking cards ratio: high_rank_count = 0 for card in cards: if Deck.get_rank(cards[0]) == "A" or Deck.get_rank(cards[0]) == "10": high_rank_count += 1 if high_rank_count != 0: high_rank_count = (high_rank_count / len(state.hand())) * 100 feature_set.append(high_rank_count) # Add phase to feature set phase = state.get_phase() feature_set.append(phase) # Number of trump cards in phase 2: phase2_trump_cards = 0 if phase == 2: phase2_trump_cards = trump_card_count ** 2 feature_set.append(phase2_trump_cards) else: feature_set.append(phase2_trump_cards) # Add stock size to feature set stock_size = state.get_stock_size() feature_set.append(stock_size) # Add leader to feature set leader = state.leader() feature_set.append(leader) # Add whose turn it is to feature set whose_turn = state.whose_turn() feature_set.append(whose_turn) # Add opponent's played card to feature set opponents_played_card = state.get_opponents_played_card() # You don't need to add anything to this part opponents_played_card = opponents_played_card if opponents_played_card is not None else -1 feature_set.append(opponents_played_card) # Do I have cards in same suit as oppponent? same_suit_cards = 0 for card in cards: if Deck.get_suit(cards[0]) == Deck.get_suit(opponents_played_card): same_suit_cards += 1 feature_set.append(same_suit_cards) # Get number of points in hand cards = state.hand() number_of_points = 0 for card in cards: if cards[0] is not None: if Deck.get_rank(cards[0]) == "J": number_of_points += 1 ** 2 elif Deck.get_rank(cards[0]) == "Q": number_of_points += 2 ** 2 elif Deck.get_rank(cards[0]) == "K": number_of_points += 3 ** 2 elif Deck.get_rank(cards[0]) == "10": number_of_points += 10 ** 2 elif Deck.get_rank(cards[0]) == "A": number_of_points += 11 ** 2 feature_set.append(number_of_points) return feature_set
def get_move(self, state): # type: (State) -> tuple[int, int] moves = state.moves() chosen_move = moves[0] opponent_card = state.get_opponents_played_card() moves_trump_suit = [] me = state.whose_turn() phase = state.get_phase() if me == 1: #if mybot is player 1, we play higher cards because we cant react to opponents plays if phase == 1: for index, move in enumerate(moves): if move[0] is not None and Deck.get_suit( move[0]) == state.get_trump_suit(): moves_trump_suit.append(move) if len(moves_trump_suit) > 0: chosen_move = moves_trump_suit[0] return chosen_move # Get move with highest rank available, of any suit for index, move in enumerate(moves): if move[0] is not None and move[0] % 5 <= chosen_move[ 0] % 5: chosen_move = move elif phase == 2: for index, move in enumerate(moves): if move[0] is not None and Deck.get_suit( move[0]) == state.get_trump_suit(): moves_trump_suit.append(move) if len(moves_trump_suit) > 0: chosen_move = moves_trump_suit[0] return chosen_move # Get move with highest rank available, of any suit for index, move in enumerate(moves): if move[0] is not None and move[0] % 5 <= chosen_move[ 0] % 5: chosen_move = move return chosen_move elif me == 2: if phase == 1: #Get all trump suit moves available for index, move in enumerate(moves): if move[0] is not None and Deck.get_suit( move[0]) == state.get_trump_suit(): moves_trump_suit.append(move) if len(moves_trump_suit) > 0: chosen_move = moves_trump_suit[len(moves_trump_suit) - 1] return chosen_move # If the opponent has played a card if state.get_opponents_played_card() is not None: moves_same_suit = [] # Get all moves of the same suit as the opponent's played card (as long as they beat that card) for index, move in enumerate(moves): if move[0] is not None and Deck.get_suit( move[0]) == Deck.get_suit( state.get_opponents_played_card() ) and Deck.get_rank( move[0]) > Deck.get_rank(opponent_card): moves_same_suit.append(move) # if there are any moves we can make of the opponents suit, pick the lowest that wins if len(moves_same_suit) > 0: chosen_move = moves_same_suit[len(moves_same_suit) - 1] return chosen_move # Get move with lowest rank available, of any suit. Throw away crap cards, basically for index, move in enumerate(moves): if move[0] is not None and move[0] % 5 >= chosen_move[ 0] % 5: chosen_move = move elif phase == 2: # Get all trump suit moves available for index, move in enumerate(moves): if move[0] is not None and Deck.get_suit( move[0]) == state.get_trump_suit(): moves_trump_suit.append(move) if len(moves_trump_suit) > 0: chosen_move = moves_trump_suit[len(moves_trump_suit) - 1] return chosen_move # If the opponent has played a card if state.get_opponents_played_card() is not None: moves_same_suit = [] # Get all moves of the same suit as the opponent's played card (as long as they beat that card) for index, move in enumerate(moves): if move[0] is not None and Deck.get_suit( move[0]) == Deck.get_suit( state.get_opponents_played_card() ) and Deck.get_rank( move[0]) > Deck.get_rank(opponent_card): moves_same_suit.append(move) # if there are any moves we can make of the opponents suit, pick the lowest that wins if len(moves_same_suit) > 0: chosen_move = moves_same_suit[len(moves_same_suit) - 1] return chosen_move # Get move with lowest rank available, of any suit. Throw away crap cards, basically for index, move in enumerate(moves): if move[0] is not None and move[0] % 5 >= chosen_move[ 0] % 5: chosen_move = move return chosen_move