2016-11-22 71 views
0

我正在尝试制作一个卡交易计划。交易卡和退货剩余物

  • 有5名球员。
  • 给出了甲板订单。
  • 该方案从牌组顶部一次处理一张牌。
    • 桌子的顶部是堆叠的开始。
  • 程序返回:
    • 5只球员手和
    • 仍包中的卡。

功能:

def deal_cards(FIVE,card_list): 
    card_list = = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] * 4 
    hand_one = [] 
    hand_two = [] 
    hand_three = [] 
    hand_four = [] 
    hand_five = [] 
    for i in card_list: 
     hand_one = card_list.append(i) 
     hand_two = card_list.pop(i + 1) 
     hand_three = card_list.pop(i + 2) 
     hand_four = card_list.pop(i + 3) 
     hand_five = card_list.pop(i + 4) 

    return hand_one, hand_two, hand_three, hand_four, hand_five 

主营:

print("Deck - ", end="") 
print(*card_list) 
hand_one, hand_two, hand_three, hand_four, hand_five = deal_cards(card_list) 
print("Player 1 - ", end="") 
print(*hand_one) 
print("Player 2 - ", end="") 
print(*hand_two) 
print("Player 3 - ", end="") 
print(*hand_three) 
print("Player 4 - ", end="") 
print(*hand_four) 
print("Player 5 - ", end="") 
print(*hand_five) 
+5

好了,什么是你的问题? –

+0

我不知道该从这里做什么,不能得到代码工作。返回剩余值也是一样。我主要质疑我如何将牌放在玩家手中以查看其优化与否。我得到空白打印此 – okai

+0

欢迎来到StackOverflow。请阅读并遵守帮助文档中的发布准则。 [最小,完整,可验证的示例](http://stackoverflow.com/help/mcve)适用于此处。在您发布代码并准确描述问题之前,我们无法有效帮助您。 – Prune

回答

0

我用这个:

colors=[('spades','♠'), ('hearts','♥'),('diamonds','♦'),('clubs','♣')] 
colors=[s for (n,s) in colors] 
faces=['A','2','3','4','5','6','7','8','9','1','J','Q','K'] 

cards=list(__import__("itertools").product(colors, faces)) 

__import__("random").shuffle(cards) 

nbplayers=5 
nbcards=6 

def cardstostr(cards): 
    return ",".join(map(lambda (c,f): f+c, cards)) 

for i in range(nbplayers): 
    print cardstostr(cards[nbcards*i:nbcards*(i+1)]) 
print cardstostr(cards[nbplayers*nbcards:])