因此,对于我正在编写的这段代码,我试图为三个不同的玩家生成一组三张随机卡,其中一个是人类,两个是模拟的。为此,我正在使用这段代码。
def shuffle_p1():
p_1_human_card_1=random.randint(1,3)
p_1_human_card_2=random.randint(1,3)
p_1_human_card_3=random.randint(1,3)
p_1_human_cards=[p_1_human_card_1,p_1_human_card_2,p_1_human_card_3]
return (p_1_human_cards)
def shuffle_p2():
p_2_ai_card_1=random.randint(1,3)
p_2_ai_card_2=random.randint(1,3)
p_2_ai_card_3=random.randint(1,3)
p_2_ai_cards=[p_2_ai_card_1,p_2_ai_card_2,p_2_ai_card_3]
return (p_1_human_cards)
def shuffle_p3():
p_3_ai_card_1=random.randint(1,3)
p_3_ai_card_2=random.randint(1,3)
p_3_ai_card_3=random.randint(1,3)
p_3_ai_cards=[p_3_ai_card_1,p_3_ai_card_2,p_3_ai_card_3]
return (p_1_human_cards)
p_1_human_cards=shuffle_p1()
p_2_ai_cards=shuffle_p2()
p_3_ai_cards=shuffle_p3()
这会生成三组,但玩家 1 和玩家 2 每次都拥有完全相同的牌。我什至放置了一组不同的代码
def card_auth_p1():
while p_1_human_cards[0]==p_1_human_cards[1] or p_1_human_cards[0]==p_1_human_cards[2]:
p_1_human_cards[0]=random.randint(1,3)
while p_1_human_cards[1]==p_1_human_cards[0] or p_1_human_cards[1]==p_1_human_cards[2]:
p_1_human_cards[1]=random.randint(1,3)
def card_auth_p2():
while p_2_ai_cards[0]==p_2_ai_cards[1] or p_2_ai_cards[0]==p_2_ai_cards[2]:
p_2_ai_cards[0]=random.randint(1,3)
while p_2_ai_cards[1]==p_2_ai_cards[0] or p_2_ai_cards[1]==p_2_ai_cards[2]:
p_2_ai_cards[1]=random.randint(1,3)
def card_auth_p3():
while p_3_ai_cards[0]==p_3_ai_cards[1] or p_3_ai_cards[0]==p_3_ai_cards[2]:
p_3_ai_cards[0]=random.randint(1,3)
while p_3_ai_cards[1]==p_3_ai_cards[0] or p_3_ai_cards[1]==p_3_ai_cards[2]:
p_3_ai_cards[1]=random.randint(1,3)
并且
if p_1_human_cards == p_2_ai_cards or p_1_human_cards == p_3_ai_cards:
p_1_human_cards=shuffle_p1()
if p_2_ai_cards == p_1_human_cards or p_2_ai_cards == p_3_ai_cards:
p_2_ai_cards=shuffle_p2()
以确保它们并不完全相同,但打印三个列表表明玩家 1 和 2 仍然相同。此外,即使在使用此代码在三组之间进行随机交易的第四个代码块之后
aluckdog
翻翻过去那场雪