def workerGame(PLAYERS, getBet=None):
    '''
    Accumulate the results of several games' calcGameHistoryValue
    for a given number of players and betting strategy
    '''
    wins = [0, ] * PLAYERS

#    for i in xrange(100000):
    for _ in xrange(1000):
        game = Game(players=PLAYERS - 1, decks=8)

        if getBet != None:
            for player in game.players:
                player.getBet = getBet
        
        # game.players[0].getBet = flatBet
        if INTERACTIVE:
            game.players[1].interactive = True
     
        game.playShoe()
        
        w = game.calcGameHistoryValue()

        wins = map(lambda x, y: x + y, w, wins)

        if DEBUG:
            print "-"*20

    return sum(wins[:PLAYERS - 1]) / (wins[PLAYERS - 1] * float((PLAYERS - 1)))
def workerHandEVByCount(players=6, numGames=1000):
    '''
    Accumulate the results of several game' calcHandEVByCount
    for a given number of players and games.
    '''
    totEV = {}

    for _ in xrange(numGames):
        game = Game(players=players, decks=6)

        game.playShoe()

        gHandEV = game.calcHandEVByCount()

        for (key, (gResult, gTotHands)) in gHandEV.iteritems():
            result, totHands = totEV.get(key, (0, 0))
            result += gResult
            totHands += gTotHands
            totEV[key] = (result, totHands)
    return totEV
def fasterWorkerGame(PLAYERS, getBet=None, numShoes=10000):
    '''
    Accumulate the results of several games' fastCalcGameHistoryValue
    for a given number of players, betting strategy, and number of games
    '''
    netValue = 0
    netHands = 0
    
    for _ in xrange(numShoes):
        game = Game(players=PLAYERS - 1, decks=6)

        if getBet != None:
            for player in game.players:
                player.getBet = getBet
        
        game.playShoe()

        value, hands = game.fastCalcGameHistoryValue()

        netValue += value
        netHands += hands

    return netValue / (netHands * float((PLAYERS - 1)))
Ejemplo n.º 4
0
def main():
    """This function runs the gamble app"""

    print("Welcome to the BlackJack game. Good Luck!")
    print(" ")
    user_name = input('Please enter your name: ')
    user_choice = None

    player = Player(user_name)
    player.hand = Hand()
    dealer = Player('Dealer')
    dealer.hand = Hand()
    deck = Deck()
    game = Game(player, dealer, deck)
    print("-------")
    print('Welcome', user_name, ", Please choose what to do.")

    while user_choice != 4:
        print("1. Get chips")
        print("2. Start the game")
        print("3. Check balance")
        print("Press '4' to quit")

        try:
            user_choice = int(input('What would you like to do?\n'))
        except ValueError:
            print("-------")
            print("Please type in a value from 1 to 3")
            print("-------")
            print("")
            continue

        if user_choice == 1:
            try:
                print("-------")
                credit = int(input('How many chips would you like to have?\n'))
                if credit < 0:
                    raise ValueError
                player.credit += credit
                print('Now you have', player.credit, 'credits')
                print("-------")
            except ValueError:
                print("-------")
                print("Please enter an positive integer")
                print("-------")
                print("")
                continue

        elif user_choice == 2:
            one_more = 1

            while one_more == 1:
                game.play()
                print("-------")
                try:
                    one_more = int(input('One more game? (1 = Yes, 0 = No)\n'))
                except ValueError:
                    print("-------")
                    print("Please enter either '1' or '0' ")
                    print("-------")
                    continue

        elif user_choice == 3:
            print("-------")
            print('Your balance is now: ', player.credit)
            print("-------")

        elif user_choice == 4:
            break