''' DS2000 Spring 2023 Sample code from class - making objects in the driver Section 1 - Go fish! Our version: * Deal 5 cards to player one * Check if there is a pair * If so, the player gets a point * Remove the pair from the hand * (A triple/four of a kind would get ignored - that could be fixed!) * Go fish! The player draws another card * Check for a pair again and update points the same way * Repeat for the second player * Whoever has the most points wins. ''' # from [filename] import [classname] from card import Card from deck import Deck def main(): # initialize the players p1 = 0 p2 = 0 p1_name = "Kayla" p2_name = "Laney" # make a deck and shuffle it d = Deck() d.shuffle() # give each player 5 cards p1_cards = [] p2_cards = [] for i in range(5): p1_cards.append(d.deal()) p2_cards.append(d.deal()) for i in range(2): # sanity check print - each player's hand for card in p1_cards: print(card) # does p1 have any pairs? loc1 = -1 for i in range(len(p1_cards)): for j in range(i + 1, len(p1_cards)): if p1_cards[i].number == p1_cards[j].number: print("\nfound a pair!") p1 += 1 loc1, loc2 = i, j if loc1 > -1: p1_cards.pop(loc1) p1_cards.pop(loc2 - 1) # print the points so far print("P1 points:", p1) # go fish! print("\n\nGo fish!!") input("Round over! OK?") p1_cards.append(d.deal()) for k in range(2): # sanity check print - each player's hand for card in p2_cards: print(card) # does p1 have any pairs? loc1 = -1 for i in range(len(p2_cards)): for j in range(i + 1, len(p2_cards)): if p2_cards[i].number == p2_cards[j].number: print("\nfound a pair!") p2 += 1 loc1, loc2 = i, j if loc1 > -1: p2_cards.pop(loc1) p2_cards.pop(loc2 - 1) # print the points so far print("P2 points:", p2) # go fish! print("\n\nGo fish!!") input("Round over! OK?") p2_cards.append(d.deal()) # Very end, after the loop, print the points print(p1_name, "ended with...", p1) print(p2_name, "ended with...", p2) main()