示例#1
0
    def _decide(self, *, step: Step, to_call: int, min_raise: int,
                board: Cards, online: bool, **_) -> Tuple[Option, int]:

        if step == Step.Preflop:
            curr_play: BasePlay = self.play.preflop

        elif step == Step.Flop:
            curr_play: BasePlay = self.play.flop

        elif step == Step.Turn:
            curr_play: BasePlay = self.play.turn

        elif step == Step.River:
            curr_play: BasePlay = self.play.river

        else:
            raise ValueError(f'Undefined step id {step}')

        if self.remaining_money() > min_raise * 3 and random(
        ) < curr_play.bluff:
            bluff = int(min_raise * (1 + random()))

            Debug.decision(
                f'609 {self.name} raise bluff {bluff}; bluff = {curr_play.bluff}'
            )

            if online:
                sleep(uniform(0.5, uniform(1, 2)))

            return Option.Raise, bluff

        probability = HoldemPoker.probability(self.cards, board)

        if probability < curr_play.min_probability_to_play:

            if to_call == 0 or to_call == self.gived:
                Debug.decision(
                    f'617 {self.name} check on low '
                    f'prob = {probability}; '
                    f'bet coefficient = {curr_play.bet} '
                    f'to call = {to_call} self.gived = {self.gived}')

                if online:
                    sleep(uniform(0.5, 1))

                return Option.CheckCall, 0

            else:
                Debug.decision(f'624 {self.name} fold low probability; '
                               f'prob = {probability}; '
                               f'min = {curr_play.min_probability_to_play}')

                if online:
                    sleep(uniform(0.5, 1))

                return Option.Fold, 0

        if probability > curr_play.min_probability_to_all_in and random(
        ) < curr_play.probability_to_all_in:

            if self.remaining_money() <= to_call:
                Debug.decision(
                    f'630 {self.name} call all in {self.gived} on high '
                    f'prob = {probability}; '
                    f'min = {curr_play.min_probability_to_all_in}')

                if online:
                    sleep(uniform(1, uniform(1.5, 3)))

            else:
                Debug.decision(f'631 {self.name} all in {self.gived} on high '
                               f'prob = {probability}; '
                               f'min = {curr_play.min_probability_to_all_in}')

                if online:
                    sleep(uniform(1, uniform(1.5, 3)))

            return Option.Raise, self.remaining_money()

        bet = int(
            min(probability * curr_play.bet_, 1) * self.remaining_money())

        if bet == self.remaining_money():

            if self.remaining_money() <= to_call:
                Debug.decision(
                    f'632 {self.name} call all in {self.gived} on high bet '
                    f'prob = {probability}; '
                    f'min = {curr_play.min_probability_to_all_in}')

                if online:
                    sleep(uniform(2, uniform(3, 5)))

            else:
                Debug.decision(
                    f'640 {self.name} all in {self.gived} on high bet '
                    f'prob = {probability}; '
                    f'bet coefficient = {curr_play.bet}')

                if online:
                    sleep(uniform(2, uniform(3, 5)))

            return Option.Raise, bet

        if to_call > bet:

            if to_call == 0 or self.gived == to_call:
                Debug.decision(
                    f'643 {self.name} check while can not raise bet = {bet}')

                if online:
                    sleep(uniform(0.5, uniform(1, 3)))

                return Option.CheckCall, 0

            else:
                Debug.decision(f'647 {self.name} fold on low bet '
                               f'prob = {probability}; '
                               f'bet coefficient = {curr_play.bet} '
                               f'bet = {bet}')

                if online:
                    sleep(uniform(1, uniform(2, 4)))

                return Option.Fold, 0

        if min_raise > bet:

            if to_call == 0 or self.gived == to_call:
                Debug.decision(f'656 {self.name} check on mid bet '
                               f'prob = {probability}; '
                               f'bet coefficient = {curr_play.bet} '
                               f'bet = {bet}')

                if online:
                    sleep(uniform(0.5, uniform(1, 2)))

                return Option.CheckCall, 0

            else:
                Debug.decision(f'666 {self.name} call {to_call} on mid bet '
                               f'prob = {probability}; '
                               f'bet coefficient = {curr_play.bet} '
                               f'bet = {bet}')

                if online:
                    sleep(uniform(2, uniform(4, 6)))

                return Option.CheckCall, to_call

        else:

            raise_bet = int(
                min(probability * curr_play.bet_ * curr_play.reduced_raise, 1)
                * self.remaining_money())

            if raise_bet <= self.gived:

                if to_call == 0 or self.gived == to_call:
                    Debug.decision(
                        f'670 {self.name} check while thinks about raise {raise_bet}'
                    )

                    if online:
                        sleep(uniform(1, uniform(2, 3)))

                    return Option.CheckCall, 0

                else:
                    Debug.decision(
                        f'672 {self.name} fold while thinks about raise {raise_bet}'
                    )

                    if online:
                        sleep(uniform(2, uniform(4, 6)))

                    return Option.Fold, 0

            if raise_bet < to_call:

                if to_call == 0 or self.gived == to_call:
                    Debug.decision(
                        f'673 {self.name} check while thinks about raise {raise_bet}'
                    )

                    if online:
                        sleep(uniform(1, uniform(2, 3)))

                    return Option.CheckCall, 0

                else:
                    Debug.decision(
                        f'677 {self.name} fold while thinks about raise {raise_bet}'
                    )

                    if online:
                        sleep(uniform(2, uniform(4, 6)))

                    return Option.Fold, 0

            if raise_bet < min_raise:

                if to_call == 0 or to_call == self.gived:
                    Debug.decision(
                        f'656 {self.name} check while thinks about raise {raise_bet}'
                    )

                    if online:
                        sleep(uniform(0.5, uniform(1, 2)))

                    return Option.CheckCall, 0

                else:
                    Debug.decision(
                        f'682 {self.name} call {to_call} while thinks about raise {raise_bet}'
                    )

                    if online:
                        sleep(uniform(3, uniform(6, 8)))

                    return Option.CheckCall, to_call

            if raise_bet == self.remaining_money():

                if raise_bet <= to_call:
                    Debug.decision(f'684 {self.name} call all in {self.gived}')

                    if online:
                        sleep(uniform(2, uniform(4, 6)))

                else:
                    Debug.decision(
                        f'687 {self.name} all in {self.gived} while thinks about raise {raise_bet}'
                    )

                    if online:
                        sleep(uniform(1, uniform(2, 3)))

                return Option.Raise, raise_bet

            if to_call == 0 and random() < curr_play.check_:
                Debug.decision(
                    f'690 {self.name} cold check wanted to raise {raise_bet} '
                    f'check probability {curr_play.check}')

                if online:
                    sleep(uniform(0.5, uniform(1, 2)))

                return Option.CheckCall, 0

            elif to_call != 0 and random() < curr_play.call:

                if self.remaining_money() <= to_call:
                    Debug.decision(
                        f'691 {self.name} cold call all in {self.gived}')

                    if online:
                        sleep(uniform(2, uniform(4, 6)))

                    return Option.CheckCall, self.remaining_money()

                else:
                    Debug.decision(
                        f'692 {self.name} cold call {to_call} while wanted to raise {raise_bet} '
                        f'call probability {curr_play.call}')

                    if online:
                        sleep(uniform(2, uniform(4, 6)))

                    return Option.CheckCall, to_call

            if self.remaining_money() <= raise_bet:

                if self.remaining_money() <= to_call:
                    Debug.decision(f'693 {self.name} call all in {self.gived}')

                    if online:
                        sleep(uniform(2, uniform(4, 6)))

                else:
                    Debug.decision(
                        f'694 {self.name} raise all in {self.gived}')

                    if online:
                        sleep(uniform(2, uniform(4, 6)))

                return Option.Raise, self.remaining_money()

            else:
                Debug.decision(
                    f'695 {self.name} raise {raise_bet} on high bet '
                    f'prob = {probability}; '
                    f'bet coefficient = {curr_play.bet} '
                    f'bet = {bet}')

                if online:
                    sleep(uniform(3, uniform(6, 9)))

                return Option.Raise, raise_bet
示例#2
0
    def _decide(self, *, step: Step, to_call: int, min_raise: int,
                board: Cards, pot: int, bb: int, strength: Strength,
                players_on_table: int, players_active: int,
                players_not_moved: int, **_) -> Tuple[Option, int]:
        if players_on_table < 2 or players_on_table > 10:
            raise ValueError('bad players on table:', players_active)

        if players_active < 2 or players_active > 10:
            raise ValueError('bad players active:', players_active)

        if players_active > players_on_table:
            raise ValueError('bad players active:', players_active,
                             'with players on table:', players_on_table)

        if players_not_moved < 0 or players_not_moved >= players_active:
            raise ValueError('bad players not moved:', players_not_moved,
                             'with players active:', players_active)

        evaluation = HoldemPoker.probability(self.cards, board)
        outs: float = HoldemPoker.calculate_outs(self.cards, board)[0]
        first: Rank = self.cards.first.rank
        second: Rank = self.cards.second.rank
        prediction = self.nn.predict(
            self.create_input(
                evaluation, self.money / pot, to_call / pot, bb / pot,
                step is Step.Preflop, step is Step.Flop, step is Step.Turn,
                step is Step.River, strength is Strength.Nothing,
                strength is Strength.Pair, strength is Strength.Pairs,
                strength is Strength.Set, strength is Strength.Straight,
                strength is Strength.Flush, strength is Strength.FullHouse,
                strength is Strength.Quad, strength is Strength.StraightFlush,
                strength is Strength.RoyalFlush, first is Rank.Two,
                first is Rank.Three, first is Rank.Four, first is Rank.Five,
                first is Rank.Six, first is Rank.Seven, first is Rank.Eight,
                first is Rank.Nine, first is Rank.Ten, first is Rank.Jack,
                first is Rank.Queen, first is Rank.King, first is Rank.Ace,
                second is Rank.Two, second is Rank.Three, second is Rank.Four,
                second is Rank.Five, second is Rank.Six, second is Rank.Seven,
                second is Rank.Eight, second is Rank.Nine, second is Rank.Ten,
                second is Rank.Jack, second is Rank.Queen, second is Rank.King,
                second is Rank.Ace,
                self.cards.suitability is Suitability.Suited,
                players_on_table == 2, players_on_table == 3,
                players_on_table == 4, players_on_table == 5,
                players_on_table == 6, players_on_table == 7,
                players_on_table == 8, players_on_table == 9,
                players_on_table == 10, players_active == 2,
                players_active == 3, players_active == 4, players_active == 5,
                players_active == 6, players_active == 7, players_active == 8,
                players_active == 9, players_active == 10,
                players_not_moved == 0, players_not_moved == 1,
                players_not_moved == 2, players_not_moved == 3,
                players_not_moved == 4, players_not_moved == 5,
                players_not_moved == 6, players_not_moved == 7,
                players_not_moved == 8, players_not_moved == 9,
                outs / HoldemPoker.MAX_OUTS))

        Debug.decision("NEURAL NETWORK 7 START THINK")
        Debug.decision('evaluation =', evaluation)
        Debug.decision('pot =', pot)
        Debug.decision('money =', self.money)
        Debug.decision('to_call =', to_call)
        Debug.decision('bb =', bb)
        Debug.decision('step =', step)
        Debug.decision('strength =', strength)
        Debug.decision('first =', first)
        Debug.decision('second =', second)
        Debug.decision('suited =', self.cards.suitability)
        Debug.decision('players_on_table =', players_on_table)
        Debug.decision('players_active =', players_active)
        Debug.decision('players_not_moved =', players_not_moved)
        Debug.decision('outs =', outs)

        answer: PokerDecisionAnswer3 = PokerDecisionAnswer3(prediction[0])

        Debug.decision('ANSWER =', answer)
        Debug.decision("NEURAL NETWORK 7 END THINK")

        raise_amount = 0
        if answer is PokerDecisionAnswer3.AllIn:
            raise_amount = self.remaining_money()
        elif answer is PokerDecisionAnswer3.RaiseSmall:
            raise_amount = (0.1 + 0.25 * random()) * pot
        elif answer is PokerDecisionAnswer3.RaiseMedium:
            raise_amount = (0.25 + 0.4 * random()) * pot
        elif answer is PokerDecisionAnswer3.RaiseALot:
            raise_amount = (0.6 + 0.6 * random()) * pot

        return answer.as_option(), raise_amount