Last active
September 24, 2022 09:06
-
-
Save petrosDemetrakopoulos/8be13f6c59d72b15ad2e7da554b7279c to your computer and use it in GitHub Desktop.
Texas Holdem Simulation function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def simulate(hand, table, players): | |
hands = [] | |
deck = random.sample(cards,len(cards)) #shuffle the deck | |
hand = hand[:] | |
table = table[:] | |
full = table + hand | |
deck = list(filter(lambda x: x not in full, deck)) | |
#deal cards to players | |
for i in range(players): | |
hn = [] | |
hn.append(deck[0]) | |
deck = deck[1:] | |
hn.append(deck[0]) | |
deck = deck[1:] | |
hands.append(hn) | |
#flop, turn, river | |
while len(table) < 5: | |
card = deck.pop(0) | |
table.append(card) | |
full.append(card) | |
my_hand_rank = evaluate_cards(full[0],full[1],full[2],full[3],full[4],full[5],full[6]) | |
for check_hand in hands: | |
all_cards = table + check_hand | |
opponent = evaluate_cards(all_cards[0],all_cards[1],all_cards[2],all_cards[3],all_cards[4],all_cards[5],all_cards[6]) | |
# from the definition of the library we use for hand evaluation, larger evaluations correspond to less strong hands | |
#so, the game is won by the player with the smallest hand evaluation | |
if opponent < my_hand_rank: | |
return 1 #'LOSE' | |
if opponent == my_hand_rank: | |
return 2 #'SPLIT' | |
return 0 #'WIN' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment