def cardToPlayComputer(): # Get list of computer hand cards hand_computer = data_cards.cardList(constants.HAND_COMPUTER) hand_copy = [] hand_copy.extend(hand_computer) # Get top pile card and value card_pile_top = data_pile_cards.getPileTopCard() card_pile_top_int = value_cards.cardValueToInt(card_pile_top) # If top pile card = 3 if card_pile_top_int == 3: card_pile_top_int = value_cards.cardValueToInt( data_pile_cards.cardUnderThree()) # Loop until card to play is found, else return error while len(hand_copy) != 0: num = random.randint(0, (len(hand_copy) - 1)) card_to_play = hand_copy[num] hand_copy.pop(num) card_to_play_int = value_cards.cardValueToInt(card_to_play) if rules.checkCanPlayCard(card_to_play_int, card_pile_top_int) == True: return card_to_play return constants.INTERNAL_NO_CARD_TO_PLAY
def drawPlayCardComputer(): card_drawn = data_cards.getRandomCard() data_cards.removeCardFromDeck(card_drawn) print(constants.MESSAGE_COMPUTER_DREW_CARD, card_drawn) card_pile = data_pile_cards.getPileTopCard() card_drawn_int = value_cards.cardValueToInt(card_drawn) card_pile_int = value_cards.cardValueToInt(card_pile) if card_pile_int == 3: card_pile_value_string = value_cards.getCardValue( data_pile_cards.cardUnderThree()) card_pile_int = value_cards.convertValueToInt(card_pile_value_string) computer_can_play_card = rules.checkCanPlayCard(card_drawn_int, card_pile_int) if computer_can_play_card == True: print(constants.MESSAGE_COMPUTER_PLAYED_CARD, card_drawn) if card_drawn_int == 10: rules.foldPile() turn.computerTurn() else: data_read_write.addToFile("\n" + card_drawn, constants.PILE_CARDS) else: data_read_write.addToFile("\n" + card_drawn, constants.HAND_COMPUTER) pickUpPileComputer()
def drawCardAndPlay(): card_drawn = data_cards.getRandomCard() data_cards.removeCardFromDeck(card_drawn) print(constants.MESSAGE_DRAW_CARD + card_drawn) card_play_value_int = value_cards.cardValueToInt(card_drawn) card_pile_value_int = value_cards.cardValueToInt( data_pile_cards.getPileTopCard()) # If top card in pile is 3 if card_pile_value_int == 3: card_pile_value_string = value_cards.getCardValue( data_pile_cards.cardUnderThree()) card_pile_value_int = value_cards.convertValueToInt( card_pile_value_string) player_can_play_card = rules.checkCanPlayCard(card_play_value_int, card_pile_value_int) if player_can_play_card == True: data_cards.removeCardFromHand(card_drawn, constants.HAND_PLAYER) print(constants.MESSAGE_PLAYED_CARD, card_drawn) if card_play_value_int == 10: rules.foldPile() turn.playerTurn() else: data_read_write.addToFile("\n" + card_drawn, constants.PILE_CARDS) if rules.fourOfAKind() == True: rules.foldPile() turn.playerTurn() else: data_read_write.addToFile("\n" + card_drawn, constants.HAND_PLAYER) pickUpAllCardsInPile()
def fourOfAKind(): pile_list = data_pile_cards.getPileList() pile_list.reverse() four_of_a_kind = False counter = 4 top_card_int = value_cards.cardValueToInt(pile_list[0]) if len(pile_list) >= 4: for i in range(1, counter): next_card_int = value_cards.cardValueToInt(pile_list[i]) while top_card_int == next_card_int: counter -= 1 break if counter == 1: four_of_a_kind = True return four_of_a_kind
def playerWithLowestHand(card_lowest_player, card_lowest_computer): card_lowest_player_value = value_cards.cardValueToInt(card_lowest_player) card_lowest_computer_value = value_cards.cardValueToInt( card_lowest_computer) player_first = False if card_lowest_player_value < card_lowest_computer_value: player_first = True elif card_lowest_player_value == card_lowest_computer_value: card_lowest_player_suite = value_cards.getCardSuite(card_lowest_player) card_lowest_computer_suite = value_cards.getCardSuite( card_lowest_computer) if constants.card_suite_values[ card_lowest_player_suite] < constants.card_suite_values[ card_lowest_computer_suite]: player_first = True return player_first
def lowestCardInHand(hand_list): card_lowest = "15" for i in range(0, len(hand_list)): card_hand_value = value_cards.cardValueToInt(hand_list[i]) card_lowest_value = value_cards.cardValueToInt(card_lowest) if card_hand_value < card_lowest_value: card_lowest = hand_list[i] elif card_hand_value == card_lowest_value: card_hand_suite = value_cards.getCardSuite(hand_list[i]) card_lowest_suite = value_cards.getCardSuite(card_lowest) card_hand_suite_value = constants.card_suite_values[ card_hand_suite] card_lowest_suite_value = constants.card_suite_values[ card_lowest_suite] if card_hand_suite_value < card_lowest_suite_value: card_lowest = hand_list[i] return card_lowest
def playCard(): ## DISPLAY displayPlayerHandNumbered() data_pile_cards.displayPileTopCard() ## PLAYER card_play = getInputCard() card_play_value_int = value_cards.cardValueToInt(card_play) ## PILE card_pile = data_pile_cards.getPileTopCard() card_pile_value_int = value_cards.cardValueToInt(card_pile) # If top card in pile is 3 if card_pile_value_int == 3: card_pile_value_string = value_cards.getCardValue( data_pile_cards.cardUnderThree()) card_pile_value_int = value_cards.convertValueToInt( card_pile_value_string) ## PLAYING player_can_play_card = rules.checkCanPlayCard(card_play_value_int, card_pile_value_int) if player_can_play_card == True: data_cards.removeCardFromHand(card_play, constants.HAND_PLAYER) print(constants.MESSAGE_PLAYED_CARD, card_play) if card_play_value_int == 10: rules.foldPile() turn.playerTurn() else: data_read_write.addToFile("\n" + card_play, constants.PILE_CARDS) if rules.fourOfAKind() == True: rules.foldPile() turn.playerTurn() else: print(constants.MESSAGE_CANNOT_PLAY_CARD) processPlayerTurn()
def playCardComputer(): card_play = cardToPlayComputer() if card_play != constants.INTERNAL_NO_CARD_TO_PLAY: data_cards.removeCardFromHand(card_play, constants.HAND_COMPUTER) print(constants.MESSAGE_COMPUTER_PLAYED_CARD, card_play) if value_cards.cardValueToInt(card_play) == 10: rules.foldPile() turn.computerTurn() else: data_read_write.addToFile("\n" + card_play, constants.PILE_CARDS) if rules.fourOfAKind() == True: rules.foldPile() turn.computerTurn() return True return False
def displayPileTopCard(): card_pile_top = getPileTopCard() if card_pile_top != "0": print(constants.MESSAGE_TOP_CARD_IN_PILE, "\n" + card_pile_top) if value_cards.cardValueToInt(card_pile_top) == 3: displayCardUnderThree()