Python: CARD GAME BOT - Remastering(你如何让一条线无论在哪里都继续?)
Python: CARD GAME BOT - Remastering (How do you make a line continue regardless of where it is?)
我正在自己重新制作机器人,但我被卡住了!这是一个代码,提示用户 select 他们从
的选项中获得了多少张卡片
7, 9, 11, and 15
def Cards():
print("Card Amounts")
print("\nChoices")
print(7)
print(9)
print(11)
print(15)
PlayerInput3()
def PlayerInput3():
global PlayersCards
PlayerInput = int(raw_input())
if(PlayerInput == 7):
PlayersCards == range(1,7)
print("Lets get started")
Game()
但是当他们选择他们想要多少张牌时,它在定义结束后仍然有效。我希望玩家卡范围在不同的定义区域中继续。这里:
def Game():
global roundNumber, MyDeck, PlayersCards
import random
Select = PlayersCards
roundNumber = roundNumber + 1
print("Round %d!") % (roundNumber)
if(roundNumber == 1) or (roundNumber < 15):
PlayersCards = random.randint(1, 50)
MyDeck.append(PlayersCards)
print("Here are your cards")
print(MyDeck)
print("Select a card")
但它不会继续超过
def Cards():
我怎样才能让 PlayersCard == range(1,7) 继续,而不管它的定义是什么?
我认为这段代码可以满足您的要求:
def instructions():
print("You will be playing with an ai and whoever lays down the highest number wins that round.")
print("The points you get are determined by how much higher your card was from your opponents card.")
print("The person with the most points wins!")
def getUserInput():
global roundNumber, My_Deck, PlayerPoints, AIPoints
My_Deck = []
roundNumber = 0
AIPoints = 0
PlayerPoints = 0
print ("\nDo you want to play?: ")
print("\nChoices")
print("1. Yes")
print("2. No\n")
Choice = input()
if(Choice == 'Yes') or (Choice == 'yes'):
print("\nOkay, lets get started!")
startGame()
elif(Choice in ['No', 'no']):
print("Okay, bye!")
quit()
else:
print("That is not a Choice!")
print("Choose 'Yes' or 'No'")
getUserInput()
def startGame():
global roundNumber, My_Deck, PlayerPoints, AIPoints
print("\nAIPoints = %d PlayerPoints = %d" % (AIPoints, PlayerPoints))
roundNumber = roundNumber + 1
print("\nRound %d!" % (roundNumber))
cardChoosen = None
import random
if(roundNumber == 1):
print("\nHere are your 9 cards.\n")
for Cards in range(9):
Cards = random.randint(1, 100)
My_Deck.append(Cards)
while True:
print("Select one of your cards: "),
print(My_Deck)
Select = int(input())
try:
if (Select in My_Deck):
My_Deck.remove(Select)
print("You choose", Select)
print("Your deck now is:")
print(My_Deck)
cardChoosen = Select
break
else:
print("You don't have that card in your deck!")
except ValueError as e:
print(e)
elif(roundNumber == 10):
if(PlayerPoints > AIPoints):
print("\nCongratulations you won with a score of %d compared to the AI's %d" % (PlayerPoints, AIPoints))
getUserInput()
elif(PlayerPoints < AIPoints):
print("\nUnfortunately you lost with a score of %d compared to the AI's %d" % (PlayerPoints, AIPoints))
getUserInput()
else:
print("\nWow this is basicaly impossible you tied with the AI with you both ahving a score of %d and %d... " % (PlayerPoints, AIPoints))
getUserInput()
else:
print("\nHere are your %d cards.\n" % (9 - roundNumber + 1))
while True:
print("Select one of your cards: "),
print(My_Deck)
Select = int(input())
try:
if (Select in My_Deck):
My_Deck.remove(Select)
print("You choose", Select)
print("Your deck now is:")
print(My_Deck)
cardChoosen = Select
break
else:
print("You don't have that card in your deck!")
except ValueError as e:
print(e)
AINumber = random.randint(1, 100)
if(cardChoosen > AINumber):
print("\nYou won! Your number %d was higher than the AI's number %d" % (cardChoosen, AINumber))
print("\nYou scored %d points" % (cardChoosen - AINumber))
PlayerPoints = PlayerPoints + (cardChoosen - AINumber)
startGame()
elif(cardChoosen < AINumber):
print("\nYou Lost! Your number %d was lower than the AI's number %d" % (cardChoosen, AINumber))
print("\nAI scored %d points" % (AINumber - cardChoosen))
AIPoints = AIPoints + (AINumber - cardChoosen)
startGame()
else:
print("\nYou tied with the AI! Your number %d was the same as the AI's number %d" % (cardChoosen, AINumber))
print("\nNobody scored points!")
startGame()
My_Deck = []
roundNumber = 0
AIPoints = 0
PlayerPoints = 0
instructions()
getUserInput()
我正在自己重新制作机器人,但我被卡住了!这是一个代码,提示用户 select 他们从
的选项中获得了多少张卡片
7, 9, 11, and 15
def Cards():
print("Card Amounts")
print("\nChoices")
print(7)
print(9)
print(11)
print(15)
PlayerInput3()
def PlayerInput3():
global PlayersCards
PlayerInput = int(raw_input())
if(PlayerInput == 7):
PlayersCards == range(1,7)
print("Lets get started")
Game()
但是当他们选择他们想要多少张牌时,它在定义结束后仍然有效。我希望玩家卡范围在不同的定义区域中继续。这里:
def Game():
global roundNumber, MyDeck, PlayersCards
import random
Select = PlayersCards
roundNumber = roundNumber + 1
print("Round %d!") % (roundNumber)
if(roundNumber == 1) or (roundNumber < 15):
PlayersCards = random.randint(1, 50)
MyDeck.append(PlayersCards)
print("Here are your cards")
print(MyDeck)
print("Select a card")
但它不会继续超过
def Cards():
我怎样才能让 PlayersCard == range(1,7) 继续,而不管它的定义是什么?
我认为这段代码可以满足您的要求:
def instructions():
print("You will be playing with an ai and whoever lays down the highest number wins that round.")
print("The points you get are determined by how much higher your card was from your opponents card.")
print("The person with the most points wins!")
def getUserInput():
global roundNumber, My_Deck, PlayerPoints, AIPoints
My_Deck = []
roundNumber = 0
AIPoints = 0
PlayerPoints = 0
print ("\nDo you want to play?: ")
print("\nChoices")
print("1. Yes")
print("2. No\n")
Choice = input()
if(Choice == 'Yes') or (Choice == 'yes'):
print("\nOkay, lets get started!")
startGame()
elif(Choice in ['No', 'no']):
print("Okay, bye!")
quit()
else:
print("That is not a Choice!")
print("Choose 'Yes' or 'No'")
getUserInput()
def startGame():
global roundNumber, My_Deck, PlayerPoints, AIPoints
print("\nAIPoints = %d PlayerPoints = %d" % (AIPoints, PlayerPoints))
roundNumber = roundNumber + 1
print("\nRound %d!" % (roundNumber))
cardChoosen = None
import random
if(roundNumber == 1):
print("\nHere are your 9 cards.\n")
for Cards in range(9):
Cards = random.randint(1, 100)
My_Deck.append(Cards)
while True:
print("Select one of your cards: "),
print(My_Deck)
Select = int(input())
try:
if (Select in My_Deck):
My_Deck.remove(Select)
print("You choose", Select)
print("Your deck now is:")
print(My_Deck)
cardChoosen = Select
break
else:
print("You don't have that card in your deck!")
except ValueError as e:
print(e)
elif(roundNumber == 10):
if(PlayerPoints > AIPoints):
print("\nCongratulations you won with a score of %d compared to the AI's %d" % (PlayerPoints, AIPoints))
getUserInput()
elif(PlayerPoints < AIPoints):
print("\nUnfortunately you lost with a score of %d compared to the AI's %d" % (PlayerPoints, AIPoints))
getUserInput()
else:
print("\nWow this is basicaly impossible you tied with the AI with you both ahving a score of %d and %d... " % (PlayerPoints, AIPoints))
getUserInput()
else:
print("\nHere are your %d cards.\n" % (9 - roundNumber + 1))
while True:
print("Select one of your cards: "),
print(My_Deck)
Select = int(input())
try:
if (Select in My_Deck):
My_Deck.remove(Select)
print("You choose", Select)
print("Your deck now is:")
print(My_Deck)
cardChoosen = Select
break
else:
print("You don't have that card in your deck!")
except ValueError as e:
print(e)
AINumber = random.randint(1, 100)
if(cardChoosen > AINumber):
print("\nYou won! Your number %d was higher than the AI's number %d" % (cardChoosen, AINumber))
print("\nYou scored %d points" % (cardChoosen - AINumber))
PlayerPoints = PlayerPoints + (cardChoosen - AINumber)
startGame()
elif(cardChoosen < AINumber):
print("\nYou Lost! Your number %d was lower than the AI's number %d" % (cardChoosen, AINumber))
print("\nAI scored %d points" % (AINumber - cardChoosen))
AIPoints = AIPoints + (AINumber - cardChoosen)
startGame()
else:
print("\nYou tied with the AI! Your number %d was the same as the AI's number %d" % (cardChoosen, AINumber))
print("\nNobody scored points!")
startGame()
My_Deck = []
roundNumber = 0
AIPoints = 0
PlayerPoints = 0
instructions()
getUserInput()