import cards import string print("Rules of Spider Solitaire:") print("The goal is to move all cards to the foundation. Cards can only be moved") print("to the foundation if in a completed run of cards (King, Queen, ..., Ace).") print("A single card in the tableau can be moved to another row if the destination") print("card is one rank higher than the moving card. Multiple cards can be moved at") print("once, but all cards within the stack being moved must be in descending order,") print("and they must all be the same suit. The destination card must also be one") print("rank higher than the top card of the stack being moved.") number = string.digits prmpt = """ Acceptable Commands: 'q' = quit 'd' = deal 'h' = help 'm' = moves the number of cards from the source row to the destination row, if the move is allowed """ #Making the command to ask over and over to enter q,d,h, or m def get_command(prmpt): command = input(prmpt).lower() while command != 'd' and command != 'q' and command != 'h' and command != 'm': print("Illegal command:", command) command = input(prmpt).lower() return command #Start making four decks deck1 = cards.Deck() deck2 = cards.Deck() deck3 = cards.Deck() deck4 = cards.Deck() #Get rid of the suits spaces and clubs piles = [[deck1.deal() for i in range (26)], [deck2.deal() for i in range(26)],[deck3.deal() for i in range(26)], [deck4.deal() for i in range(26)]] #Shuffles the rest of the diamonds and hearts deck1.shuffle() deck2.shuffle() deck3.shuffle() deck4.shuffle() #Adds all the cards to piles piles1 = [deck1.deal() for i in range(26)] piles2 = [deck2.deal() for i in range(26)] piles3 = [deck3.deal() for i in range(26)] piles4 = [deck4.deal() for i in range(26)] #Makes the piles into one big pile piles1 += piles2 piles1 += piles3 piles1 += piles4 master_pile = piles1 #Makes the tableau and stock piles from the shuffled up master pile tableau,stock = master_pile[0:54], master_pile[54:] Row_0 = [] #Individually go through and make the rows and hide the cards that should be hidden Row_1 = tableau[0:6] Row_1[0].set_hidden() Row_1[1].set_hidden() Row_1[2].set_hidden() Row_1[3].set_hidden() Row_1[4].set_hidden() Row_2 = tableau[6:12] Row_2[0].set_hidden() Row_2[1].set_hidden() Row_2[2].set_hidden() Row_2[3].set_hidden() Row_2[4].set_hidden() Row_3 = tableau[12:18] Row_3[0].set_hidden() Row_3[1].set_hidden() Row_3[2].set_hidden() Row_3[3].set_hidden() Row_3[4].set_hidden() Row_4 = tableau[18:24] Row_4[0].set_hidden() Row_4[1].set_hidden() Row_4[2].set_hidden() Row_4[3].set_hidden() Row_4[4].set_hidden() Row_5 = tableau[24:29] Row_5[0].set_hidden() Row_5[1].set_hidden() Row_5[2].set_hidden() Row_5[3].set_hidden() Row_6 = tableau[29:34] Row_6[0].set_hidden() Row_6[1].set_hidden() Row_6[2].set_hidden() Row_6[3].set_hidden() Row_7 = tableau[34:39] Row_7[0].set_hidden() Row_7[1].set_hidden() Row_7[2].set_hidden() Row_7[3].set_hidden() Row_8 = tableau[39:44] Row_8[0].set_hidden() Row_8[1].set_hidden() Row_8[2].set_hidden() Row_8[3].set_hidden() Row_9 = tableau[44:49] Row_9[0].set_hidden() Row_9[1].set_hidden() Row_9[2].set_hidden() Row_9[3].set_hidden() Row_10 = tableau[49:54] Row_10[0].set_hidden() Row_10[1].set_hidden() Row_10[2].set_hidden() Row_10[3].set_hidden() #Makes a list of all these rows to have easy access List = [Row_0,Row_1,Row_2,Row_3,Row_4,Row_5,Row_6,Row_7,Row_8,Row_9,Row_10] print('-'*30) print("Foundation = 0/8 runs completed") print("Stock:", len(stock),"cards remaining") command = get_command(prmpt) #Make one big while true loop to keep program going until quit dog = True while dog == True: while command == 'm': print("Row 1:" , Row_1) print("Row 2:" , Row_2) print("Row 3:" , Row_3) print("Row 4:" , Row_4) print("Row 5:" , Row_5) print("Row 6:" , Row_6) print("Row 7:" , Row_7) print("Row 8:" , Row_8) print("Row 9:" , Row_9) print("Row 10:", Row_10) #Ask for the numb of cards, which row to move from, which row to move to num1 = (input("Please enter the # of cards you desire to move at same time")) while num1 not in number: num1 =(input("Please enter the # of cards you desire to move at same time")) num2 = (input("Please enter the source row you plan on taking these cards from")) while num2 not in number: num2 = (input("Please enter the source row you plan on taking these cards from")) num3 =(input("Please enter the destination row you plan on putting these cards")) while num3 not in number: num3 = (input("Please enter the destination row you plan on putting these cards")) num1 = int(num1) num2 = int(num2) num3 = int(num3) #Makes cards based on numbers inputed card1,card2 = List[num2][-1],List[num3][-1] rank1, rank2 = card1.get_rank(),card2.get_rank()-1 #Each statement does the appropriate procedure depending on the number of cards being moved at one time if num1 == 2: card1,card2,card3 = List[num2][-1],List[num2][-2],List[num3][-1] rank1,rank2 = card2.get_rank(),card3.get_rank()-1 suit1,suit2 = card1.get_suit(),card2.get_suit() if suit1 == suit2 and rank1 == rank2: List[num3] += [card2] List[num3] += [card1] del List[num2][-1:-3:-1] List[num2][-1].set_hidden(val = False) elif num1 == 3: card1,card2,card3,card4 = List[num2][-1],List[num2][-2],List[num2][-3],List[num3][-1] rank1,rank2 = card2.get_rank(),card3.get_rank()-1 suit1,suit2,suit3= card1.get_suit(),card2.get_suit(),card3.get_suit() if suit1 == suit2 == suit3 and rank1 == rank2: List[num3] += [card3] List[num3] += [card2] List[num3] += [card1] del List[num2][-1:-4:-1] List[num2][-1].set_hidden(val = False) elif num1 == 4: card1,card2,card3,card4,card5 = List[num2][-1],List[num2][-2],List[num2][-3],List[num2][-4],List[num3][-1] rank1,rank2 = card2.get_rank(),card3.get_rank()-1 suit1,suit2,suit3,suit4= card1.get_suit(),card2.get_suit(),card3.get_suit(),card4.get_suit() if suit1 == suit2 == suit3 == suit4 and rank1 == rank2: List[num3] += [card4] List[num3] += [card3] List[num3] += [card2] List[num3] += [card1] del List[num2][-1:-5:-1] List[num2][-1].set_hidden(val = False) elif num1 == 5: card1,card2,card3,card4,card5,card6 = List[num2][-1],List[num2][-2],List[num2][-3],List[num2][-4],List[num2][-5],List[num3][-1] rank1,rank2 = card2.get_rank(),card3.get_rank()-1 suit1,suit2,suit3,suit4,suit5= card1.get_suit(),card2.get_suit(),card3.get_suit(),card4.get_suit(),card5.get_suit() if suit1 == suit2 == suit3 == suit4 == suit5 and rank1 == rank2: List[num3] += [card5] List[num3] += [card4] List[num3] += [card3] List[num3] += [card2] List[num3] += [card1] del List[num2][-1:-6:-1] List[num2][-1].set_hidden(val = False) elif num1 == 6: card1,card2,card3,card4,card5,card6 = List[num2][-1],List[num2][-2],List[num2][-3],List[num2][-4],List[num2][-5],List[num2][-6] card7 = List[num3][-1] rank1,rank2 = card2.get_rank(),card3.get_rank()-1 suit1,suit2,suit3,suit4,suit5= card1.get_suit(),card2.get_suit(),card3.get_suit(),card4.get_suit(),card5.get_suit() suit6 = card6.get_suit() if suit1 == suit2 == suit3 == suit4 == suit5 == suit6 and rank1 == rank2: List[num3] += [card6] List[num3] += [card5] List[num3] += [card4] List[num3] += [card3] List[num3] += [card2] List[num3] += [card1] del List[num2][-1:-7:-1] List[num2][-1].set_hidden(val = False) elif num1 == 7: card1,card2,card3,card4,card5,card6 = List[num2][-1],List[num2][-2],List[num2][-3],List[num2][-4],List[num2][-5],List[num2][-6] card7,card8 = List[num2][-7],List[num3][-1] rank1,rank2 = card2.get_rank(),card3.get_rank()-1 suit1,suit2,suit3,suit4,suit5= card1.get_suit(),card2.get_suit(),card3.get_suit(),card4.get_suit(),card5.get_suit() suit6,suit7 = card6.get_suit(),card7.get_suit() if suit1 == suit2 == suit3 == suit4 == suit5 == suit6 == suit7 and rank1 == rank2: List[num3] += [card7] List[num3] += [card6] List[num3] += [card5] List[num3] += [card4] List[num3] += [card3] List[num3] += [card2] List[num3] += [card1] del List[num2][-1:-8:-1] List[num2][-1].set_hidden(val = False) elif num1 == 8: card1,card2,card3,card4,card5,card6 = List[num2][-1],List[num2][-2],List[num2][-3],List[num2][-4],List[num2][-5],List[num2][-6] card7,card8,card9 = List[num2][-7],List[num2][-8],List[num3][-1] rank1,rank2 = card2.get_rank(),card3.get_rank()-1 suit1,suit2,suit3,suit4,suit5= card1.get_suit(),card2.get_suit(),card3.get_suit(),card4.get_suit(),card5.get_suit() suit6,suit7,suit8 = card6.get_suit(),card7.get_suit(),card8.get_suit() if suit1 == suit2 == suit3 == suit4 == suit5 == suit6 == suit7 == suit8 and rank1 == rank2: List[num3] += [card8] List[num3] += [card7] List[num3] += [card6] List[num3] += [card5] List[num3] += [card4] List[num3] += [card3] List[num3] += [card2] List[num3] += [card1] del List[num2][-1:-9:-1] List[num2][-1].set_hidden(val = False) elif num1 == 9: card1,card2,card3,card4,card5,card6 = List[num2][-1],List[num2][-2],List[num2][-3],List[num2][-4],List[num2][-5],List[num2][-6] card7,card8,card9,card10 = List[num2][-7],List[num2][-8],List[num2][-9],List[num3][-1] rank1,rank2 = card2.get_rank(),card3.get_rank()-1 suit1,suit2,suit3,suit4,suit5= card1.get_suit(),card2.get_suit(),card3.get_suit(),card4.get_suit(),card5.get_suit() suit6,suit7,suit8,suit9 = card6.get_suit(),card7.get_suit(),card8.get_suit(),card9.get_suit() if suit1 == suit2 == suit3 == suit4 == suit5 == suit6 == suit7 == suit8 == suit9 and rank1 == rank2: List[num3] += [card9] List[num3] += [card8] List[num3] += [card7] List[num3] += [card6] List[num3] += [card5] List[num3] += [card4] List[num3] += [card3] List[num3] += [card2] List[num3] += [card1] del List[num2][-1:-10:-1] List[num2][-1].set_hidden(val = False) elif num1 == 10: card1,card2,card3,card4,card5,card6 = List[num2][-1],List[num2][-2],List[num2][-3],List[num2][-4],List[num2][-5],List[num2][-6] card7,card8,card9,card10,card11 = List[num2][-7],List[num2][-8],List[num2][-9],List[num2][-10],List[num3][-1] rank1,rank2 = card2.get_rank(),card3.get_rank()-1 suit1,suit2,suit3,suit4,suit5= card1.get_suit(),card2.get_suit(),card3.get_suit(),card4.get_suit(),card5.get_suit() suit6,suit7,suit8,suit9,suit10 = card6.get_suit(),card7.get_suit(),card8.get_suit(),card9.get_suit(),card10.get_suit() if suit1 == suit2 == suit3 == suit4 == suit5 == suit6 == suit7 == suit8 == suit9 == suit10 and rank1 == rank2: List[num3] += [card10] List[num3] += [card9] List[num3] += [card8] List[num3] += [card7] List[num3] += [card6] List[num3] += [card5] List[num3] += [card4] List[num3] += [card3] List[num3] += [card2] List[num3] += [card1] del List[num2][-1:-11:-1] List[num2][-1].set_hidden(val = False) elif num1 == 11: card1,card2,card3,card4,card5,card6 = List[num2][-1],List[num2][-2],List[num2][-3],List[num2][-4],List[num2][-5],List[num2][-6] card7,card8,card9,card10,card11,card12 = List[num2][-7],List[num2][-8],List[num2][-9],List[num2][-10],List[num2][-11],List[num3][-1] rank1,rank2 = card2.get_rank(),card3.get_rank()-1 suit1,suit2,suit3,suit4,suit5= card1.get_suit(),card2.get_suit(),card3.get_suit(),card4.get_suit(),card5.get_suit() suit6,suit7,suit8,suit9,suit10,suit11 = card6.get_suit(),card7.get_suit(),card8.get_suit(),card9.get_suit(),card10.get_suit(),card11.get_suit() if suit1 == suit2 == suit3 == suit4 == suit5 == suit6 == suit7 == suit8 == suit9 == suit10 ==suit11 and rank1 == rank2: List[num3] += [card11] List[num3] += [card10] List[num3] += [card9] List[num3] += [card8] List[num3] += [card7] List[num3] += [card6] List[num3] += [card5] List[num3] += [card4] List[num3] += [card3] List[num3] += [card2] List[num3] += [card1] del List[num2][-1:-12:-1] List[num2][-1].set_hidden(val = False) elif num1 == 12: card1,card2,card3,card4,card5,card6 = List[num2][-1],List[num2][-2],List[num2][-3],List[num2][-4],List[num2][-5],List[num2][-6] card7,card8,card9,card10,card11,card12,card13 = List[num2][-7],List[num2][-8],List[num2][-9],List[num2][-10],List[num2][-11],List[num2][-12],List[num3][-1] rank1,rank2 = card2.get_rank(),card3.get_rank()-1 suit1,suit2,suit3,suit4,suit5= card1.get_suit(),card2.get_suit(),card3.get_suit(),card4.get_suit(),card5.get_suit() suit6,suit7,suit8,suit9,suit10,suit11,suit12 = card6.get_suit(),card7.get_suit(),card8.get_suit(),card9.get_suit(),card10.get_suit(),card11.get_suit(),card12.get_suit() if suit1 == suit2 == suit3 == suit4 == suit5 == suit6 == suit7 == suit8 == suit9 == suit10 ==suit11 == suit12 and rank1 == rank2: List[num3] += [card12] List[num3] += [card11] List[num3] += [card10] List[num3] += [card9] List[num3] += [card8] List[num3] += [card7] List[num3] += [card6] List[num3] += [card5] List[num3] += [card4] List[num3] += [card3] List[num3] += [card2] List[num3] += [card1] del List[num2][-1:-13:-1] List[num2][-1].set_hidden(val = False) elif rank1 == rank2: print("yes") List[num3] += [card1] del List[num2][-1] List[num2][-1].set_hidden(val = False) print("Foundation = 0/8 runs completed") print("Stock:", len(stock),"cards remaining") command = get_command(prmpt) #If the command is d then distribute a card to each pile while command == 'd': #Making 10 cards from the stock pile card1,card2,card3,card4,card5 = stock[0],stock[1],stock[2],stock[3],stock[4] card6,card7,card8,card9,card10 = stock[5],stock[6],stock[7],stock[8],stock[9] #Adding one of those stock piles cards to each list List[1] += [card1] List[2] += [card2] List[3] += [card3] List[4] += [card4] List[5] += [card5] List[6] += [card6] List[7] += [card7] List[8] += [card8] List[9] += [card9] List[10] += [card10] print("Row 1:" , Row_1) print("Row 2:" , Row_2) print("Row 3:" , Row_3) print("Row 4:" , Row_4) print("Row 5:" , Row_5) print("Row 6:" , Row_6) print("Row 7:" , Row_7) print("Row 8:" , Row_8) print("Row 9:" , Row_9) print("Row 10:", Row_10) #Gets rid of the ten cards from the stock pile del stock[0:10:1] print("Foundation = 0/8 runs completed") print("Stock:", len(stock),"cards remaining") command = get_command(prmpt) #If command is h then rereads the user the rules while command == 'h': print("Rules of Spider Solitaire:") print("The goal is to move all cards to the foundation. Cards can only be moved") print("to the foundation if in a completed run of cards (King, Queen, ..., Ace).") print("A single card in the tableau can be moved to another row if the destination") print("card is one rank higher than the moving card. Multiple cards can be moved at") print("once, but all cards within the stack being moved must be in descending order,") print("and they must all be the same suit. The destination card must also be one") print("rank higher than the top card of the stack being moved.") command = get_command(prmpt) #If command is q then quits the big while true look and allows user to start using blank shell while command == 'q': print("Thank you for playing!") dog = False break