【问题标题】:Poker Game Swapping Out Cards For Different Cards扑克游戏用不同的牌交换牌
【发布时间】: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


    【解决方案1】:

    以下是可行的:

    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))
    

    这个想法是玩家选择他想要丢弃的卡片数量,然后选择他想要多次丢弃的卡片。然后他从牌堆中抽回牌。如果您需要任何说明,请随时询问。

    【讨论】:

    • 语法无效..? for i in range(n_cards_to_exchange):
    • 实际上,整个事情都行不通。我尝试修复它,但没有任何效果。
    • 我编辑了帖子以修复语法错误。我检查了它,它现在应该可以工作了:)
    • card_text 变量的语法也无效。我讨厌打扰,但也许我的游戏只是讨厌我。老实说,我什至不知道那里的 f 是用来做什么的。我编程太差了。
    • 帮助..?你确定你检查了吗?
    猜你喜欢
    • 2016-03-01
    • 2012-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-14
    • 1970-01-01
    相关资源
    最近更新 更多