예제 #1
0
파일: game.py 프로젝트: Dormeus/BlackJack
def whowins(person, cpu, offer):
    winlose = True
    playerDiff = 21 - hand.handvalue(person)
    aiDiff = 21 - hand.handvalue(cpu)
    if (playerDiff < aiDiff and playerDiff >= 0) or (playerDiff >= 0 and aiDiff < 0):
        if aiDiff < 0:
            print("Your opponent busted!")
        print ("You win!")
        mplayer.get(offer, winlose)
        mai.get(offer, winlose)
    elif (playerDiff < 0 and aiDiff < 0) or playerDiff == aiDiff:
        if playerDiff < 0 and aiDiff < 0:
            print("Both players busted.")
        elif playerDiff == aiDiff:
            print ("Both players got the same score.")
        print("It's a draw!")
    else:
        print ("You lost!")
        winlose = False
        mplayer.get(offer, winlose)
        mai.get(offer, winlose)
예제 #2
0
파일: ai.py 프로젝트: Dormeus/BlackJack
 def choose(self):
     greaterCard = 0.0
     deckSize = 52.0
     while True:
         need = 21- hand.handvalue(self)
         if (need <= 0):
             break
         for x in range (1, 53):
             if (deck.deck[x] == 0):
                 deckSize = deckSize - 1.0
             elif (deck.deck[x] != 0):
                 if (hand.check(deck.deck[x], self) > need):
                     greaterCard = greaterCard + 1.0
         bustProb = greaterCard/deckSize
         if (bustProb < 0.50):
             hand.deal(self)
         else:
             break
예제 #3
0
파일: game.py 프로젝트: Dormeus/BlackJack
    print("You received a: %s\n" % (hand.name(hand.deal(player))))

    #deals two cards to ai

    print("AI received two cards...")
    print("AI's card shown: " + hand.name(hand.deal(ai))+"\n")
    hand.name(hand.deal(ai))

    #hit or stay? 



    offer = money.bet (player.owner)

    while True:
        cardsum = hand.handvalue(player)
        print("Your cards sum up to: " + str(hand.handvalue(player)))
        if cardsum > 21:
            print ("You're Busted!")
            break
        else:
            print("Would you like another card??")
            hit = input("Type in 'hit' for another card or 'stay' if you are satisfied with your current hand: \n")
            if hit == "stay":
                break
            elif hit == "hit":
                print("You received a: " + hand.name(hand.deal(player)))

    ai.choose()
    print ("\n%s's hand: " % ai.owner)
    ai.show_hand()