好的,我将卡片分发给两名玩家后,进入下一步。
我需要该程序能够拿走想要摆脱的玩家所需的纸牌并将其交换为新的随机纸牌。玩家将被询问要交换多少张卡。代码应该类似于如果玩家为一张一次性纸牌输入“ 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牌,那么您想淘汰多少张牌。
答案 0 :(得分:0)
以下是可行的:
n_cards_to_exchange = int(input('How many cards would you like to exchange? 1, 2, 3, or 4 IF you have an Ace.'))
for i in range(n_cards_to_exchange):
print(player1)
card_text = ', '.join([str(j) for j in range(1,5-i)]) + f', or {5-i}?'
card_id = int(input(f'Which card would you like to exchange? {card_text} 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.')) - 1
deck.append(player1.pop(card_id))
random.shuffle(deck)
for i in range(n_cards_to_exchange):
player1.append(deck.pop(0))
这个想法是,玩家选择他想丢的牌数量,然后选择他想丢多次的牌。然后他从卡组中抽回卡片。如果您需要任何澄清,请随时询问。