Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # crazy_eights_solitaire.py
- import random
- import os
- cls = lambda: os.system('cls')
- rank = 'A23456789TJQK'
- suit = 'cdhs'
- full_deck = []
- pile = []
- for r in list(rank):
- for s in list(suit):
- card = r + s
- full_deck.append(card)
- 0
- def status():
- print
- if pile:
- print 'DECK:', len(deck), 'Remaining'
- print 'Last Card Played:', pile[-1]
- print 'YOUR HAND:', hand
- print
- 0
- def deal():
- for i in range(6):
- hand.append(deck.pop())
- 0
- def accept_card(x):
- z = hand.index(x)
- pile.append(hand.pop(z))
- if not deck:
- print '\n*** NO MORE CARDS IN THE DECK... YOU WON !!! ***'
- game.pop()
- else:
- hand.append(deck.pop())
- 0
- def deny():
- game[0] = '\n*** Invalid Selection! ***'
- 0
- def check_card(x):
- return (
- x[0] == '8',
- x[0] == pile[-1][0],
- x[1] == pile[-1][1],
- pile[-1][0] == '8'
- )
- 0
- def read_input(x):
- if len(x) is 2:
- x = x[0].upper()+x[-1].lower()
- if x in hand:
- if not pile:
- accept_card(x)
- elif x in hand:
- if '8' in x or True in check_card(x):
- accept_card(x)
- else:
- deny()
- elif x.lower() is 'q':
- game.pop()
- else:
- deny()
- 0
- def play_card():
- if 1 not in game:
- print game[0]
- game[0] = 1
- status()
- if pile:
- if '8' in pile[-1]:
- print "Any Are Now Valid..."
- x = raw_input("What Card Would You Like To Play? ")
- read_input(x)
- def check_hand():
- for z in hand:
- if True in check_card(z):
- return
- print '\n*** NO MORE VALID CARDS TO PLAY... YOU LOST !!! ***\n'
- game.pop()
- while 1:
- deck = full_deck[:]
- random.shuffle(deck)
- hand = []
- deal()
- game = ["Select The First Card To Place In The Pile...\n"]
- while game:
- cls()
- play_card()
- check_hand()
- x = raw_input("Play Again? ")
- if x.lower().startswith('n'):
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement