Advertisement
Guest User

idiotsimulator

a guest
Jul 7th, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. import random
  2. initdeck = [(s,v) for s in "♥♠♦♣" for v in range(2,15)] # 15 = ace
  3. initboard = [[],[],[],[]]
  4.  
  5. random.shuffle(initdeck)
  6.  
  7. def deal(deck,board):
  8.     for i in board:
  9.         i.append(deck.pop())
  10.  
  11. def eliminate(board):
  12.     hits = 0
  13.     for i in board:
  14.         if len(i)>0:
  15.             card = i[-1]
  16.             for j in board:
  17.                 if len(j)>0:
  18.                     bard = j[-1]
  19.                     if card[0] == bard[0] and card[1]>bard[1]:
  20.                         j.remove(bard)
  21.                         hits += 1
  22.         else:
  23.             c = False
  24.             for j in board:
  25.                 if len(j)>1:
  26.                     c = True
  27.                     break
  28.             if c:
  29.                 printboard(board)
  30.                 raw = input("which card to move to empty slot? >")
  31.                 if 1<=int(raw)<=4:
  32.                     i.append(board[int(raw)-1].pop())
  33.                 return 1
  34.     return hits
  35.  
  36. def printboard(board):
  37.     for i in board:
  38.         line = str(board.index(i)+1)+". "
  39.         for j in i:
  40.             line += j[0]+str(j[1])+" "
  41.         print(line)
  42.     print("")
  43.  
  44. def play(deck,board):
  45.     while(len(deck)>0):
  46.         deal(deck,board)
  47.         printboard(board)
  48.         while(eliminate(board)>0):
  49.             printboard(board)
  50.        
  51.     if checkvictory(board):
  52.         print("VICTORY!")
  53.     else:
  54.         print("YOU LOOOOSE!")
  55.  
  56. def checkvictory(board):
  57.     for i in board:
  58.         if not (len(i)==1 and i[0][1]==15):
  59.             return False
  60.     return True
  61.  
  62. play(initdeck,initboard)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement