2017-01-05 4 views
-1

블랙 잭 알고리즘을 만들고 싶습니다. 코드를 거의 완성했습니다. 비록 내가 항상 NameError : name 'pointCoint'오류가 정의되어 있지 않습니다. 나는 내가 사용하고있는 python 버전 3.6으로 인해 raw_input을 입력으로 변경해야한다는 것을 인터넷에서 발견했다. 누군가가 나를 도울 수 있고 뭔가를 놓치고 있는지 내 코드를 살펴볼 수 있습니까? dealerCount = pointCoint (대리점) 나가서 설명하자면 NameError : 이름이 'pointCoint은'NameError : name ''이 (가) 정의되지 않았습니다. Python

감사

당신은 pointCount(...)라는 함수가 아닌 pointCoint을 만든
+0

하여 들여 쓰기를 수정, 오류가 발생한 위치를 표시하고 최소한의 예를 아래 코드를 제거. –

+0

이 코드에는 많은 오류가 있지만 "pointCoint"라는 이름은 없습니다. 어떤 라인에서 오류가 발생합니까? – Marvo

+0

행 49, dealerCount = pointCoint (딜러) – userpython1

답변

0

를 정의되어 있지 않습니다. pointCointpointCount으로 변경하십시오.

전체 코드 :

from random import shuffle 

def deck(): 
    deck = [] 
    for suit in ['H', 'D', 'S', 'C']: 
     for rank in ['A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K']: 
      deck.append(suit+rank) 
    shuffle(deck) 
    return deck 

def pointCount(myCards): 
    myCount = 0 
    aceCount = 0 
    for i in myCards: 
     if(i[1] == 'J' or i[1] == 'Q' or i[1] == 'K' or i[1] == 'T'): 
      myCount += 10 
     elif(i[1] != 'A'): 
      myCount += int(i[1]) 
     else: 
      aceCount += 1 

    if(aceCount == 1 and myCount >= 10): 
     myCount += 11 
    elif(aceCount != 0): 
     myCount += 1 

    return myCount 

def createPlayingHands(myDeck): 
    dealerHand = [] 
    playerHand = [] 
    dealerHand.append(myDeck.pop()) 
    dealerHand.append(myDeck.pop()) 
    playerHand.append(myDeck.pop()) 
    playerHand.append(myDeck.pop()) 

    while(pointCount(dealerHand) <= 16): 
     dealerHand.append(myDeck.pop()) 

    return [dealerHand, playerHand] 

game = "" 
myDeck = deck() 
hands = createPlayingHands(myDeck) 
dealer = hands[0] 
player = hands[1] 

while(game != "exit"): 
    dealerCount = pointCount(dealer) 
    playerCount = pointCount(player) 
    print("Dealer has:") 
    print(dealer[0]) 

    print("Player1, you have:") 
    print(player) 

    if(playerCount == 21): 
     print("Blackjack Player wins") 
     break 
    elif(playerCount > 21): 
     print("player Busts with " + str(playerCount) + "points") 
     break 
    elif(playerCount > 21): 
     print("Dealer Busts with " + str(dealerCount) + "points") 
     break 

    game = input("What would you like to do? M: Hit me, S: Stand? ") 

    if(game == 'H'): 
     player.append(myDeck.pop()) 
    elif(playerCount > dealerCount): 
     print("Player wins with " + str(playerCount) + "points") 
     print("Dealer has: " + str(dealer) + "or" + str(dealerCount) + "points") 
     break 
    else: 
     print("Dealer wins") 
     print("Dealer has: " + str(dealer) + "or" + str(dealerCount) + "points") 
     break