Advertisement
here2share

# crazy_eights_solitaire.py

Jul 4th, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. # crazy_eights_solitaire.py
  2.  
  3. import random
  4. import os
  5.  
  6. cls = lambda: os.system('cls')
  7.  
  8. rank = 'A23456789TJQK'
  9. suit = 'cdhs'
  10. full_deck = []
  11. pile = []
  12. for r in list(rank):
  13.     for s in list(suit):
  14.         card = r + s
  15.         full_deck.append(card)
  16. 0
  17. def status():
  18.     print
  19.     if pile:
  20.         print 'DECK:', len(deck), 'Remaining'
  21.         print 'Last Card Played:', pile[-1]
  22.     print 'YOUR HAND:', hand
  23.     print
  24. 0
  25. def deal():
  26.     for i in range(6):
  27.         hand.append(deck.pop())
  28. 0
  29. def accept_card(x):
  30.     z = hand.index(x)
  31.     pile.append(hand.pop(z))
  32.     if not deck:
  33.         print '\n*** NO MORE CARDS IN THE DECK... YOU WON !!! ***'
  34.         game.pop()
  35.     else:
  36.         hand.append(deck.pop())
  37. 0
  38. def deny():
  39.     game[0] = '\n*** Invalid Selection! ***'
  40. 0
  41. def check_card(x):
  42.     return (
  43.     x[0] == '8',
  44.     x[0] == pile[-1][0],
  45.     x[1] == pile[-1][1],
  46.     pile[-1][0] == '8'
  47.     )
  48. 0
  49. def read_input(x):
  50.     if len(x) is 2:
  51.         x = x[0].upper()+x[-1].lower()
  52.         if x in hand:
  53.             if not pile:
  54.                 accept_card(x)
  55.             elif x in hand:
  56.                 if '8' in x or True in check_card(x):
  57.                     accept_card(x)
  58.             else:
  59.                 deny()
  60.     elif x.lower() is 'q':
  61.         game.pop()
  62.     else:
  63.         deny()
  64. 0
  65. def play_card():
  66.     if 1 not in game:
  67.         print game[0]
  68.         game[0] = 1
  69.     status()
  70.     if pile:
  71.         if '8' in pile[-1]:
  72.             print "Any Are Now Valid..."
  73.     x = raw_input("What Card Would You Like To Play? ")
  74.     read_input(x)
  75.    
  76. def check_hand():
  77.     for z in hand:
  78.         if True in check_card(z):
  79.             return
  80.     print '\n*** NO MORE VALID CARDS TO PLAY... YOU LOST !!! ***\n'
  81.     game.pop()
  82.        
  83. while 1:
  84.     deck = full_deck[:]
  85.     random.shuffle(deck)
  86.     hand = []
  87.     deal()
  88.     game = ["Select The First Card To Place In The Pile...\n"]
  89.     while game:
  90.         cls()
  91.         play_card()
  92.         check_hand()
  93.     x = raw_input("Play Again? ")
  94.     if x.lower().startswith('n'):
  95.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement