def unknown_simulation(new_hole_cards): # Extract parameters hole_cards_list = unknown_simulation.hole_cards_list unknown_index = unknown_simulation.unknown_index deck = unknown_simulation.deck[:] generate_boards = unknown_simulation.generate_boards num = unknown_simulation.num board_length = unknown_simulation.board_length given_board = unknown_simulation.given_board combined_winner_list = unknown_simulation.combined_winner_list combined_result_histograms = unknown_simulation.combined_result_histograms # Set simulation variables num_players = len(hole_cards_list) result_histograms, winner_list = [], [0] * (num_players + 1) for _ in range(num_players): result_histograms.append([0] * len(holdem_functions.hand_rankings)) hole_cards_list[unknown_index] = new_hole_cards deck.remove(new_hole_cards[0]) deck.remove(new_hole_cards[1]) # Find winner holdem_functions.find_winner(generate_boards, deck, tuple(hole_cards_list), num, board_length, given_board, winner_list, result_histograms) # Write results to parallel data structure for future tabulation proc_name = multiprocessing.current_process().name proc_id = int(proc_name.split("-")[-1]) % multiprocessing.cpu_count() for index, result in enumerate(winner_list): combined_winner_list[proc_id * (num_players + 1) + index] += result for histogram_index, histogram in enumerate(result_histograms): for index, result in enumerate(histogram): combined_result_histograms[ len(holdem_functions.hand_rankings) * (proc_id * num_players + histogram_index) + index] += result
def unknown_simulation(new_hole_cards): # Extract parameters hole_cards_list = unknown_simulation.hole_cards_list unknown_index = unknown_simulation.unknown_index deck = unknown_simulation.deck[:] generate_boards = unknown_simulation.generate_boards num = unknown_simulation.num board_length = unknown_simulation.board_length given_board = unknown_simulation.given_board combined_winner_list = unknown_simulation.combined_winner_list combined_result_histograms = unknown_simulation.combined_result_histograms # Set simulation variables num_players = len(hole_cards_list) result_histograms, winner_list = [], [0] * (num_players + 1) for _ in xrange(num_players): result_histograms.append([0] * len(holdem_functions.hand_rankings)) hole_cards_list[unknown_index] = new_hole_cards deck.remove(new_hole_cards[0]) deck.remove(new_hole_cards[1]) # Find winner holdem_functions.find_winner(generate_boards, deck, tuple(hole_cards_list), num, board_length, given_board, winner_list, result_histograms) # Write results to parallel data structure for future tabulation proc_name = multiprocessing.current_process().name proc_id = int(proc_name.split("-")[-1]) % multiprocessing.cpu_count() for index, result in enumerate(winner_list): combined_winner_list[proc_id * (num_players + 1) + index] += result for histogram_index, histogram in enumerate(result_histograms): for index, result in enumerate(histogram): combined_result_histograms[len(holdem_functions.hand_rankings) * (proc_id * num_players + histogram_index) + index] += result
def run_simulation(hole_cards, num, exact, given_board, deck, verbose, pad_opp=True): num_players = len(hole_cards) if pad_opp: num_players += 1 #import pdb #pdb.set_trace() # Create results data structures which track results of comparisons # 1) result_histograms: a list for each player that shows the number of # times each type of poker hand (e.g. flush, straight) was gotten # 2) winner_list: number of times each player wins the given round # 3) result_list: list of the best possible poker hand for each pair of # hole cards for a given board result_histograms, winner_list = [], [0] * (num_players + 1) for _ in range(num_players): result_histograms.append([0] * len(holdem_functions.hand_rankings)) # Choose whether we're running a Monte Carlo or exhaustive simulation board_length = 0 if given_board is None else len(given_board) # When a board is given, exact calculation is much faster than Monte Carlo # simulation, so default to exact if a board is given if exact or given_board is not None: generate_boards = holdem_functions.generate_exhaustive_boards else: generate_boards = holdem_functions.generate_random_boards if (None, None) in hole_cards: hole_cards_list = list(hole_cards) unknown_index = hole_cards.index((None, None)) for filler_hole_cards in holdem_functions.generate_hole_cards(deck): hole_cards_list[unknown_index] = filler_hole_cards deck_list = list(deck) deck_list.remove(filler_hole_cards[0]) deck_list.remove(filler_hole_cards[1]) holdem_functions.find_winner(generate_boards, tuple(deck_list), tuple(hole_cards_list), num, board_length, given_board, winner_list, result_histograms) else: holdem_functions.find_winner(generate_boards, deck, hole_cards, num, board_length, given_board, winner_list, result_histograms,pad_opp = pad_opp) if verbose: holdem_functions.print_results(hole_cards, winner_list, result_histograms) return holdem_functions.return_results(hole_cards, winner_list, result_histograms,pad_opp = pad_opp, board = given_board )
def run_simulation(hole_cards, num, exact, given_board, deck, verbose): num_players = len(hole_cards) # Create results data structures which track results of comparisons # 1) result_histograms: a list for each player that shows the number of # times each type of poker hand (e.g. flush, straight) was gotten # 2) winner_list: number of times each player wins the given round # 3) result_list: list of the best possible poker hand for each pair of # hole cards for a given board result_histograms, winner_list = [], [0] * (num_players + 1) for _ in range(num_players): result_histograms.append([0] * len(holdem_functions.hand_rankings)) # Choose whether we're running a Monte Carlo or exhaustive simulation board_length = 0 if given_board is None else len(given_board) if exact: generate_boards = holdem_functions.generate_exhaustive_boards else: generate_boards = holdem_functions.generate_random_boards if (None, None) in hole_cards: hole_cards_list = list(hole_cards) unknown_index = hole_cards.index((None, None)) for filler_hole_cards in holdem_functions.generate_hole_cards(deck): hole_cards_list[unknown_index] = filler_hole_cards deck_list = list(deck) deck_list.remove(filler_hole_cards[0]) deck_list.remove(filler_hole_cards[1]) holdem_functions.find_winner(generate_boards, tuple(deck_list), tuple(hole_cards_list), num, board_length, given_board, winner_list, result_histograms) else: holdem_functions.find_winner(generate_boards, deck, hole_cards, num, board_length, given_board, winner_list, result_histograms) if verbose: players_histograms = holdem_functions.calc_histogram( result_histograms, winner_list) return [ holdem_functions.find_winning_percentage(winner_list), players_histograms ]
def run_simulation(hole_cards, num, exact, given_board, deck, verbose): num_players = len(hole_cards) # Create results data structures which track results of comparisons # 1) result_histograms: a list for each player that shows the number of # times each type of poker hand (e.g. flush, straight) was gotten # 2) winner_list: number of times each player wins the given round # 3) result_list: list of the best possible poker hand for each pair of # hole cards for a given board result_histograms, winner_list = [], [0] * (num_players + 1) for _ in xrange(num_players): result_histograms.append([0] * len(holdem_functions.hand_rankings)) # Choose whether we're running a Monte Carlo or exhaustive simulation board_length = 0 if given_board is None else len(given_board) # When a board is given, exact calculation is much faster than Monte Carlo # simulation, so default to exact if a board is given if exact or given_board is not None: generate_boards = holdem_functions.generate_exhaustive_boards else: generate_boards = holdem_functions.generate_random_boards if (None, None) in hole_cards: hole_cards_list = list(hole_cards) unknown_index = hole_cards.index((None, None)) for filler_hole_cards in holdem_functions.generate_hole_cards(deck): hole_cards_list[unknown_index] = filler_hole_cards deck_list = list(deck) deck_list.remove(filler_hole_cards[0]) deck_list.remove(filler_hole_cards[1]) holdem_functions.find_winner(generate_boards, tuple(deck_list), tuple(hole_cards_list), num, board_length, given_board, winner_list, result_histograms) else: holdem_functions.find_winner(generate_boards, deck, hole_cards, num, board_length, given_board, winner_list, result_histograms) if verbose: holdem_functions.print_results(hole_cards, winner_list, result_histograms) return holdem_functions.find_winning_percentage(winner_list)