コード例 #1
0
 def test_level53(self):
     self.assertEqual(matcher(["W", "L", "L", "W", "W", "L"], strategy1),
                      56)
コード例 #2
0
 def test_level01(self):
     self.assertEqual(matcher(["W"], strategy1), 0)
コード例 #3
0
 def test_level42(self):
     self.assertEqual(matcher(["W", "L", "L", "W", "W"], strategy1), 43)
コード例 #4
0
ファイル: script.py プロジェクト: sylwekg/blackjack
def game(dobraneKarty, money, baseBet, idlePlay, maxBet, selectedStrategy, strategyCoeff): # az do rozdania wszystkich kart w tali
    talia=['2','2','2','2',
           '3','3','3','3',
           '4','4','4','4',
           '5','5','5','5',
           '6','6','6','6',
           '7','7','7','7',
           '8','8','8','8',
           '9','9','9','9',
           '10','10','10','10',
           'J','J','J','J',
           'D','D','D','D',
           'K','K','K','K',
           'A','A','A','A'
            ]
    report=[]
    gamesRegister=[]
    #extending to 4 decks
    talia.extend(talia)
    talia.extend(talia)
    
    rozdanie = 0
    zostaloKart = 0
    totalWin=0
    HL = 0 
    realHL =0
    
    while len(talia) > 10:
        rozdanie +=1
        zostaloKart = len(talia)

        #pojedyncze rozdanie
        krupier = []
        user = []
        result = 0

        #bet set according to strategy
        if selectedStrategy=="hiloActive":
            baseBetHL=baseBet+realHL*baseBet
        
        elif selectedStrategy=="betStrategyActive":
            baseBetHL=baseBet*matcher(gamesRegister, strategyCoeff)
            if baseBetHL==0:
                baseBetHL=baseBet

        else:
            baseBetHL=baseBet

        if baseBetHL<idlePlay:
            baseBetHL= idlePlay

        #pobranie karty przez krupiera
        krupier=random.sample(talia, 1)
        for item in krupier:
            talia.remove(item)

        #dobieranie kart przez usera
        user=random.sample(talia, 2)
        for item in user:
            talia.remove(item)

        hitLimit = 0
        # if bestScore(score(krupier)) < 7:
        #     hitLimit=5
        while bestScore(score(user)) < (17-dobraneKarty-hitLimit):
            newCard=random.sample(talia, 1)
            for item in newCard:
                talia.remove(item)
            user.extend(newCard)

        #dobieranie kart przez krupiera
        if bestScore(score(user)) <= 21:
            while bestScore(score(krupier)) < bestScore(score(user)):
                newCard=random.sample(talia, 1)
                for item in newCard:
                    talia.remove(item)
                krupier.extend(newCard)
            # czy remis
            if bestScore(score(krupier)) == bestScore(score(user)):
                result = 0

            elif bestScore(score(krupier)) > 21:
                result = 1
                totalWin+=1
                money += baseBetHL
            
            else:
                money -= baseBetHL    

        else:
            money -= baseBetHL

        if result==0:
            gamesRegister.append("L")
            resultBackground="lose"
        elif result==1:
            gamesRegister.append("W")
            resultBackground="win"
        
        if len(gamesRegister)>6:
            gamesRegister.pop(0)


        HL = hiLo(HL, krupier, user)
        realHL = HL/4

        print("\nUser: "******"Krupier: "+str(bestScore(score(krupier))), krupier)
        # print("Talia: ",talia)
        print("Result: "+str(totalWin)+"/"+str(rozdanie))
        print("Zostało kart:", len(talia))
        print("real HI-LO: "+str(realHL))
        print("money: ",money)
        print("bet :",baseBetHL)
        print("game register :",gamesRegister)
        report.append({ 
            "no": str(rozdanie),
            "userScore": str(bestScore(score(user))), 
            "userCards": user,
            "krupierScore": str(bestScore(score(krupier))),
            "krupierCards": krupier,
            "totalWin": str(totalWin),
            "cardsLeft": str(len(talia)),
            "realHL": str(realHL),
            "balance":str(money),
            "bet": str(baseBetHL),
            "result": resultBackground
            })
    
    return report

# cykl 1..2..3 (kilkaset rozdań) - dobieram 0..1..2 kart gdy score < 17
    #----- losuj karte dla krupiera -> Input 1
    #----- losuj karty dla usera -> Input 2
    # dobieraj karty dla krupiera az > Input 2
    # zapisz wygrana/przegrana -> Output


    
# money = []
# balance = 1000
# for i in range(1):
#     baseBet = 10
#     # balance =  game(0, balance, baseBet)
#     money.append( game(0, 1000, baseBet))

# print(money)

# plt.hist(money, normed=True, bins=30)
# plt.ylabel('Probability')
# plt.show()