[英]remove an item from one list and store it into the end of another list
我正在用 python 制作一個簡單的紙牌游戲,其中玩家比較一張紙牌的統計數據,具有較高統計值的紙牌贏得本輪比賽,輸家給他們那張紙牌,將其從牌組中取出並將其放入最后優勝者甲板。
這是我的游戲代碼,其中包括一輪游戲玩法:
import random
class Ram():
def __init__(self, name, weight, milk, wool, offs, thigh, fert, meat, fat):
self.name = name
self.weight = weight
self.milk = milk
self.wool = wool
self.offs = offs
self.thigh = thigh
self.fert = fert
self.meat = meat
self.fat = fat
def __repr__(self):
return f"{self.name,self.weight,self.milk,self.wool,self.offs,self.thigh,self.fert,self.meat,self.fat}"
def Read(txtfile):
datalist=[]
f = open(txtfile, "r", encoding="utf-8")
for line in f:
datalist.append(line.split(','))
f.close()
cardlist = []
for i in datalist:
cardlist.append(Ram(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]))
return cardlist
def RandomChoice():
l=["User","Computer"]
return random.choice(l)
cardlist=Read("hrutaspil.txt")
random.shuffle(cardlist)
split = len(cardlist) // 2
user_deck = cardlist[:split]
computer_deck = cardlist[split:]
game=input("Do you want to play?(y/n)")
if game == "y":
if RandomChoice() == "User":
print("The user chooses first")
print("Your top card is:",user_deck[0].name)
print("1 = weight =",user_deck[0].weight)
print("2 = milk =", user_deck[0].milk)
print("3 = wool =", user_deck[0].wool)
print("4 = offs =", user_deck[0].offs)
print("5 = thigh =", user_deck[0].thigh)
print("6 = fert =", user_deck[0].fert)
print("7 = meat =", user_deck[0].meat)
print("8 = fat =", user_deck[0].fat)
choice=input("Choose stat: ")
if choice == ("1"):
print("Weight is:",float(user_deck[0].weight))
print("compared with computer:",float(computer_deck[0].weight))
if float(computer_deck[0].weight) > float(user_deck[0].weight):
print("Computer wins.")
else:
print("You win.")
現在,我如何從失敗者牌組中取出一張牌並將其添加到獲勝者牌組的底部?
if float(computer_deck[0].weight) > float(user_deck[0].weight):
print("Computer wins.")
computer_deck.append(user_deck.pop(0))
else:
print("You win.")
user_deck.append(computer_deck.pop(0))
您是否也知道用戶贏得了關系? 根據閱讀您的問題,我不確定這是您的意圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.