【发布时间】:2019-02-04 16:00:44
【问题描述】:
好的,我在将牌发给两名玩家后进入下一步。
我需要该程序能够获取玩家想要摆脱的所需卡片并将它们交换为新的随机卡片。玩家将被询问想要交换多少张牌和哪些牌。代码应该类似于玩家为一张一次性卡片输入“1”,然后玩家可以选择移除哪张卡片。因此,该卡将从手牌或代码列表中移除并替换为 1 张新卡。这只发生一次,然后它应该打印两个玩家的手。
我看到的每一个地方都以更复杂的方式完成,我知道这是简单的编码,但我确实对最简单的事情一无所知。
到目前为止我得到了什么:
def poker():
import random
(raw_input('Welcome to a classic game of Poker! You will recieve 5 cards. You will have the option to exchange 1 to 3 cards from your hand for new cards of the same amount you exchanged. IF you have an Ace in your beginning hand, you may exchange that Ace for up to four new cards (three other cards including the ace). ~Press Enter~'))
(raw_input('S = Spades , H = Hearts , C = Clubs , D = Diamonds ~Press Enter~'))
deck = ['2S','2H','2C','2D','3S','3H','3C','3D','4S','4H','4C','4D','5S','5H','5C','5D','6S','6H','6C','6D','7S','7H','7C','7D','8S','8H','8C','8D','9S','9H','9C','9D','10S','10H','10C','10D','Jack(S)','Jack(H)','Jack(C)','Jack(D)','Queen(S)','Queen(H)','Queen(C)','Queen(D)','King(S)','King(H)','King(C)','King(D)', 'Ace(S)','Ace(H)','Ace(C)','Ace(D)']
new_cards = ''
player1 = []
player2 = []
random.shuffle(deck)
for i in range(5): player1.append(deck.pop(0)) and player2.append(deck.pop(0))
print player1
int(input('How many cards would you like to exchange? 1, 2, 3, or 4 IF you have an Ace.'))
#ignore this for now
int(input('Which card would you like to exchange? 1, 2, 3, 4, or 5? Note: The first card in your hand (or list in this case) is the number 1 spot. So if you want to exchange the first card, input 1. The same is for the other cards.'))
在开始时交换的牌在交换后也无法从套牌列表中访问。就像... ['8D','2S','Queen(H),'8S','Jack(H)'] 如果我想移除 1 张牌,我选择移除“2S”,“2S”将不再在我的手上,将与牌组中的另一张牌交换。 '2S'也不会以任何理由回到我的手中,因为它不能再次从列表中取出。所以输出应该是所有相同的卡,除了“2S”将丢失并且新卡将在它的位置。
标准是一次最多移除 3 张牌,但如果您的起始手牌中有 A,您也可以最多移除 4 张牌。但是你应该被拒绝,然后再次询问如果你不提供 A 的话,你想摆脱多少张牌。
【问题讨论】:
标签: python