def get_decisions(game: PokerGame, hand: PokerHand) -> List[BasePokerDecision]: decisions: List[BasePokerDecision] = [] pot_size = 0 money: Dict[str, int] = {p.name: p.money for p in hand.players} bb: int = hand.big_blind Debug.datasets(')' * 20) for n, v in money.items(): Debug.datasets(f'{n} - {v}') Debug.datasets('(' * 20) for step, stage in hand: Debug.datasets('NEW STEP', step) gived: Dict[str, int] = {p.name: 0 for p in hand.players} if step == Step.Preflop: raise_amount = hand.big_blind else: raise_amount = 0 for act in stage: if act.event.is_statement(): continue Debug.datasets(act, raise_amount) if act.event == Event.Ante: pot_size += act.money money[act.player.name] -= act.money elif act.event == Event.SmallBlind: pot_size += act.money gived[act.player.name] = act.money money[act.player.name] -= act.money elif act.event == Event.BigBlind: pot_size += act.money gived[act.player.name] = act.money money[act.player.name] -= act.money elif act.event == Event.Fold: if act.player.cards is not None and act.player.cards.initialized( ) and not act.player.is_loser: pr = HoldemPoker.probability( act.player.cards, hand.board.get_from_step(step)) my_money = money[act.player.name] to_call = raise_amount - gived[act.player.name] des = PokerDecision.create(PokerDecisionAnswer.Fold, pr, my_money, pot_size, to_call, bb, step) decisions += [des] elif act.event == Event.Check: if act.player.cards is not None and act.player.cards.initialized( ) and not act.player.is_loser: pr = HoldemPoker.probability( act.player.cards, hand.board.get_from_step(step)) my_money = money[act.player.name] to_call = raise_amount - gived[act.player.name] des = PokerDecision.create( PokerDecisionAnswer.CheckCall, pr, my_money, pot_size, to_call, bb, step) decisions += [des] elif act.event == Event.Call: if act.player.cards is not None and act.player.cards.initialized( ) and not act.player.is_loser: pr = HoldemPoker.probability( act.player.cards, hand.board.get_from_step(step)) my_money = money[act.player.name] if raise_amount > my_money + gived[act.player.name]: to_call = my_money else: to_call = raise_amount - gived[act.player.name] des = PokerDecision.create( PokerDecisionAnswer.CheckCall, pr, my_money, pot_size, to_call, bb, step) decisions += [des] pot_size += act.money - gived[act.player.name] money[ act.player.name] -= act.money - gived[act.player.name] gived[act.player.name] = act.money elif act.event == Event.Raise or act.event == Event.Allin: if act.player.cards is not None and act.player.cards.initialized( ) and not act.player.is_loser: pr = HoldemPoker.probability( act.player.cards, hand.board.get_from_step(step)) my_money = money[act.player.name] to_call = raise_amount - gived[act.player.name] des = PokerDecision.create(PokerDecisionAnswer.Raise, pr, my_money, pot_size, to_call, bb, step) decisions += [des] pot_size += act.money - gived[act.player.name] money[ act.player.name] -= act.money - gived[act.player.name] gived[act.player.name] = act.money if raise_amount < act.money: raise_amount = act.money elif act.event == Event.ReturnMoney: pot_size -= act.money else: raise ValueError('you forget about', act.event) Debug.datasets(')' * 20) for n, v in gived.items(): Debug.datasets(f'{n}: {money[n]} ({v})') Debug.datasets('(' * 20) Debug.datasets('*' * 20) for des in decisions: Debug.datasets(des) Debug.datasets('_' * 20) return decisions
def get_decisions(game: PokerGame, hand: PokerHand) -> List[BasePokerDecision]: decisions: List[BasePokerDecision] = [] pot_size = 0 players_on_table = len(hand.players) players_active = players_on_table money: Dict[str, int] = {p.name: p.money for p in hand.players} bb: int = hand.big_blind Debug.datasets(')' * 20) for n, v in money.items(): Debug.datasets(f'{n} - {v}') Debug.datasets('(' * 20) for step, stage in hand: Debug.datasets('NEW STEP', step) gived: Dict[str, int] = {p.name: 0 for p in hand.players} players_not_moved = players_active - 1 # myself don`t count so minus 1 if step == Step.Preflop: raise_amount = hand.big_blind else: raise_amount = 0 for act in stage: if act.event.is_statement(): continue Debug.datasets(act, raise_amount) if act.event == Event.Ante: pot_size += act.money money[act.player.name] -= act.money elif act.event == Event.SmallBlind: pot_size += act.money gived[act.player.name] = act.money money[act.player.name] -= act.money elif act.event == Event.BigBlind: pot_size += act.money gived[act.player.name] = act.money money[act.player.name] -= act.money elif act.event == Event.Fold: if act.player.cards is not None and act.player.cards.initialized( ) and not act.player.is_loser: my_money = money[act.player.name] to_call = raise_amount - gived[act.player.name] des = PokerDecision6.create( PokerDecisionAnswer3.Fold, my_money, pot_size, to_call, bb, step, act.player.cards, hand.board.get_from_step(step), players_on_table, players_active, players_not_moved, ) decisions += [des] players_active -= 1 players_not_moved -= 1 elif act.event == Event.Check: if act.player.cards is not None and act.player.cards.initialized( ) and not act.player.is_loser: my_money = money[act.player.name] to_call = raise_amount - gived[act.player.name] des = PokerDecision6.create( PokerDecisionAnswer3.CheckCall, my_money, pot_size, to_call, bb, step, act.player.cards, hand.board.get_from_step(step), players_on_table, players_active, players_not_moved, ) decisions += [des] players_not_moved -= 1 elif act.event == Event.Call: if act.player.cards is not None and act.player.cards.initialized( ) and not act.player.is_loser: my_money = money[act.player.name] if raise_amount > my_money + gived[act.player.name]: to_call = my_money else: to_call = raise_amount - gived[act.player.name] des = PokerDecision6.create( PokerDecisionAnswer3.CheckCall, my_money, pot_size, to_call, bb, step, act.player.cards, hand.board.get_from_step(step), players_on_table, players_active, players_not_moved, ) decisions += [des] pot_size += act.money - gived[act.player.name] money[ act.player.name] -= act.money - gived[act.player.name] gived[act.player.name] = act.money players_not_moved -= 1 elif act.event == Event.Raise or act.event == Event.Allin: if act.player.cards is not None and act.player.cards.initialized( ) and not act.player.is_loser: my_money = money[act.player.name] to_call = raise_amount - gived[act.player.name] actually_raised = act.money - gived[act.player.name] pot_sized_raise = actually_raised / pot_size if my_money == actually_raised: answer = PokerDecisionAnswer3.AllIn elif pot_sized_raise < 0.25: answer = PokerDecisionAnswer3.RaiseSmall elif pot_sized_raise < 0.75: answer = PokerDecisionAnswer3.RaiseMedium else: answer = PokerDecisionAnswer3.RaiseALot des = PokerDecision6.create( answer, my_money, pot_size, to_call, bb, step, act.player.cards, hand.board.get_from_step(step), players_on_table, players_active, players_not_moved, ) decisions += [des] pot_size += act.money - gived[act.player.name] money[ act.player.name] -= act.money - gived[act.player.name] gived[act.player.name] = act.money if raise_amount < act.money: raise_amount = act.money players_not_moved = players_active - 2 # without raiser and myself elif act.event == Event.ReturnMoney: pot_size -= act.money else: raise ValueError('you forget about', act.event) Debug.datasets(')' * 20) for n, v in gived.items(): Debug.datasets(f'{n}: {money[n]} ({v})') Debug.datasets('(' * 20) Debug.datasets('*' * 20) for des in decisions: Debug.datasets(des) Debug.datasets('_' * 20) return decisions
def get_decisions(game: PokerGame, hand: PokerHand) -> List[BasePokerDecision]: if game != PokerDecision10.CurrGame: PokerDecision10.CurrGame = game PokerDecision10.CurrRaisers = dict() PokerDecision10.CurrCallers = dict() PokerDecision10.CurrFolders = dict() PokerDecision10.CurrCheckers = dict() curr_raisers: Dict[Tuple[str, PokerPosition], PlayerStatistics] = PokerDecision10.CurrRaisers curr_callers: Dict[Tuple[str, PokerPosition], PlayerStatistics] = PokerDecision10.CurrCallers curr_folders: Dict[Tuple[str, PokerPosition], PlayerStatistics] = PokerDecision10.CurrFolders curr_checkers: Dict[Tuple[str, PokerPosition], PlayerStatistics] = PokerDecision10.CurrCheckers for player in hand.players: key = (player.name, player.position) if key not in curr_raisers: curr_raisers[key] = PlayerStatistics() if key not in curr_callers: curr_callers[key] = PlayerStatistics() if key not in curr_folders: curr_folders[key] = PlayerStatistics() if key not in curr_checkers: curr_checkers[key] = PlayerStatistics() decisions: List[BasePokerDecision] = [] pot_size = 0 players_on_table = len(hand.players) players_active = players_on_table folded_players: List[str] = [] money: Dict[str, int] = {p.name: p.money for p in hand.players} average_money_on_table: int = int( sum(p.money for p in hand.players) / len(hand.players)) max_money_on_table: int = max(p.money for p in hand.players) bb: int = hand.big_blind Debug.datasets(')' * 20) for n, v in money.items(): Debug.datasets(f'{n} - {v}') Debug.datasets('(' * 20) for step, stage in hand: Debug.datasets('NEW STEP', step) gived: Dict[str, int] = {p.name: 0 for p in hand.players} players_not_moved = players_active - 1 # myself don`t count so minus 1 if step == Step.Preflop: raise_amount = hand.big_blind else: raise_amount = 0 for act in stage: if act.event.is_statement(): continue Debug.datasets(act, raise_amount) folder = curr_folders[act.player.name, act.player.position] caller = curr_callers[act.player.name, act.player.position] raiser = curr_raisers[act.player.name, act.player.position] checker = curr_checkers[act.player.name, act.player.position] if act.event == Event.Ante: pot_size += act.money money[act.player.name] -= act.money elif act.event == Event.SmallBlind: pot_size += act.money gived[act.player.name] = act.money money[act.player.name] -= act.money elif act.event == Event.BigBlind: pot_size += act.money gived[act.player.name] = act.money money[act.player.name] -= act.money elif act.event == Event.Fold: if act.player.cards is not None and act.player.cards.initialized( ) and not act.player.is_loser: my_money = money[act.player.name] to_call = raise_amount - gived[act.player.name] des = PokerDecision10.create( PokerDecisionAnswer3.Fold, my_money, pot_size, to_call, bb, step, act.player.cards, hand.board.get_from_step(step), players_on_table, players_active, players_not_moved, max_money_on_table, average_money_on_table, hand.players, folded_players, act.player.position, ) decisions += [des] if step == Step.Preflop: folder.activate() caller.skip() raiser.skip() if raise_amount == 0 or raise_amount == gived[ act.player.name]: checker.skip() players_active -= 1 players_not_moved -= 1 folded_players += [act.player.name] elif act.event == Event.Check: if act.player.cards is not None and act.player.cards.initialized( ) and not act.player.is_loser: my_money = money[act.player.name] to_call = raise_amount - gived[act.player.name] des = PokerDecision10.create( PokerDecisionAnswer3.CheckCall, my_money, pot_size, to_call, bb, step, act.player.cards, hand.board.get_from_step(step), players_on_table, players_active, players_not_moved, max_money_on_table, average_money_on_table, hand.players, folded_players, act.player.position, ) decisions += [des] if step == Step.Preflop: folder.skip() checker.activate() raiser.skip() players_not_moved -= 1 elif act.event == Event.Call: if act.player.cards is not None and act.player.cards.initialized( ) and not act.player.is_loser: my_money = money[act.player.name] if raise_amount > my_money + gived[act.player.name]: to_call = my_money else: to_call = raise_amount - gived[act.player.name] des = PokerDecision10.create( PokerDecisionAnswer3.CheckCall, my_money, pot_size, to_call, bb, step, act.player.cards, hand.board.get_from_step(step), players_on_table, players_active, players_not_moved, max_money_on_table, average_money_on_table, hand.players, folded_players, act.player.position, ) decisions += [des] if step == Step.Preflop: folder.skip() caller.activate() raiser.skip() pot_size += act.money - gived[act.player.name] money[ act.player.name] -= act.money - gived[act.player.name] gived[act.player.name] = act.money players_not_moved -= 1 elif act.event == Event.Raise or act.event == Event.Allin: if act.player.cards is not None and act.player.cards.initialized( ) and not act.player.is_loser: my_money = money[act.player.name] to_call = raise_amount - gived[act.player.name] actually_raised = act.money - gived[act.player.name] pot_sized_raise = actually_raised / pot_size if my_money == actually_raised: answer = PokerDecisionAnswer3.AllIn elif pot_sized_raise < 0.25: answer = PokerDecisionAnswer3.RaiseSmall elif pot_sized_raise < 0.75: answer = PokerDecisionAnswer3.RaiseMedium else: answer = PokerDecisionAnswer3.RaiseALot des = PokerDecision10.create( answer, my_money, pot_size, to_call, bb, step, act.player.cards, hand.board.get_from_step(step), players_on_table, players_active, players_not_moved, max_money_on_table, average_money_on_table, hand.players, folded_players, act.player.position, ) decisions += [des] if step == Step.Preflop: folder.skip() caller.skip() raiser.activate() if raise_amount == 0 or raise_amount == gived[ act.player.name]: checker.skip() pot_size += act.money - gived[act.player.name] money[ act.player.name] -= act.money - gived[act.player.name] gived[act.player.name] = act.money if raise_amount < act.money: raise_amount = act.money players_not_moved = players_active - 2 # without raiser and myself elif act.event == Event.ReturnMoney: pot_size -= act.money else: raise ValueError('you forget about', act.event) Debug.datasets(')' * 20) for n, v in gived.items(): Debug.datasets(f'{n}: {money[n]} ({v})') Debug.datasets('(' * 20) Debug.datasets('*' * 20) for des in decisions: Debug.datasets(des) Debug.datasets('_' * 20) return decisions