我目前正在使用python進行二十一點玩家模擬器工作,用戶可以通過遊戲中的步驟進行操作。我已經在程序結構方面取得了一些成功,但是在嘗試通過應用程序觸發時會觸發我的邏輯。例如,通常在抽取王牌時,「新總計」文本重複一次。該計劃的另一個問題是,當抽籤一張A時,所用的兩個總數不會像我所希望的那樣進入下一張抽牌/總數。作爲編程新手,我提前抱歉,由於我在識別深度錯誤時遇到了問題,因此我的描述聽起來很模糊。如何解決我的「二十一點播放器模擬器」的邏輯?
所有幫助表示讚賞。
import random
def play_hand_dealer():
total = 0
player_is_bust = False
ace_was_thrown = False
another_card = True
ace_total = 0
high_ace = 10
while player_is_bust == False and another_card != "n":
card = random.choice([1,2,3,4,5,6,7,8,9,10,10,10,10])
total = total + int(card)
if card == 1:
ace_was_thrown = True
ace_total = high_ace + int(total)
print("Ace New Total is", total, "or", ace_total, end = " ")
if ace_total < 21 and ace_was_thrown:
ace_total = total + 10
print("New Total is ", total, "or", ace_total, end = " ")
else:
print(card, "New Total is ", total, end = " ")
if total > 21:
player_is_bust = True
if total < 21:
another_card = input("Another Card? ")
if ace_was_thrown:
if total + 10 >= 17 and total + 10 <= 21:
total = total + 10
if player_is_bust:
print("Bust")
else:
print(" Final Total:",total)
choice = ""
while(choice != "q"):
play_hand_dealer()
print()
choice = input("Enter to play again , or 'q' to quit: ")
print()
也許這個問題,它更適合Code Review.SE。嘗試將你的問題分成更具體的編程問題。 – iled
@iled只要有「邏輯錯誤」,它根本不屬於Code Review。請閱讀[Stack Overflow用戶代碼評論指南](http://meta.codereview.stackexchange.com/questions/5777/a-guide-to-code-review-for-stack-overflow-users) –
@ SimonForsbergMcFeely謝謝,這很有幫助。我已經看到其他類似的問題被建議去CR,但是這個話題更加清晰。謝謝。無論如何,我仍然認爲OP應該用更小更具體的問題來解決這個問題。 – iled