import streamlit as st from prettytable import PrettyTable import simulation as s from poker_functions import Card def run_simulation( hand: list[str], flop: list[str] = None, turn: list[str] = None, river: list[str] = None, sims=10000, ) -> None: sim = s.simulation_one_player(hand, flop, turn, river, sims=sims) hc_pct = s.percent(sim[1], sim[0]) hc_ratio = s.ratio(sim[1], sim[0]) pair_pct = s.percent(sim[2], sim[0]) pair_ratio = s.ratio(sim[2], sim[0]) two_pair_pct = s.percent(sim[3], sim[0]) two_pair_ratio = s.ratio(sim[3], sim[0]) three_ok_pct = s.percent(sim[4], sim[0]) three_ok_ratio = s.ratio(sim[4], sim[0]) straight_pct = s.percent(sim[5], sim[0]) straight_ratio = s.ratio(sim[5], sim[0]) flush_pct = s.percent(sim[6], sim[0]) flush_ratio = s.ratio(sim[6], sim[0]) boat_pct = s.percent(sim[7], sim[0]) boat_ratio = s.ratio(sim[7], sim[0]) quads_pct = s.percent(sim[8], sim[0]) quads_ratio = s.ratio(sim[8], sim[0]) strt_flush_pct = s.percent(sim[9], sim[0]) strt_flush_ratio = s.ratio(sim[9], sim[0]) hole_card_str = f"{Card(hand[0]).pretty_name} {Card(hand[1]).pretty_name}" table = PrettyTable() table.field_names = ["Your Hand", "Board"] if flop is None: flop = [] if turn is None: turn = [] if river is None: river = [] board_str = "".join(f"{Card(card).pretty_name} " for card in (flop + turn + river)) table.add_row([hole_card_str, board_str]) odds = PrettyTable() odds.add_column( "Best Final Hand", [ "High Card", "Pair", "Two Pair", "Three of a Kind", "Straight", "Flush", "Full House", "Four of a Kind", "Straight Flush", ], ) odds.add_column( "% Prob", [ hc_pct, pair_pct, two_pair_pct, three_ok_pct, straight_pct, flush_pct, boat_pct, quads_pct, strt_flush_pct, ], ) odds.add_column( "Odds", [ hc_ratio, pair_ratio, two_pair_ratio, three_ok_ratio, straight_ratio, flush_ratio, boat_ratio, quads_ratio, strt_flush_ratio, ], ) st.divider() st.subheader("Odds") st.write(table, "\n") st.write(f"We ran your hand {sims} times. Here's the odds:\n") st.write(odds, "\n") st.divider() if __name__ == "__main__": run_simulation(["As", "Ah"], ["2s", "3s", "4s"], sims=4000)