Beispiel #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 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
Beispiel #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 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
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 = [