Exemplo n.º 1
0
    def first_round_98h(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/98h.png', strategy='Snowie3', round_number=0)
        t.checkButton = False
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "PreFlop"
        d.__init__(t, h, p, l)
        d.preflop_table_analyser(t, logger, h, p)

        self.assertEqual(t.preflop_sheet_name, '4R3')
Exemplo n.º 2
0
    def second_round_with_raiser(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/QQ.png', strategy='Snowie3', round_number=1)
        l = MagicMock()
        t.checkButton = False
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "PreFlop"
        d.__init__(t, h, p, l)
        d.preflop_table_analyser(t, logger, h, p)

        self.assertEqual(t.preflop_sheet_name, '22R6')
Exemplo n.º 3
0
    def sheet_12R4R6(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/12R4R6.png', round_number=1)
        l = MagicMock()
        t.checkButton = False
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "PreFlop"
        d.__init__(t, h, p, l)
        d.preflop_table_analyser(t, logger, h, p)

        self.assertEqual(t.preflop_sheet_name, '12R4R6')
Exemplo n.º 4
0
    def incorrect_preflop_table2(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/3Ts.png', strategy='Snowie3')
        l = MagicMock()
        t.checkButton = False
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "PreFlop"
        d.__init__(t, h, p, l)
        d.preflop_table_analyser(t, logger, h, p)

        self.assertEqual(t.preflop_sheet_name, '6R1C2')
Exemplo n.º 5
0
    def test_preflop_round2_3(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/897376414_PreFlop_1.png', round_number=1)
        p = StrategyHandler()
        p.read_strategy('Pokemon4')
        l = MagicMock()
        t.checkButton = False
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "PreFlop"

        d.__init__(t, h, p, l)
        d.preflop_table_analyser(t, logger, h, p)
        self.assertEqual(t.first_raiser_utg, 2)
Exemplo n.º 6
0
    def incorrect_preflop_table1(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/K9o.png', strategy='Snowie3')
        l = MagicMock()
        t.checkButton = False
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "PreFlop"
        d.__init__(t, h, p, l)
        d.preflop_table_analyser(t, logger, h, p)

        self.assertEqual(t.first_raiser_utg, 4)
        self.assertEqual(np.isnan(t.second_raiser_utg), True)
        self.assertEqual(t.preflop_sheet_name, '6R5')
Exemplo n.º 7
0
    def test_position_adjustment(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/467381034_PreFlop_0.png', strategy='Pokemon4')
        t.gameStage = "PreFlop"
        p = StrategyHandler()
        p.read_strategy('Nickpick12')
        l = MagicMock()
        t.checkButton = True
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "Flop"
        p.selected_strategy['FlopBluffMinEquity'] = 0.3
        p.selected_strategy['FlopBluff'] = "1"
        p.selected_strategy['pre_flop_equity_reduction_by_position'] = 0.02

        d.__init__(t, h, p, l)
        self.assertAlmostEqual(d.preflop_adjustment, 0.1, delta=0.01)
Exemplo n.º 8
0
    def test_position_adjustment(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/467381034_PreFlop_0.png', strategy='Pokemon4')
        t.gameStage="PreFlop"
        p = StrategyHandler()
        p.read_strategy('Nickpick12')
        l = MagicMock()
        t.checkButton = True
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "Flop"
        p.selected_strategy['FlopBluffMinEquity'] = 0.3
        p.selected_strategy['FlopBluff'] = "1"
        p.selected_strategy['pre_flop_equity_reduction_by_position'] = 0.02

        d.__init__(t, h, p, l)
        self.assertAlmostEqual(d.preflop_adjustment, 0.1, delta=0.01)
Exemplo n.º 9
0
    def test_preflop_call_before_raise(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/1791526_PreFlop_0.png', round_number=0)
        p = StrategyHandler()
        p.read_strategy('Pokemon4')
        l = MagicMock()
        t.checkButton = False
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "PreFlop"

        d.__init__(t, h, p, l)
        d.preflop_table_analyser(t, logger, h, p)

        self.assertEqual(t.first_raiser, 2)
        self.assertEqual(t.second_raiser, 4)

        self.assertEqual(t.preflop_sheet_name, '6R5C3')
Exemplo n.º 10
0
    def no_test_preflop_state1(self):
        strategy = 'snowie1'

        # preflop
        t, p, _, h, _ = init_table('tests/screenshots/76s.png',
                                   strategy=strategy)
        p = StrategyHandler()
        p.read_strategy(strategy)
        lst = MagicMock()
        t.totalPotValue = 0.5
        t.equity = 0.5
        t.checkButton = False
        d = Decision(t, h, p, lst)
        t.isHeadsUp = True
        t.gameStage = "PreFlop"
        d.__init__(t, h, p, lst)
        d.preflop_table_analyser(t, h, p)
        preflop_state = CurrentHandPreflopState()
        bot_preflop_decision = 'Call'
        d = MagicMock()
        preflop_state.update_values(t, bot_preflop_decision, h, d)

        self.assertEqual(t.preflop_sheet_name, '6R4')

        # flop
        t, p, _, h, _ = init_table('tests/screenshots/76ss.png',
                                   strategy=strategy)
        sheet_name = ''
        for abs_pos in range(5):
            if t.other_players[abs_pos]['status'] == 1:
                sheet_name = preflop_state.get_reverse_sheetname(abs_pos, t, h)

        self.assertEqual('4', sheet_name)
Exemplo n.º 11
0
    def no_test_position_adjustment(self):
        table, strategy, _, history, _ = init_table(
            'tests/screenshots/467381034_PreFlop_0.png', strategy='Pokemon4')
        table.gameStage = "PreFlop"
        strategy = StrategyHandler()
        strategy.read_strategy('Nickpick12')
        l = MagicMock()
        table.checkButton = True
        d = Decision(table, history, strategy, l)
        table.isHeadsUp = True
        table.gameStage = "Flop"
        strategy.selected_strategy['FlopBluffMinEquity'] = 0.3
        strategy.selected_strategy['FlopBluff'] = "1"
        strategy.selected_strategy[
            'pre_flop_equity_reduction_by_position'] = 0.02

        d.__init__(table, history, strategy, l)
        self.assertAlmostEqual(d.preflop_adjustment, 0.1, delta=0.01)
Exemplo n.º 12
0
    def first_round_98h(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/98h.png', strategy='Snowie3', round_number=0)
        t.checkButton = False
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "PreFlop"
        d.__init__(t, h, p, l)
        d.preflop_table_analyser(t, logger, h, p)

        self.assertEqual(t.preflop_sheet_name, '4R3')
Exemplo n.º 13
0
    def sheet_12R4R6(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/12R4R6.png', round_number=1)
        l = MagicMock()
        t.checkButton = False
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "PreFlop"
        d.__init__(t, h, p, l)
        d.preflop_table_analyser(t, logger, h, p)

        self.assertEqual(t.preflop_sheet_name, '12R4R6')
Exemplo n.º 14
0
    def incorrect_preflop_table2(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/3Ts.png', strategy='Snowie3')
        l = MagicMock()
        t.checkButton = False
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "PreFlop"
        d.__init__(t, h, p, l)
        d.preflop_table_analyser(t, logger, h, p)

        self.assertEqual(t.preflop_sheet_name, '6R1C2')
Exemplo n.º 15
0
    def second_round_with_raiser(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/QQ.png', strategy='Snowie3', round_number=1)
        l = MagicMock()
        t.checkButton = False
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "PreFlop"
        d.__init__(t, h, p, l)
        d.preflop_table_analyser(t, logger, h, p)

        self.assertEqual(t.preflop_sheet_name, '22R6')
Exemplo n.º 16
0
def reverse_init(t, h, p):
    lst = MagicMock()
    t.totalPotValue = 0.5
    t.equity = 0.5
    t.checkButton = False
    d = Decision(t, h, p, lst)
    t.isHeadsUp = True
    t.gameStage = "PreFlop"
    d.__init__(t, h, p, lst)
    d.preflop_table_analyser(t, h, p)
    return d
Exemplo n.º 17
0
    def sheet_12R4R6(self):
        table, strategy, _, history, _ = init_table(
            'tests/screenshots/12R4R6.png', round_number=1)
        l = MagicMock()
        table.checkButton = False
        d = Decision(table, history, strategy, l)
        table.isHeadsUp = True
        table.gameStage = "PreFlop"
        d.__init__(table, history, strategy, l)
        d.preflop_table_analyser(table, history, strategy)

        self.assertEqual(table.preflop_sheet_name, '12R4R6')
Exemplo n.º 18
0
    def first_round_98h(self):
        table, strategy, _, history, _ = init_table(
            'tests/screenshots/98h.png', strategy='Snowie3', round_number=0)
        table.checkButton = False
        l = MagicMock()
        d = Decision(table, history, strategy, l)
        table.isHeadsUp = True
        table.gameStage = "PreFlop"
        d.__init__(table, history, strategy, l)
        d.preflop_table_analyser(table, history, strategy)

        self.assertEqual(table.preflop_sheet_name, '4R3')
Exemplo n.º 19
0
    def incorrect_preflop_table2(self):
        table, strategy, _, history, _ = init_table(
            'tests/screenshots/3Ts.png', strategy='Snowie3')
        l = MagicMock()
        table.checkButton = False
        d = Decision(table, history, strategy, l)
        table.isHeadsUp = True
        table.gameStage = "PreFlop"
        d.__init__(table, history, strategy, l)
        d.preflop_table_analyser(table, history, strategy)

        self.assertEqual(table.preflop_sheet_name, '6R1C2')
Exemplo n.º 20
0
    def incorrect_preflop_table1(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/K9o.png', strategy='Snowie3')
        l = MagicMock()
        t.checkButton = False
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "PreFlop"
        d.__init__(t, h, p, l)
        d.preflop_table_analyser(t, logger, h, p)

        self.assertEqual(t.first_raiser_utg, 4)
        self.assertEqual(np.isnan(t.second_raiser_utg), True)
        self.assertEqual(t.preflop_sheet_name, '6R5')
Exemplo n.º 21
0
    def test_preflop_round2_3(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/897376414_PreFlop_1.png', round_number=1)
        p = StrategyHandler()
        p.read_strategy('Pokemon4')
        l = MagicMock()
        t.checkButton = False
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "PreFlop"

        d.__init__(t, h, p, l)
        d.preflop_table_analyser(t, logger, h, p)
        self.assertEqual(t.first_raiser_utg, 2)
Exemplo n.º 22
0
    def no_test_preflop_round2_3(self):
        table, strategy, _, history, _ = init_table(
            'tests/screenshots/897376414_PreFlop_1.png', round_number=1)
        strategy = StrategyHandler()
        strategy.read_strategy('Pokemon4')
        l = MagicMock()
        table.checkButton = False
        d = Decision(table, history, strategy, l)
        table.isHeadsUp = True
        table.gameStage = "PreFlop"

        d.__init__(table, history, strategy, l)
        d.preflop_table_analyser(table, history, strategy)
        self.assertEqual(table.first_raiser_utg, 2)
Exemplo n.º 23
0
    def incorrect_preflop_table1(self):
        table, strategy, _, history, _ = init_table(
            'tests/screenshots/K9o.png', strategy='Snowie3')
        l = MagicMock()
        table.checkButton = False
        d = Decision(table, history, strategy, l)
        table.isHeadsUp = True
        table.gameStage = "PreFlop"
        d.__init__(table, history, strategy, l)
        d.preflop_table_analyser(table, history, strategy)

        self.assertEqual(table.first_raiser_utg, 4)
        self.assertEqual(np.isnan(table.second_raiser_utg), True)
        self.assertEqual(table.preflop_sheet_name, '6R5')
Exemplo n.º 24
0
    def test_bluff(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/751235173_PreFlop_0.png')
        p = StrategyHandler()
        p.read_strategy('Pokemon')
        l = MagicMock()
        t.totalPotValue = 0.5
        t.equity = 0.7
        t.checkButton = True
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "Flop"
        p.selected_strategy['FlopBluffMinEquity'] = 0.3
        p.selected_strategy['FlopBluff'] = "1"

        d.decision = DecisionTypes.check
        t.playersAhead = 0
        d.bluff(t, p, h)
        self.assertEqual(d.decision, DecisionTypes.bet_bluff)

        d.decision = DecisionTypes.check
        t.playersAhead = 1
        d.bluff(t, p, h)
        self.assertEqual(d.decision, DecisionTypes.check)
Exemplo n.º 25
0
    def test_preflop_call_before_raise(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/1791526_PreFlop_0.png', round_number=0)
        p = StrategyHandler()
        p.read_strategy('Pokemon4')
        l = MagicMock()
        t.checkButton = False
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "PreFlop"

        d.__init__(t, h, p, l)
        d.preflop_table_analyser(t, logger, h, p)

        self.assertEqual(t.first_raiser, 2)
        self.assertEqual(t.second_raiser, 4)

        self.assertEqual(t.preflop_sheet_name, '6R5C3')
Exemplo n.º 26
0
    def no_test_bluff(self):
        table, strategy, _, history, _ = init_table(
            'tests/screenshots/751235173_PreFlop_0.png')
        strategy = StrategyHandler()
        strategy.read_strategy('Pokemon')
        l = MagicMock()
        table.totalPotValue = 0.5
        table.equity = 0.7
        table.checkButton = True
        d = Decision(table, history, strategy, l)
        table.isHeadsUp = True
        table.gameStage = "Flop"
        strategy.selected_strategy['FlopBluffMinEquity'] = 0.3
        strategy.selected_strategy['FlopBluff'] = "1"

        d.decision = DecisionTypes.check
        table.playersAhead = 0
        d.bluff(table, strategy, history)
        self.assertEqual(d.decision, DecisionTypes.bet_bluff)

        d.decision = DecisionTypes.check
        table.playersAhead = 1
        d.bluff(table, strategy, history)
        self.assertEqual(d.decision, DecisionTypes.check)
Exemplo n.º 27
0
    def no_test_preflop_call_before_raise(self):
        table, strategy, _, history, _ = init_table(
            'tests/screenshots/1791526_PreFlop_0.png', round_number=0)
        strategy = StrategyHandler()
        strategy.read_strategy('Pokemon4')
        l = MagicMock()
        table.checkButton = False
        d = Decision(table, history, strategy, l)
        table.isHeadsUp = True
        table.gameStage = "PreFlop"

        d.__init__(table, history, strategy, l)
        d.preflop_table_analyser(table, history, strategy)

        self.assertEqual(table.first_raiser, 2)
        self.assertEqual(table.second_raiser, 4)

        self.assertEqual(table.preflop_sheet_name, '6R5C3')
Exemplo n.º 28
0
    def test_bluff(self):
        t, p, gui_signals, h, logger = init_table('tests/screenshots/751235173_PreFlop_0.png')
        p = StrategyHandler()
        p.read_strategy('Pokemon')
        l = MagicMock()
        t.totalPotValue = 0.5
        t.equity = 0.7
        t.checkButton = True
        d = Decision(t, h, p, l)
        t.isHeadsUp = True
        t.gameStage = "Flop"
        p.selected_strategy['FlopBluffMinEquity'] = 0.3
        p.selected_strategy['FlopBluff'] = "1"

        d.decision = DecisionTypes.check
        t.playersAhead = 0
        d.bluff(t, p, h)
        self.assertEqual(d.decision, DecisionTypes.bet_bluff)

        d.decision = DecisionTypes.check
        t.playersAhead = 1
        d.bluff(t, p, h)
        self.assertEqual(d.decision, DecisionTypes.check)
Exemplo n.º 29
0
    def run(self):
        log = logging.getLogger(__name__)
        history = History()
        preflop_url, preflop_url_backup = self.updater.get_preflop_sheet_url()
        try:
            history.preflop_sheet = pd.read_excel(preflop_url,
                                                  sheet_name=None,
                                                  engine='openpyxl')
        except:
            history.preflop_sheet = pd.read_excel(preflop_url_backup,
                                                  sheet_name=None,
                                                  engine='openpyxl')

        self.game_logger.clean_database()

        strategy = StrategyHandler()
        strategy.read_strategy()

        preflop_state = CurrentHandPreflopState()
        mongo = MongoManager()
        table_scraper_name = None

        while True:
            # reload table if changed
            config = ConfigObj(CONFIG_FILENAME)
            if table_scraper_name != config['table_scraper_name']:
                table_scraper_name = config['table_scraper_name']
                log.info(
                    f"Loading table scraper info for {table_scraper_name}")
                table_dict = mongo.get_table(table_scraper_name)

            if self.gui_signals.pause_thread:
                while self.gui_signals.pause_thread:
                    time.sleep(0.5)
                    if self.gui_signals.exit_thread:
                        sys.exit()

            ready = False
            while not ready:
                strategy.read_strategy()
                table = TableScreenBased(strategy, table_dict,
                                         self.gui_signals, self.game_logger,
                                         version)
                mouse = MouseMoverTableBased(table_dict)
                mouse.move_mouse_away_from_buttons_jump()

                ready = table.take_screenshot(True, strategy) and \
                        table.get_top_left_corner(strategy) and \
                        table.check_for_captcha(mouse) and \
                        table.get_lost_everything(history, table, strategy, self.gui_signals) and \
                        table.check_for_imback(mouse) and \
                        table.get_my_cards(history) and \
                        table.get_new_hand(mouse, history, strategy) and \
                        table.get_table_cards(history) and \
                        table.upload_collusion_wrapper(strategy, history) and \
                        table.get_dealer_position() and \
                        table.check_fast_fold(history, strategy, mouse) and \
                        table.check_for_button() and \
                        table.get_round_number(history) and \
                        table.check_for_checkbutton() and \
                        table.init_get_other_players_info() and \
                        table.get_other_player_status(strategy, history) and \
                        table.get_other_player_names(strategy) and \
                        table.get_other_player_funds(strategy) and \
                        table.get_total_pot_value(history) and \
                        table.get_round_pot_value(history) and \
                        table.check_for_call() and \
                        table.check_for_betbutton() and \
                        table.check_for_allincall() and \
                        table.get_current_call_value(strategy) and \
                        table.get_current_bet_value(strategy)

            if not self.gui_signals.pause_thread:
                config = ConfigObj(CONFIG_FILENAME)
                m = run_montecarlo_wrapper(strategy, self.gui_signals, config,
                                           ui, table, self.game_logger,
                                           preflop_state, history)
                self.gui_signals.signal_progressbar_increase.emit(20)
                d = Decision(table, history, strategy, self.game_logger)
                d.make_decision(table, history, strategy, self.game_logger)
                self.gui_signals.signal_progressbar_increase.emit(10)
                if self.gui_signals.exit_thread: sys.exit()

                self.update_most_gui_items(preflop_state, strategy, m, table,
                                           d, history, self.gui_signals)

                log.info("Equity: " + str(table.equity * 100) + "% -> " +
                         str(int(table.assumedPlayers)) + " (" +
                         str(int(table.other_active_players)) + "-" +
                         str(int(table.playersAhead)) + "+1) Plr")
                log.info("Final Call Limit: " + str(d.finalCallLimit) +
                         " --> " + str(table.minCall))
                log.info("Final Bet Limit: " + str(d.finalBetLimit) + " --> " +
                         str(table.minBet))
                log.info("Pot size: " + str((table.totalPotValue)) +
                         " -> Zero EV Call: " + str(round(d.maxCallEV, 2)))
                log.info("+++++++++++++++++++++++ Decision: " +
                         str(d.decision) + "+++++++++++++++++++++++")

                mouse_target = d.decision
                if mouse_target == 'Call' and table.allInCallButton:
                    mouse_target = 'Call2'
                mouse.mouse_action(mouse_target, table.tlc)

                table.time_action_completed = datetime.datetime.utcnow()

                filename = str(history.GameID) + "_" + str(
                    table.gameStage) + "_" + str(history.round_number) + ".png"
                log.debug("Saving screenshot: " + filename)
                pil_image = table.crop_image(table.entireScreenPIL,
                                             table.tlc[0], table.tlc[1],
                                             table.tlc[0] + 950,
                                             table.tlc[1] + 650)
                pil_image.save("log/screenshots/" + filename)

                self.gui_signals.signal_status.emit("Logging data")

                t_log_db = threading.Thread(
                    name='t_log_db',
                    target=self.game_logger.write_log_file,
                    args=[strategy, history, table, d])
                t_log_db.daemon = True
                t_log_db.start()
                # self.game_logger.write_log_file(strategy, history, table, d)

                history.previousPot = table.totalPotValue
                history.histGameStage = table.gameStage
                history.histDecision = d.decision
                history.histEquity = table.equity
                history.histMinCall = table.minCall
                history.histMinBet = table.minBet
                history.hist_other_players = table.other_players
                history.first_raiser = table.first_raiser
                history.first_caller = table.first_caller
                history.previous_decision = d.decision
                history.lastRoundGameID = history.GameID
                history.previous_round_pot_value = table.round_pot_value
                history.last_round_bluff = False if table.currentBluff == 0 else True
                if table.gameStage == 'PreFlop':
                    preflop_state.update_values(table, d.decision, history, d)
                mongo.increment_plays(table_scraper_name)
                log.info("=========== round end ===========")
Exemplo n.º 30
0
    def run(self):
        h = History()
        preflop_url, preflop_url_backup = u.get_preflop_sheet_url()
        try:
            h.preflop_sheet = pd.read_excel(preflop_url, sheetname=None)
        except:
            h.preflop_sheet = pd.read_excel(preflop_url_backup, sheetname=None)

        self.game_logger.clean_database()

        p = StrategyHandler()
        p.read_strategy()

        preflop_state = CurrentHandPreflopState()

        while True:
            if self.gui_signals.pause_thread:
                while self.gui_signals.pause_thread == True:
                    time.sleep(1)
                    if self.gui_signals.exit_thread == True: sys.exit()

            ready = False
            while (not ready):
                p.read_strategy()
                t = TableScreenBased(p, gui_signals, self.game_logger, version)
                mouse = MouseMoverTableBased(p.selected_strategy['pokerSite'])
                mouse.move_mouse_away_from_buttons_jump

                ready = t.take_screenshot(True, p) and \
                        t.get_top_left_corner(p) and \
                        t.check_for_captcha(mouse) and \
                        t.get_lost_everything(h, t, p, gui_signals) and \
                        t.check_for_imback(mouse) and \
                        t.get_my_cards(h) and \
                        t.get_new_hand(mouse, h, p) and \
                        t.get_table_cards(h) and \
                        t.upload_collusion_wrapper(p, h) and \
                        t.get_dealer_position() and \
                        t.get_snowie_advice(p, h) and \
                        t.check_fast_fold(h, p, mouse) and \
                        t.check_for_button() and \
                        t.get_round_number(h) and \
                        t.init_get_other_players_info() and \
                        t.get_other_player_names(p) and \
                        t.get_other_player_funds(p) and \
                        t.get_other_player_pots() and \
                        t.get_total_pot_value(h) and \
                        t.get_round_pot_value(h) and \
                        t.check_for_checkbutton() and \
                        t.get_other_player_status(p, h) and \
                        t.check_for_call() and \
                        t.check_for_betbutton() and \
                        t.check_for_allincall() and \
                        t.get_current_call_value(p) and \
                        t.get_current_bet_value(p)

            if not self.gui_signals.pause_thread:
                config = ConfigObj("config.ini")
                m = run_montecarlo_wrapper(p, self.gui_signals, config, ui, t,
                                           self.game_logger, preflop_state, h)
                d = Decision(t, h, p, self.game_logger)
                d.make_decision(t, h, p, self.logger, self.game_logger)
                if self.gui_signals.exit_thread: sys.exit()

                self.update_most_gui_items(preflop_state, p, m, t, d, h,
                                           self.gui_signals)

                self.logger.info("Equity: " + str(t.equity * 100) + "% -> " +
                                 str(int(t.assumedPlayers)) + " (" +
                                 str(int(t.other_active_players)) + "-" +
                                 str(int(t.playersAhead)) + "+1) Plr")
                self.logger.info("Final Call Limit: " + str(d.finalCallLimit) +
                                 " --> " + str(t.minCall))
                self.logger.info("Final Bet Limit: " + str(d.finalBetLimit) +
                                 " --> " + str(t.minBet))
                self.logger.info("Pot size: " + str((t.totalPotValue)) +
                                 " -> Zero EV Call: " +
                                 str(round(d.maxCallEV, 2)))
                self.logger.info("+++++++++++++++++++++++ Decision: " +
                                 str(d.decision) + "+++++++++++++++++++++++")

                mouse_target = d.decision
                if mouse_target == 'Call' and t.allInCallButton:
                    mouse_target = 'Call2'
                mouse.mouse_action(mouse_target, t.tlc)

                t.time_action_completed = datetime.datetime.utcnow()

                filename = str(h.GameID) + "_" + str(t.gameStage) + "_" + str(
                    h.round_number) + ".png"
                self.logger.debug("Saving screenshot: " + filename)
                pil_image = t.crop_image(t.entireScreenPIL, t.tlc[0], t.tlc[1],
                                         t.tlc[0] + 950, t.tlc[1] + 650)
                pil_image.save("log/screenshots/" + filename)

                self.gui_signals.signal_status.emit("Logging data")

                t_log_db = threading.Thread(
                    name='t_log_db',
                    target=self.game_logger.write_log_file,
                    args=[p, h, t, d])
                t_log_db.daemon = True
                t_log_db.start()
                # self.game_logger.write_log_file(p, h, t, d)

                h.previousPot = t.totalPotValue
                h.histGameStage = t.gameStage
                h.histDecision = d.decision
                h.histEquity = t.equity
                h.histMinCall = t.minCall
                h.histMinBet = t.minBet
                h.hist_other_players = t.other_players
                h.first_raiser = t.first_raiser
                h.first_caller = t.first_caller
                h.previous_decision = d.decision
                h.lastRoundGameID = h.GameID
                h.previous_round_pot_value = t.round_pot_value
                h.last_round_bluff = False if t.currentBluff == 0 else True
                if t.gameStage == 'PreFlop':
                    preflop_state.update_values(t, d.decision, h, d)
                self.logger.info("=========== round end ===========")
Exemplo n.º 31
0
    def run(self):
        h = History()
        preflop_url, preflop_url_backup = u.get_preflop_sheet_url()
        try:
            h.preflop_sheet = pd.read_excel(preflop_url, sheetname=None)
        except:
            h.preflop_sheet = pd.read_excel(preflop_url_backup, sheetname=None)

        self.game_logger.clean_database()

        p = StrategyHandler()
        p.read_strategy()

        preflop_state = CurrentHandPreflopState()

        while True:
            if self.gui_signals.pause_thread:
                while self.gui_signals.pause_thread == True:
                    time.sleep(1)
                    if self.gui_signals.exit_thread == True: sys.exit()

            ready = False
            while (not ready):
                p.read_strategy()
                t = TableScreenBased(p, gui_signals, self.game_logger, version)
                mouse = MouseMoverTableBased(p.selected_strategy['pokerSite'])
                mouse.move_mouse_away_from_buttons_jump

                ready = t.take_screenshot(True, p) and \
                        t.get_top_left_corner(p) and \
                        t.check_for_captcha(mouse) and \
                        t.get_lost_everything(h, t, p, gui_signals) and \
                        t.check_for_imback(mouse) and \
                        t.get_my_cards(h) and \
                        t.get_new_hand(mouse, h, p) and \
                        t.get_table_cards(h) and \
                        t.upload_collusion_wrapper(p, h) and \
                        t.get_dealer_position() and \
                        t.get_snowie_advice(p, h) and \
                        t.check_fast_fold(h, p, mouse) and \
                        t.check_for_button() and \
                        t.get_round_number(h) and \
                        t.init_get_other_players_info() and \
                        t.get_other_player_names(p) and \
                        t.get_other_player_funds(p) and \
                        t.get_other_player_pots() and \
                        t.get_total_pot_value(h) and \
                        t.get_round_pot_value(h) and \
                        t.check_for_checkbutton() and \
                        t.get_other_player_status(p, h) and \
                        t.check_for_call() and \
                        t.check_for_betbutton() and \
                        t.check_for_allincall() and \
                        t.get_current_call_value(p) and \
                        t.get_current_bet_value(p)

            if not self.gui_signals.pause_thread:
                config = ConfigObj("config.ini")
                m = run_montecarlo_wrapper(p, self.gui_signals, config, ui, t, self.game_logger, preflop_state, h)
                d = Decision(t, h, p, self.game_logger)
                d.make_decision(t, h, p, self.logger, self.game_logger)
                if self.gui_signals.exit_thread: sys.exit()

                self.update_most_gui_items(preflop_state, p, m, t, d, h, self.gui_signals)

                self.logger.info(
                    "Equity: " + str(t.equity * 100) + "% -> " + str(int(t.assumedPlayers)) + " (" + str(
                        int(t.other_active_players)) + "-" + str(int(t.playersAhead)) + "+1) Plr")
                self.logger.info("Final Call Limit: " + str(d.finalCallLimit) + " --> " + str(t.minCall))
                self.logger.info("Final Bet Limit: " + str(d.finalBetLimit) + " --> " + str(t.minBet))
                self.logger.info(
                    "Pot size: " + str((t.totalPotValue)) + " -> Zero EV Call: " + str(round(d.maxCallEV, 2)))
                self.logger.info("+++++++++++++++++++++++ Decision: " + str(d.decision) + "+++++++++++++++++++++++")

                mouse_target = d.decision
                if mouse_target == 'Call' and t.allInCallButton:
                    mouse_target = 'Call2'
                mouse.mouse_action(mouse_target, t.tlc)

                t.time_action_completed = datetime.datetime.utcnow()

                filename = str(h.GameID) + "_" + str(t.gameStage) + "_" + str(h.round_number) + ".png"
                self.logger.debug("Saving screenshot: " + filename)
                pil_image = t.crop_image(t.entireScreenPIL, t.tlc[0], t.tlc[1], t.tlc[0] + 950, t.tlc[1] + 650)
                pil_image.save("log/screenshots/" + filename)

                self.gui_signals.signal_status.emit("Logging data")

                t_log_db = threading.Thread(name='t_log_db', target=self.game_logger.write_log_file, args=[p, h, t, d])
                t_log_db.daemon = True
                t_log_db.start()
                # self.game_logger.write_log_file(p, h, t, d)

                h.previousPot = t.totalPotValue
                h.histGameStage = t.gameStage
                h.histDecision = d.decision
                h.histEquity = t.equity
                h.histMinCall = t.minCall
                h.histMinBet = t.minBet
                h.hist_other_players = t.other_players
                h.first_raiser = t.first_raiser
                h.first_caller = t.first_caller
                h.previous_decision = d.decision
                h.lastRoundGameID = h.GameID
                h.previous_round_pot_value=t.round_pot_value
                h.last_round_bluff = False if t.currentBluff == 0 else True
                if t.gameStage == 'PreFlop':
                    preflop_state.update_values(t, d.decision, h, d)
                self.logger.info("=========== round end ===========")
Exemplo n.º 32
0
    def run(self):
        log = logging.getLogger(__name__)
        h = History()
        # preflop_url, preflop_url_backup = self.updater.get_preflop_sheet_url()
        preflop_url = os.path.join('tools', 'preflop.xlsx')
        try:
            h.preflop_sheet = pd.read_excel(preflop_url, sheet_name=None)
        except:
            h.preflop_sheet = pd.read_excel(preflop_url_backup,
                                            sheet_name=None)

        self.game_logger.clean_database()

        p = StrategyHandler()
        p.read_strategy()

        preflop_state = CurrentHandPreflopState()
        preflop_state_Zenith = CurrentHandPreflopStateZenith()
        mongo = MongoManager()
        table_scraper_name = None

        while True:
            # reload table if changed
            config = ConfigObj("config.ini")
            if table_scraper_name != config['DEFAULT']['table_scraper_name']:
                table_scraper_name = config['DEFAULT']['table_scraper_name']
                log.info(
                    f"Loading table scraper info for {table_scraper_name}")
                table_dict = mongo.get_table(table_scraper_name)

            if self.gui_signals.pause_thread:
                while self.gui_signals.pause_thread == True:
                    time.sleep(0.5)
                    if self.gui_signals.exit_thread == True: sys.exit()

            ready = False
            while (not ready):
                p.read_strategy()
                t = TableScreenBased(p, table_dict, self.gui_signals,
                                     self.game_logger, version)
                try:
                    time_start = datetime.datetime.utcnow()
                    # mouse = MouseMoverTableBased(table_dict)
                    # mouse.move_mouse_away_from_buttons_jump()
                    log.info(
                        "___________________________________________________")
                    ready = t.take_screenshot(True, p) and \
                            t.get_top_left_corner(p, self.gui_signals) and \
                            t.get_my_cards(h, is_debug) and \
                            t.get_table_cards(h) and \
                            t.upload_collusion_wrapper(p, h) and \
                            t.get_dealer_position() and \
                            t.check_for_button(is_debug) and \
                            t.get_round_number(h) and \
                            t.check_for_checkbutton() and \
                            t.init_get_other_players_info() and \
                            t.get_other_player_status(p, h) and \
                            t.get_my_funds(h, p) and \
                            t.get_other_player_funds(p) and \
                            t.get_other_player_pots() and \
                            t.get_total_pot_value(h) and \
                            t.get_round_pot_value(h) and \
                            t.check_for_call() and \
                            t.check_for_betbutton() and \
                            t.get_current_call_value(p) and \
                            t.get_current_bet_value(p) and \
                            t.get_new_hand2(h, p) and \
                            t.check_for_allincall()
                    # t.get_other_player_names(p) and \
                    # t.get_lost_everything(h, t, p, self.gui_signals) and \
                    # t.check_for_captcha(mouse) and \
                    # t.check_for_imback(mouse) and \
                    # t.get_new_hand(mouse, h, p) and \
                    # t.check_fast_fold(h, p, mouse) and \
                    # t.check_for_allincall() and \
                finally:
                    time_end = datetime.datetime.utcnow()
                    log.info(
                        "___________________________________________________")
                    log.info(f"time to total record: {time_end - time_start}")

            if not self.gui_signals.pause_thread:
                config = ConfigObj("config.ini")
                if not is_debug:
                    m = run_montecarlo_wrapper(p, self.gui_signals, config, ui,
                                               t, self.game_logger,
                                               preflop_state, h)
                    self.gui_signals.signal_progressbar_increase.emit(20)
                    d = Decision(t, h, p, self.game_logger)
                    d.make_decision(t, h, p, self.game_logger)
                    self.gui_signals.signal_progressbar_increase.emit(10)
                    if self.gui_signals.exit_thread: sys.exit()

                    self.update_most_gui_items(preflop_state, p, m, t, d, h,
                                               self.gui_signals)

                    log.info("Equity: " + str(t.equity * 100) + "% -> " +
                             str(int(t.assumedPlayers)) + " (" +
                             str(int(t.other_active_players)) + "-" +
                             str(int(t.playersAhead)) + "+1) Plr")
                    log.info("Final Call Limit: " + str(d.finalCallLimit) +
                             " --> " + str(t.minCall))
                    log.info("Final Bet Limit: " + str(d.finalBetLimit) +
                             " --> " + str(t.minBet))
                    log.info("Pot size: " + str((t.totalPotValue)) +
                             " -> Zero EV Call: " + str(round(d.maxCallEV, 2)))
                    # log.info("+++++++++++++++++++++++ Decision: " + str(d.decision) + "+++++++++++++++++++++++")

                    # mouse_target = d.decision
                    # if mouse_target == 'Call' and t.allInCallButton:
                    #     mouse_target = 'Call2'
                    # mouse.mouse_action(mouse_target, t.tlc)

                    t.time_action_completed = datetime.datetime.utcnow()

                    filename = str(h.GameID) + "_" + str(
                        t.gameStage) + "_" + str(h.round_number) + ".png"
                    log.debug("Saving screenshot: " + filename)
                    pil_image = t.crop_image(t.entireScreenPIL, t.tlc[0],
                                             t.tlc[1], t.tlc[0] + 950,
                                             t.tlc[1] + 650)
                    # pil_image.save("log/screenshots/" + filename)

                    self.gui_signals.signal_status.emit("Logging data")

                    t_log_db = threading.Thread(
                        name='t_log_db',
                        target=self.game_logger.write_log_file,
                        args=[p, h, t, d])
                    t_log_db.daemon = True
                    t_log_db.start()
                    # self.game_logger.write_log_file(p, h, t, d)

                    h.previousPot = t.totalPotValue
                    h.histGameStage = t.gameStage
                    # h.histDecision = d.decision
                    h.histEquity = t.equity
                    h.histMinCall = t.minCall
                    h.histMinBet = t.minBet
                    h.hist_other_players = t.other_players
                    h.first_raiser = t.first_raiser
                    h.first_caller = t.first_caller
                    # h.previous_decision = d.decision
                    h.lastRoundGameID = h.GameID
                    h.previous_round_pot_value = t.round_pot_value
                    # h.last_round_bluff = False if t.currentBluff == 0 else True
                if t.gameStage == 'PreFlop':
                    if not is_debug:
                        preflop_state.update_values(t, d.decision, h, d)
                    preflop_state_Zenith.get_players_status(t)
                log.info("=========== round end ===========")
                log.info(f"{h.GameID}")
                self.gui_signals.signal_hand_history.emit(h)