Esempio n. 1
0
def bet():
    action = ""
    global game
    if game.getLenRemaining() == 1:
        return
    print "bet"
    for player in game.getPlayers():
        if not player.in_game:
            continue
        remaining = game.getRemaining()
        if len(remaining) > 1:
            tablecards = game.getTable().get_cards()
            hand = player.get_hand() + tablecards
            hand_power = find_hand(cards.calc_cards_power(hand))
            print "Player", player.no, "has", hand_power + str(cards.calc_cards_power(hand))
            action = betting.evaluateHand(game, player)
            addContext(player, action)
            print "#####", player.hs
        else:
            game.finished = True
            player_won(player)
    remaining = game.getRemaining()
    for player in remaining:
        if player.bet != game.getTable().get_bet():
                bet()
Esempio n. 2
0
    def calculate_results(self, player, opponents, shared_cards):

        result = {"win": 0, "loss": 0, "tie": 0}

        pl = cards.calc_cards_power(player + shared_cards)
        i = 0
        for p in opponents:
            i += 1
            o = cards.calc_cards_power(p + shared_cards)
            if o[0] > pl[0]:
              result['loss'] += 1
            elif o[0] == pl[0]:
              if o == pl:
                result['tie'] += 1
              else:
                loss = False
                for j in range(1, len(o)):
                    if o[j] > pl[j]:
                        loss = True
                        break
                if loss: 
                    result['loss'] += 1
                else:
                    result['win'] += 1
            else: 
                result['win'] += 1

        # Return win tables. 
        return result
    def calculate_results(self, player, opponents, shared_cards):
        loss = False
        tie = False

        pl = cards.calc_cards_power(player + shared_cards)
        for p in opponents:

            o = cards.calc_cards_power(p + shared_cards)
            if o[0] > pl[0]:
                loss = True
            elif o[0] == pl[0]:
                if o == pl:
                    tie = True
                else:
                    for j in range(1, len(o)):
                        if o[j] > pl[j]:
                            loss = True
                            break

        # Return win tables.
        return {
            "win": int(not (loss or tie)),
            "loss": int(loss),
            "tie": int(tie and not (loss))
        }
def calculateOutcome(player, tableCards, opponents):
    winners = []
    currentWinner = player
    hand = player[:]
    for c in tableCards:
        hand.append(c)
    winningHand = cards.calc_cards_power(hand)
    winners.append(player)
    for opponent in opponents:
        ny_hand = opponent
        for c in tableCards:
            ny_hand.append(c)
        power = cards.calc_cards_power(ny_hand)
        for i in range(len(power)):
            if power[i] > winningHand[i]:
                currentWinner = opponent
                winningHand = power
                winners = [currentWinner]
                break
            elif power[i] < winningHand[i]:
                break
            elif i == len(power):
                winners.append(opponent)
    if not player in winners:  # Lose
        return -1
    elif len(winners) == 1:  # Win
        return 1
    else:  # Draw
        return 0
Esempio n. 5
0
    def calculate_results(self, player, opponents, shared_cards):

        result = {"win": 0, "loss": 0, "tie": 0}

        pl = cards.calc_cards_power(player + shared_cards)
        i = 0
        for p in opponents:
            i += 1
            o = cards.calc_cards_power(p + shared_cards)
            if o[0] > pl[0]:
              result['loss'] += 1
            elif o[0] == pl[0]:
              if o == pl:
                result['tie'] += 1
              else:
                loss = False
                for j in range(1, len(o)):
                    if o[j] > pl[j]:
                        loss = True
                        break
                if loss: 
                    result['loss'] += 1
                else:
                    result['win'] += 1
            else: 
                result['win'] += 1

        # Return win tables. 
        return result
def calculateOutcome(player, tableCards, opponents):
    winners = []
    currentWinner = player
    hand = player[:]
    for c in tableCards:
        hand.append(c)
    winningHand = cards.calc_cards_power(hand)
    winners.append(player)
    for opponent in opponents:
        ny_hand = opponent
        for c in tableCards:
            ny_hand.append(c)
        power = cards.calc_cards_power(ny_hand)
        for i in range(len(power)):
            if power[i] > winningHand[i]:
                currentWinner = opponent
                winningHand = power
                winners = [currentWinner]
                break
            elif power[i] < winningHand[i]:
                break
            elif i == len(power):
                winners.append(opponent)
    if not player in winners:  # Lose
        return -1
    elif len(winners) == 1:  # Win
        return 1
    else:  # Draw
        return 0
Esempio n. 7
0
    def calculate_win(self, is_last_round=False):
        # Winning calcs
        if self.count_active_players(self.active_players) < 2:
            for p in self.active_players:
                if p != None:
                    print("Pot is added to winner", p.name)
                    p.win(self.pot)
                    return [[p],
                            cards.calc_cards_power(p.cards + self.shared_cards)
                            ]

        if is_last_round:

            count_active = self.count_active_players(self.active_players)

            winner = [None, [0, 0, 0, 0, 0]]
            for p in self.active_players:
                if p == None:
                    continue

                ranking = cards.calc_cards_power(p.cards + self.shared_cards)
                #If the players cards are better than the current winner,
                #the player is set as the current winner
                if ranking[0] > winner[1][0]:
                    winner = [[p], ranking]
                elif ranking[0] == winner[1][0]:
                    #If the player has the same cards as the current winner,
                    #they will share the pot, so we add the player to the winner-table
                    if ranking == winner[1]:
                        winner[0].append(p)
                    else:
                        for j in range(1, len(ranking)):
                            if ranking[j] > winner[1][j]:
                                winner = [[p], ranking]
                                break

            for p in winner[0]:
                print("Pot is added to winner after last round")
                #p.win(self.pot/len(winner[0]))
                winners = len(winner[0])
                if (winners > 1):
                    # It's a tie, register it, and split the money
                    p.showdown_tie(self.pot / winners)
                else:
                    # Only one winner, give him the money!
                    p.showdown_win(self.pot / winners)

            #Check who lost the showdown
            for p in self.active_players:
                if p != None:
                    p.save_modeling(count_active, self.shared_cards)
                    if not p in winner[0]:
                        # Register loss on the players
                        p.showdown_loss()

            return winner

        return False
Esempio n. 8
0
    def calculate_win(self, is_last_round=False):
        # Winning calcs
        if self.count_active_players(self.active_players) < 2:
            for p in self.active_players:
                if p != None:
                    print("Pot is added to winner", p.name)
                    p.win(self.pot)
                    return [[p], cards.calc_cards_power(p.cards + self.shared_cards)]

        if is_last_round:

            count_active = self.count_active_players(self.active_players)

            winner = [None, [0, 0, 0, 0, 0]]
            for p in self.active_players:
                if p == None:
                    continue

                ranking = cards.calc_cards_power(p.cards + self.shared_cards)
                # If the players cards are better than the current winner,
                # the player is set as the current winner
                if ranking[0] > winner[1][0]:
                    winner = [[p], ranking]
                elif ranking[0] == winner[1][0]:
                    # If the player has the same cards as the current winner,
                    # they will share the pot, so we add the player to the winner-table
                    if ranking == winner[1]:
                        winner[0].append(p)
                    else:
                        for j in range(1, len(ranking)):
                            if ranking[j] > winner[1][j]:
                                winner = [[p], ranking]
                                break

            for p in winner[0]:
                print("Pot is added to winner after last round")
                # p.win(self.pot/len(winner[0]))
                winners = len(winner[0])
                if winners > 1:
                    # It's a tie, register it, and split the money
                    p.showdown_tie(self.pot / winners)
                else:
                    # Only one winner, give him the money!
                    p.showdown_win(self.pot / winners)

            # Check who lost the showdown
            for p in self.active_players:
                if p != None:
                    p.save_modeling(count_active, self.shared_cards)
                    if not p in winner[0]:
                        # Register loss on the players
                        p.showdown_loss()

            return winner

        return False
Esempio n. 9
0
def calculateOutcome(player, opponent):
    playerPower = cards.calc_cards_power(player)
    opponentPower = cards.calc_cards_power(opponent)
    for i in range(len(playerPower)):
        if playerPower[i] > opponentPower[i]:
            return 1
        elif playerPower[i] < opponentPower[i]:
            return -1
        elif i == len(playerPower):
            return 0
Esempio n. 10
0
def evaluateHand(game, player):
    if player.phase == 1:
        gameHand = player.hand + game.getTable().get_cards()
        hand = cards.calc_cards_power(gameHand, len(gameHand))
        #print "PHASE1: ", hand
        evaluateHandNormal(player, game.getTable(), hand)
    elif player.strategy == 3:
        print "PHASE2: "
        evaluateHandLastPhase(game, player)
    #test(game)
    checkValue = player.strategy.getAction(game, player)
    #print checkValue
    #if player.strategy.aggressive == False and player.strategy.coward == False:
    #    evaluateHandNormal(player, table, hand)
    #el
    if checkValue == "raise":
        #print "###################\n RAISE \n#####################"
        #print player.strategy.aggressive
        return raise_bet(player, game.getTable(), bet)
    elif checkValue == "call":
        #print "###################\n CALL \n#####################"
        #print player.strategy.aggressive
        return call(player, game.getTable())
    elif checkValue == "fold":
        #print "###################\n FOLD \n#####################"
        #print player.strategy.aggressive
        return fold(player)
    elif checkValue == "check":
        #print "###################\n CHECK \n#####################"
        return check(player, game.getTable())
    else:
        print "Betting strategy do not work!"
Esempio n. 11
0
  def take_loose_aggressive_action(self, highest_bet, pot, players, position, shared_cards, state, total_raises, strength, highest_strength):
    #1. Highest card
    #2. One pair
    #3. Two pair
    #4. 3 of a kind
    #5. Straight
    #6. Flush
    #7. Full House
    #8. 4 of a kind
    #9. Straight Flush - with Royal Flush being the highest of these

    ranking = cards.calc_cards_power(self.cards + shared_cards) # calculate hand ranking
    action = ""
    ret = None

    if state == 1:
      # Pre-flop
      if (ranking[0] == 1 and ranking[1] > 12) or (ranking[0] == 2) or (strength > 0.30 and highest_strength != 0 and strength > (highest_strength - 0.2)): #High card and highest card is above 10 or pair or strength > 30%
        # Raise
        if(self.raise_count > 5):
          self.last_action = "call"
          ret = self.call_action(highest_bet)
        else:
          if(self.sum_pot_in == highest_bet):
            self.last_action = "check"
            ret = self.call_action(highest_bet)
          else:
            self.last_action = "raise"
            ret = self.raise_action(highest_bet)
      else:
        if(self.sum_pot_in == highest_bet):
          self.last_action = "check"
          ret = self.call_action(highest_bet)
        else:
          return self.fold_action()
    elif state >= 2:
      # Post-flop
      if(self.raise_count > 5):
        self.last_action = "call"
        ret = self.call_action(highest_bet)
      else:
        if (ranking[0] == 2 and players < 4 and self.sum_pot_in != highest_bet) or (strength > 0.30 and highest_strength != 0 and strength > (highest_strength - 0.2)) or (ranking[0] > 3 and self.sum_pot_in != highest_bet):
          self.last_action = "raise"
          ret = self.raise_action(highest_bet)
        elif self.sum_pot_in == highest_bet:
          self.last_action = "check"
          ret = self.call_action(highest_bet)
        else:
          return self.fold_action()        
    else:
      return self.fold_action()
    
    if self.last_action != "":
      self.take_action_super(highest_bet, pot, players, position, shared_cards, state, total_raises, self.last_action)

    print("DEBUG RET FROM AGGRESSIVE ===================== ", ret)
    return ret
Esempio n. 12
0
def bet(game):
    if len(find_remaining(players)) == 1:
        return
    for player in players:
		if player.in_game == False:
			continue
		remaining = find_remaining(players)
		if len(remaining) > 1:
			tablecards = table.get_cards()
			hand = player.get_hand() + tablecards
			hand_power = find_hand(cards.calc_cards_power(hand))
			betting.evaluateHand(player, table, cards.calc_cards_power(hand))
		else:
			game.finished = True
			player_won(player)
    remaining = find_remaining(players)
    for player in remaining:
	    if player.bet != table.bet:
	        bet(game)
Esempio n. 13
0
def Showdown():
    global remainingPlayers
    global tableCards, estimatorTable
    print("SHOWDOWN!")
    #print("Remaining players:", len(remainingPlayers))
    winners = []
    for a in remainingPlayers:
        #estimatorTable[a.name].append(a.contextTable)
        estimatorTable[a.name] = a.contextTable

    if len(remainingPlayers) > 0:
        currentWinner = remainingPlayers[0]
        #hand = currentWinner.cards
        hand = list(tableCards)
        hand.append(currentWinner.cards[0])
        hand.append(currentWinner.cards[1])

        winningHand = cards.calc_cards_power(hand)
        winners.append(remainingPlayers[0])
        #print "Player:", currentWinner.name, winningHand, "     ", currentWinner.cards

    for i in range(1,len(remainingPlayers)):
        #hand2 = remainingPlayers[i].cards
        hand2 = list(tableCards)
        hand2.append(remainingPlayers[i].cards[0])
        hand2.append(remainingPlayers[i].cards[1])

        power2 = cards.calc_cards_power(hand2)
        #print "Player:", remainingPlayers[i].name, power2, "        ", remainingPlayers[i].cards
        for j in range(len(power2)):
            if power2[j] > winningHand[j]:
                currentWinner = remainingPlayers[i]
                winningHand = power2
                winners = [currentWinner]
                break
            elif power2[j] < winningHand[j]:
                break;
            elif j == len(power2)-1:
                winners.append(remainingPlayers[i])
    print "Winner(s) after showdown!:"
    for p in winners:
        print p.name, winningHand, "(prize",pot/len(winners),")", "personality:(",p.personality,")","type:(",p.type,")"
        p.cash += pot/len(winners)
    def calculate_results(self, player, opponents, shared_cards):
        loss = False
        tie = False

        pl = cards.calc_cards_power(player + shared_cards)
        for p in opponents:

            o = cards.calc_cards_power(p + shared_cards)
            if o[0] > pl[0]:
              loss = True
            elif o[0] == pl[0]:
              if o == pl:
                tie = True
              else:
                for j in range(1, len(o)):
                    if o[j] > pl[j]:
                        loss = True
                        break

        # Return win tables. 
        return {"win": int(not(loss or tie)), "loss": int(loss), "tie": int(tie and not(loss))}
Esempio n. 15
0
 def print_action_info(self, shared_cards):
     print(self.name, "- play style: " + self.play_style, "(", self.money,
           "credits):", cards.card_names(self.cards),
           cards.calc_cards_power(self.cards + shared_cards))
     print("Total wins before showdown: ", self.total_pre_showdown_win)
     print("Total wins at showdown: ", self.total_showdown_win)
     print("Total ties at showdown: ", self.total_showdown_tie)
     print("Total losses at showdown: ", self.total_showdown_loss)
     print("Total calls: ", self.total_call)
     print("Total checks: ", self.total_check)
     print("Total raises: ", self.total_raise)
     print("Total folds: ", self.total_fold)
     print("\n")
Esempio n. 16
0
def bet():
	global game
	remaining = game.getRemaining()
	if len(remaining) == 1:
		return
	print "bet"
	for player in remaining:
		if len(remaining) > 1:
			tablecards = game.getTable().get_cards()
			hand = player.get_hand() + tablecards
			hand_power = find_hand(cards.calc_cards_power(hand))
			print "Player", player.no, "has", hand_power + str(cards.calc_cards_power(hand))
			context = str(game.state) + str(len(remaining)) + str(pot_odds(game.table, player))
			action = betting.evaluateHand(game, player)
			print action, game.table.bet
			player.contexts[context+action] = 0
			remaining = game.getRemaining()
		else:
			game.finished = True
			player_won(player)
	remaining = game.getRemaining()
	for player in remaining:
		if player.bet != game.getTable().get_bet():
				bet()
Esempio n. 17
0
def showdown():
    remaining = list(players)
    players_power = []
    #print "Showdown!\n-------------------"
    for player in players:
        hand = player.hand + table
        hand_power = cards.calc_cards_power(hand)
     #   print "hand power", hand_power
        players_power.append(hand_power)
    while len(remaining) > 1:
        remaining2 = check_hand(players_power, remaining)
        remaining = remaining2[1]
    #print "After showdown,", len(remaining), "players remain"
    if len(remaining) == 0:
        return remaining2[0][0]
    return find_winners(remaining)
Esempio n. 18
0
def showdown(game):
    remaining = find_remaining(players)
    if len(remaining) == 1:
        return
    tablecards = table.get_cards()
    players_power = []
    for player in remaining:
        hand = player.get_hand()
        hand_power = cards.calc_cards_power(hand)
        players_power.append(hand_power)
    while len(remaining) > 1:
        remaining = check_hand(players_power, remaining)
        remaining = remaining[1]
    game.finished = True
    if len(remaining) == 0:
        return
    player_won(remaining[0])
Esempio n. 19
0
def showdown():
    global game
    remaining = game.getRemaining()
    if len(remaining) == 1:
        return
    tableCards = game.getTable().get_cards()
    players_power = []
    #print "-------------------Showdown!-------------------"
    for player in remaining:
        hand = player.get_hand() + tableCards
        hand_power = cards.calc_cards_power(hand)
        #print "hand power", hand_power
        players_power.append(hand_power)
    while len(remaining) > 1:
        remaining2 = check_hand(players_power, remaining)
        remaining = remaining2[1]
    #print "After showdown,", len(remaining), "players remain"
    game.finished = True
    if len(remaining) == 0:
        return
    player_won(remaining[0])
Esempio n. 20
0
 def print_info(self, shared_cards):
   print(self.name, "- play style: "+self.play_style, "(", self.money, "credits):", cards.card_names(self.cards), cards.calc_cards_power(self.cards + shared_cards))
Esempio n. 21
0
  def take_tight_passive_action(self, highest_bet, pot, players, position, shared_cards, state, total_raises, strength, highest_strength):
    #1. Highest card
    #2. One pair
    #3. Two pair
    #4. 3 of a kind
    #5. Straight
    #6. Flush
    #7. Full House
    #8. 4 of a kind
    #9. Straight Flush - with Royal Flush being the highest of these

    ranking = cards.calc_cards_power(self.cards + shared_cards) # calculate hand ranking

    self.last_action = ""

    if len(shared_cards) < 1: # pre-flop
      # check for pair, high cards, suited, high card suited. 
      if (ranking[0] == 2 and ranking[1] > 9 and self.raise_count < 3) or (strength > 0.7 and highest_strength != 0 and strength > (highest_strength)):
        # raise if not already committed equally to highest bet
        # check otherwise (call 0)
        if(self.sum_pot_in == highest_bet):
          self.last_action = "check"
          ret = self.call_action(highest_bet)
        else:
          self.last_action = "raise"
          ret = self.raise_action(highest_bet)

      elif (ranking[0] == 1 and ranking[1] > 10 and ranking[2] > 10) or (strength > 0.5 and highest_strength != 0 and strength > (highest_strength-0.1)): # high card
        # call
        self.last_action = "call"
        ret = self.call_action(highest_bet)

      elif self.cards[0][1] == self.cards[1][1] and ranking[1] > 10 and ranking[2] > 10: # suited high
        # call
        self.last_action = "call"
        ret = self.call_action(highest_bet)

      elif self.sum_pot_in == highest_bet:
        # check, we use call for this purpose(calls 0)
        self.last_action = "check"
        ret = self.call_action(highest_bet)

      else:
        # fold
        return self.fold_action()

    else: # post-flop
      if ((ranking[0] == 3 and ranking[1] > 10 and ranking[2] > 10) or (ranking[0] == 4 and ranking[1] > 7) or (ranking[0] > 4) or (strength > 0.7 and highest_strength != 0 and strength > (highest_strength))) and self.raise_count < 3:
        # raise if not already committed equally to highest bet
        # check otherwise (call 0)
        if(self.sum_pot_in == highest_bet):
          self.last_action = "check"
          ret = self.call_action(highest_bet)
        else:
          self.last_action = "raise"
          ret = self.raise_action(highest_bet)

      elif (highest_bet != self.sum_pot_in and ((ranking[0] == 1) or (ranking[0] == 2 and ranking[1] < 12) )) or strength < 0.3 or (highest_strength != 0 and highest_strength-0.1 > strength):
        # fold
        return self.fold_action()

      else:
        # call/check
        self.last_action = "call" if highest_bet != self.sum_pot_in else "check"
        ret = self.call_action(highest_bet)
    
    if self.last_action != "":
      self.take_action_super(highest_bet, pot, players, position, shared_cards, state, total_raises, self.last_action)

    return ret
Esempio n. 22
0
    def take_loose_aggressive_action(self, highest_bet, pot, players, position,
                                     shared_cards, state, total_raises):
        #1. Highest card
        #2. One pair
        #3. Two pair
        #4. 3 of a kind
        #5. Straight
        #6. Flush
        #7. Full House
        #8. 4 of a kind
        #9. Straight Flush - with Royal Flush being the highest of these

        ranking = cards.calc_cards_power(
            self.cards + shared_cards)  # calculate hand ranking
        action = ""
        ret = None

        if state == 1:
            # Pre-flop
            if ranking[0] == 1 and ranking[
                    1] > 12:  #High card and highest card is above 10
                # Raise
                if (self.raise_count > 5):
                    self.last_action = "call"
                    ret = self.call_action(highest_bet)
                else:
                    if (self.sum_pot_in == highest_bet):
                        self.last_action = "check"
                        ret = self.call_action(highest_bet)
                    else:
                        self.last_action = "raise"
                        ret = self.raise_action(highest_bet)
            elif ranking[0] == 2:  # Hole pair.. RAISE!
                if (self.raise_count > 5):
                    self.last_action = "call"
                    ret = self.call_action(highest_bet)
                else:
                    if (self.sum_pot_in == highest_bet):
                        self.last_action = "check"
                        ret = self.call_action(highest_bet)
                    else:
                        self.last_action = "raise"
                        ret = self.raise_action(highest_bet)
            else:
                if (self.sum_pot_in == highest_bet):
                    self.last_action = "check"
                    ret = self.call_action(highest_bet)
                else:
                    return self.fold_action()
        elif state >= 2:
            # Post-flop
            if (self.raise_count > 5):
                self.last_action = "call"
                ret = self.call_action(highest_bet)
            else:
                if ranking[
                        0] == 2 and players < 4 and self.sum_pot_in != highest_bet:
                    self.last_action = "raise"
                    ret = self.raise_action(highest_bet)
                elif ranking[0] > 3 and self.sum_pot_in != highest_bet:
                    self.last_action = "raise"
                    ret = self.raise_action(highest_bet)
                elif self.sum_pot_in == highest_bet:
                    self.last_action = "check"
                    ret = self.call_action(highest_bet)
                else:
                    return self.fold_action()
        else:
            return self.fold_action()

        if self.last_action != "":
            self.take_action_super(highest_bet, pot, players, position,
                                   shared_cards, state, total_raises,
                                   self.last_action)

        #print("DEBUG RET FROM AGGRESSIVE ===================== ", ret)
        return ret
Esempio n. 23
0
    def take_tight_passive_action(self, highest_bet, pot, players, position,
                                  shared_cards, state, total_raises):
        #1. Highest card
        #2. One pair
        #3. Two pair
        #4. 3 of a kind
        #5. Straight
        #6. Flush
        #7. Full House
        #8. 4 of a kind
        #9. Straight Flush - with Royal Flush being the highest of these

        ranking = cards.calc_cards_power(
            self.cards + shared_cards)  # calculate hand ranking

        action = ""

        if len(shared_cards) < 1:  # pre-flop
            # check for pair, high cards, suited, high card suited.
            if ranking[0] == 2 and ranking[1] > 9 and self.raise_count < 3:
                # raise if not already committed equally to highest bet
                # check otherwise (call 0)
                if (self.sum_pot_in == highest_bet):
                    self.last_action = "check"
                    ret = self.call_action(highest_bet)
                else:
                    self.last_action = "raise"
                    ret = self.raise_action(highest_bet)

            elif ranking[0] == 1 and ranking[1] > 10 and ranking[
                    2] > 10:  # high card
                # call
                self.last_action = "call"
                ret = self.call_action(highest_bet)

            elif self.cards[0][1] == self.cards[1][
                    1] and ranking[1] > 10 and ranking[2] > 10:  # suited high
                # call
                self.last_action = "call"
                ret = self.call_action(highest_bet)

            elif self.sum_pot_in == highest_bet:
                # check, we use call for this purpose(calls 0)
                self.last_action = "check"
                ret = self.call_action(highest_bet)

            else:
                # fold
                return self.fold_action()

        else:  # post-flop
            if ((ranking[0] == 3 and ranking[1] > 10 and ranking[2] > 10) or
                (ranking[0] == 4 and ranking[1] > 7) or
                (ranking[0] > 4)) and self.raise_count < 3:
                # raise if not already committed equally to highest bet
                # check otherwise (call 0)
                if (self.sum_pot_in == highest_bet):
                    self.last_action = "check"
                    ret = self.call_action(highest_bet)
                else:
                    self.last_action = "raise"
                    ret = self.raise_action(highest_bet)

            elif highest_bet != self.sum_pot_in and (
                (ranking[0] == 1) or (ranking[0] == 2 and ranking[1] < 12)):
                # fold
                return self.fold_action()

            else:
                # call/check
                self.last_action = "call" if highest_bet != self.sum_pot_in else "check"
                ret = self.call_action(highest_bet)

        if self.last_action != "":
            self.take_action_super(highest_bet, pot, players, position,
                                   shared_cards, state, total_raises,
                                   self.last_action)

        return ret
Esempio n. 24
0
 def print_action_info(self, shared_cards):
   print(self.name, "- play style: "+self.play_style, "(", self.money, "credits):", cards.card_names(self.cards), cards.calc_cards_power(self.cards + shared_cards))
   print("Total wins before showdown: ", self.total_pre_showdown_win)
   print("Total wins at showdown: ", self.total_showdown_win)
   print("Total ties at showdown: ", self.total_showdown_tie)
   print("Total losses at showdown: ", self.total_showdown_loss)
   print("Total calls: ", self.total_call)
   print("Total checks: ", self.total_check)
   print("Total raises: ", self.total_raise)
   print("Total folds: ", self.total_fold)
   print("\n")
Esempio n. 25
0
    def Assess(self):

        if(self.type == "phase1"):

            if(len(tableCards) == 0):
                pass
            else:


                if (self != smallBlind or not firstRound) and (self != bigBlind or not firstRound):
                        i = random.randint(0,2)
                        if i == 0:
                            self.Fold()

                        elif i == 1:
                            self.Raise(raiseValue)

                        else:
                            self.Call()

                else:
                    cashmult = 1
                    powertol = 1
                    if(self.personality == "conservative"):
                        cashmult = 2
                        powertol = 2
                    elif(self.personality == "bluffer"):
                        cashmult = 4
                        powertol = 0
                    elif(self.personality == "persistent"):
                        cashmult = 99
                        powertol = 2

                    if(not done):
                        temp = []
                        temp.append(self.cards[0])
                        temp.append(self.cards[1])
                        for card in tableCards:
                            temp.append(card)
                        hand = list(temp)
                        #self.cards = list(hand)
                        power = cards.calc_cards_power(hand)[0]
                        if power > powertol and self.bet < cashmult*raiseValue:
                            self.Raise(raiseValue)
                        elif power > ((powertol/2) and self.bet < (cashmult/2)*raiseValue) or self.bet == currentBet:
                            self.Call()
                        else:
                            self.Fold()


        elif(self.type == "phase2"):

            if len(tableCards) == 0:
                high = None
                low = None
                suit = None
                if self.cards[0][0] > self.cards[1][0]:
                    high = self.cards[0][0]
                    low = self.cards[1][0]
                else:
                    high = self.cards[1][0]
                    low = self.cards[0][0]

                if self.cards[0][1] == self.cards[1][1]:
                    suit = 1
                else:
                    suit = 0
                if(self.handStrength == 0):
                    self.handStrength = preFlopTable[high -2][low -2][suit][len(players) -2] *2

            else:
                if(self.handStrength == 0):
                    self.handStrength = CalculateHandStrength(self)
            printHandStrength(self)
            #raiser med bra kort, men raiser ikke med for mye
            if self.personality == "conservative":
                if(self.handStrength > 0.6):
                    if self.bet < raiseValue * 2:
                        self.Raise(raiseValue)
                    else:
                        self.Call()
                elif((self.handStrength >0.45 and self.bet < raiseValue * 2) or self.bet == currentBet):
                    self.Call()
                else:
                    self.Fold()

            elif self.personality == "bluffer":
                    if(self.handStrength > 0.5):
                        if self.bet < raiseValue * 10:
                            self.Raise(raiseValue)
                        else:
                            self.Call()
                    elif(self.handStrength > (1/len(remainingPlayers)) or self.bet == currentBet):
                        self.Call()
                    else:
                        self.Fold()

            elif self.personality == "persistent":
                    if(self.handStrength > 0.6):
                        if self.bet < raiseValue * 20:
                            self.Raise(raiseValue)
                        else:
                            self.Call()
                    elif(self.handStrength >(1/len(remainingPlayers)) or self.bet == currentBet):
                        self.Call()
                    else:
                        self.Fold()


        elif(self.type == "phase3"):

            if(len(tableCards) == 0):
                high = None
                low = None
                suit = None
                if self.cards[0][0] > self.cards[1][0]:
                    high = self.cards[0][0]
                    low = self.cards[1][0]
                else:
                    high = self.cards[1][0]
                    low = self.cards[0][0]

                if self.cards[0][1] == self.cards[1][1]:
                    suit = 1
                else:
                    suit = 0
                if(self.handStrength == 0):
                    self.handStrength = preFlopTable[high -2][low -2][suit][len(players) -2] * 2

            else:
                if(self.handStrength == 0):
                    self.handStrength = CalculateHandStrength(self)
            printHandStrength(self)
                #ownStrength = hand_strength.calculateHandStrength([self.cards[0],self.cards[1]], len(remainingPlayers) -1, tableCards)
            guess = self.GuessHand()

            shouldRaise = False
            shouldCall = True
            shouldFold = False
            if self.personality == "conservative":
                    for g in guess:
                        if g > self.handStrength:
                            shouldFold = True
                            shouldRaise = False
                            break
                        elif self.handStrength-0.1 > g:
                            Raise = True
                    if(shouldRaise):
                        if(self.bet < raiseValue * 3):
                            self.Raise(raiseValue)
                        else:
                            self.Call()
                    elif(shouldCall or self.bet == currentBet):
                        self.Call()
                    elif(shouldFold):
                        self.Fold()

            elif self.personality == "persistent":
                    counter = 0
                    for g in guess:
                        if g > self.handStrength:
                            counter += 1
                    if(counter > len(remainingPlayers)/3):
                        shouldFold = True
                        shouldCall = False
                    elif counter == 0:
                        shouldRaise = True
                        shouldCall = False

                    if(shouldRaise):
                        if(self.bet < 20*raiseValue):
                            self.Raise(raiseValue)
                        else:
                            self.Call()
                    elif (shouldCall or self.bet == currentBet):
                        self.Call()
                    else:
                        self.Fold()

            elif self.personality == "bluffer":
                    counter = 0
                    for g in guess:
                        if g > self.handStrength:
                            counter += 1
                    if(counter > len(remainingPlayers)/2):
                        shouldFold = True
                        shouldCall = False
                    elif counter < 2:
                        shouldRaise = True
                        shouldCall = False

                    if(shouldRaise):
                        if(self.bet < 10*raiseValue):
                            self.Raise(raiseValue)
                        else:
                            self.Call()
                    elif (shouldCall or self.bet == currentBet):
                        self.Call()
                    else:
                        self.Fold()