Exemplo n.º 1
0
    def bet(self, communityData, playerPot: int):
        #predefined pre-flop behavior - try to go into flop with low cost
        moves = MoveValidator.availableAndLegalMoves(communityData, playerPot, self.balance)
        if len(communityData.actions) == 1:
            if Move.CALL in moves: return Move.CALL
            elif Move.CHECK in moves: return Move.CHECK
            elif Move.BLIND in moves: return Move.BLIND
            return Move.QUIT

        playerList = set(x[0] for x in communityData.actions[-1] if x[0] != self.name)

        commVal = CardVal.combination(communityData.communityCards)
        predictedHands = [knn[len(communityData.actions)-2].predict([[
            commVal,
            countBets(player, communityData.actions[-1]),
            countCalls(player, communityData.actions[-1])
        ]]) for player in playerList]

        if len(predictedHands) > 0 and\
           max(predictedHands) > CardVal.combination(communityData.communityCards + self.hand):
            return Move.FOLD

        if random.choice([True, False]):
            if Move.BET in moves: return Move.BET
            elif Move.RAISE in moves: return Move.RAISE
        else:
            if Move.CALL in moves: return Move.CALL
            elif Move.CHECK in moves: return Move.CHECK
        
        return Move.FOLD if Move.FOLD in moves else Move.QUIT
Exemplo n.º 2
0
    def bet(self, communityData, playerPot: int):
        #predefined pre-flop behavior - try to go into flop with low cost
        moves = MoveValidator.availableAndLegalMoves(communityData, playerPot,
                                                     self.balance)
        if Move.BLIND in moves: return Move.BLIND
        if moves == [Move.QUIT]: return Move.QUIT
        if len(communityData.actions) == 1:
            strategy = handToStartCategory(self.hand)
            if strategy in [StartCat.PLAYABLE_EXTENT, StartCat.PLAYABLE] or\
              (strategy == StartCat.UNTIL_RAISE and sum(1 for x in communityData.actions[-1]if x[1] in [Move.BET, Move.RAISE])):
                if Move.CALL in moves: return Move.CALL
                if Move.CHECK in moves: return Move.CHECK
            return Move.FOLD

        playerList = set(x[0] for x in communityData.actions[-1]
                         if x[0] != self.name)
        commVal = list(
            map(lambda x: CardVal.checkHighCard([x]) / 1.0,
                communityData.communityCards))
        predStr = []
        for idx, player in enumerate(playerList):
            ans = tf.convert_to_tensor(
                tuple([[
                    *commVal[:3 + len(communityData.actions) - 2],
                    countCalls(player, communityData.actions[-1]),
                    countBets(player, communityData.actions[-1]), idx / 1.0,
                    len(playerList) / 1.0
                ]]))
            predStr.append(*ann[len(communityData.actions) - 2].predict(ans))

        if len(predStr) > 0:

            ans = tf.convert_to_tensor(
                tuple([[
                    *[CardVal.checkHighCard([x]) / 1.0 for x in self.hand],
                    *commVal,
                    max(predStr)[0]
                ]]))
            if dec_ann[len(communityData.actions) - 2].predict(ans) > 0.9:
                if random.choice([True, False]):
                    if Move.BET in moves: return Move.BET
                    elif Move.RAISE in moves: return Move.RAISE
                else:
                    if Move.CALL in moves: return Move.CALL
                    elif Move.CHECK in moves: return Move.CHECK

        if Move.CHECK in moves: return Move.CHECK
        return Move.FOLD if Move.FOLD in moves else Move.QUIT
Exemplo n.º 3
0
 def __showdown(self) -> None:
     players = self.betQueue.getNonFoldingPlayers()
     winners = CardValidator.showdown(players, self.betQueue.getCommCards())
     prize = self.betQueue.getBankroll() // len(winners)
     prizeToSmallBets = prize // (self.betQueue.communityData.limit // 2)
     for player in players:
         player.agent.handsPlayed += 1
         if player in winners:
             player.incrBalance(prize)
             player.agent.smallBets += prizeToSmallBets
         else:
             player.agent.smallBets -= prizeToSmallBets
     for player in self.betQueue.allPlayers():
         player.agent.showdown(winners, players)
Exemplo n.º 4
0
    def bet(self, communityData, playerPot: int):
        #predefined pre-flop behavior - try to go into flop with low cost
        moves = MoveValidator.availableAndLegalMoves(communityData, playerPot,
                                                     self.balance)
        if len(communityData.actions) == 1:
            if Move.CALL in moves: return Move.CALL
            elif Move.CHECK in moves: return Move.CHECK
            elif Move.BLIND in moves: return Move.BLIND
            return Move.QUIT

        playerList = set(x[0] for x in communityData.actions[-1]
                         if x[0] != self.name)
        commVal = list(
            map(lambda x: CardVal.checkHighCard([x]) / 1.0,
                communityData.communityCards))
        predStr = []
        for idx, player in enumerate(playerList):
            ans = tf.convert_to_tensor(
                tuple([[
                    *commVal[:3 + len(communityData.actions) - 2],
                    countCalls(player, communityData.actions[-1]),
                    countBets(player, communityData.actions[-1]), idx / 1.0,
                    len(playerList) / 1.0
                ]]))
            predStr.append(ann[len(communityData.actions) - 2].predict(ans))
        if len(predStr) > 0 and\
           max(predStr) > CardVal.combination(communityData.communityCards + self.hand):
            return Move.FOLD
        if random.choice([True, False]):
            if Move.BET in moves: return Move.BET
            elif Move.RAISE in moves: return Move.RAISE
        else:
            if Move.CALL in moves: return Move.CALL
            elif Move.CHECK in moves: return Move.CHECK

        if Move.CHECK in moves: return Move.CHECK
        return Move.FOLD if Move.FOLD in moves else Move.QUIT
Exemplo n.º 5
0
    def bet(self, communityData: CommunityData, playerPot: int):
        moves = MoveValidator.availableAndLegalMoves(communityData, playerPot,
                                                     self.balance)
        if len(communityData.actions) == 1:
            if Move.CALL in moves: return Move.CALL
            elif Move.CHECK in moves: return Move.CHECK
            elif Move.BLIND in moves: return Move.BLIND
            return Move.QUIT

        handValue = CardValidator.combination(self.hand +
                                              communityData.communityCards)
        ihr = ((handValue * 100) / 1743)
        print('---formula based---\nhands: ')
        [print(x.asString()) for x in self.hand]
        print('ihr > ', ihr)
        if ihr > 35:
            if Move.BET in moves: return Move.BET
            elif Move.RAISE in moves: return Move.RAISE

        if ihr > 15:
            if Move.CALL in moves: return Move.CALL
            elif Move.CHECK in moves: return Move.CHECK

        return Move.FOLD if Move.FOLD in moves else Move.QUIT
def countActions(l, actions):
    return sum(1 for x in l if x in actions) / 1.0


with open('/home/szymon/inne/ips/PokerHandsDataset/hands_valid.json',
          'r') as f:
    features = ([], [], [])
    labels = ([], [], [])

    line = f.readline()
    while line:
        info = json.loads(line)
        comm = stringsToCards(info['board'])
        numOfPlayers = [x['num_players'] for x in info['pots'][1:]]
        commPts = list(
            map(lambda x: CardValidator.checkHighCard([x]) / 1.0, comm))
        points = [[], [], []]
        winners = []
        for player in info['players']:
            if player['winnings'] > 0:
                winners.append(player['user'])
            for idx in range(3):
                points[idx].append([
                    player['user'],
                    CardValidator.combination(
                        stringsToCards(player['pocket_cards']) +
                        comm[:3 + idx]) / 1.0
                ])

        for player in info['players']:
            hand = [
Exemplo n.º 7
0
    features = ([], [], [])
    labels = ([], [], [])

    line = f.readline()
    while line:
        info = json.loads(line)
        comm = stringsToCards(info['board'])
        communityCardsValues = tuple(
            map(CardValidator.combination, [comm[:3], comm[:4], comm]))
        for players in info['players']:
            if len(players['pocket_cards']) == 2:
                playerHand = stringsToCards(players['pocket_cards'])
                for idx, stage in enumerate(players['bets'][1:]):
                    raising = countActions(stage['actions'], ['b', 'r'])
                    calling = countActions(stage['actions'], ['c', 'k'])
                    features[idx].append(
                        [communityCardsValues[idx], raising, calling])
                    labels[idx].append(
                        CardValidator.combination(playerHand + comm[:3 + idx]))
                    print('features -> ', features[idx][-1], '\tlabels -> ',
                          labels[idx][-1])
        line = f.readline()

print("creating knn models")
knn = []
for n in range(3):
    knn.append(KNeighborsClassifier())
    knn[n].fit(features[n], labels[n])
print("saving models")
joblib.dump(knn, 'testKNNmodels.joblib', compress=4)
print('done')