def test_preflop_state1(self): strategy = 'snowie1' # preflop t, p, gui_signals, h, logger = init_table('tests/screenshots/76s.png', strategy=strategy) p = StrategyHandler() p.read_strategy(strategy) l = MagicMock() t.totalPotValue = 0.5 t.equity = 0.5 t.checkButton = False d = Decision(t, h, p, l) t.isHeadsUp = True t.gameStage = "PreFlop" d.__init__(t, h, p, l) d.preflop_override(t, logger, 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, gui_signals, h, logger = init_table('tests/screenshots/76ss.png', strategy=strategy) 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)
def init_table(file, round_number=0, strategy='Pokemon4'): LOG_FILENAME = 'testing.log' logger = logging.getLogger('tester') gui_signals = MagicMock() p = StrategyHandler() p.read_strategy(strategy_override=strategy) h = main.History() h.preflop_sheet = pd.read_excel('decisionmaker/preflop.xlsx', sheetname=None) game_logger = GameLogger() t = main.TableScreenBased(p, gui_signals, game_logger, 0.0) t.entireScreenPIL = Image.open(file) t.get_top_left_corner(p) t.get_dealer_position() t.get_my_funds(h, p) t.get_my_cards(h) t.get_table_cards(h) t.get_round_number(h) h.round_number = round_number t.init_get_other_players_info() t.get_other_player_names(p) t.get_other_player_funds(p) t.get_other_player_pots() t.get_other_player_status(p, h) t.check_for_checkbutton() t.check_for_call() t.check_for_betbutton() t.check_for_allincall() t.get_current_call_value(p) t.get_current_bet_value(p) p = MagicMock() gui_signals = MagicMock() return t, p, gui_signals, h, logger
def test_preflop_fullhouse_river_round2(self): strategy = 'pp_nickpick_supersonic2' # preflop t, p, gui_signals, h, logger = init_table( 'tests/screenshots/1791526_PreFlop_0.png', strategy=strategy) p = StrategyHandler() p.read_strategy(strategy) l = MagicMock() t.totalPotValue = 0.5 t.equity = 0.5 t.checkButton = False d = Decision(t, h, p, l) t.isHeadsUp = True t.gameStage = "PreFlop" d.__init__(t, h, p, l) d.preflop_override(t, logger, h, p) preflop_state = CurrentHandPreflopState() bot_preflop_decision = 'Call' preflop_state.update_values(t, bot_preflop_decision, h) # river round 2 t, p, gui_signals, h, logger = init_table( 'tests/screenshots/1791526_River_1.png', strategy=strategy) for abs_pos in range(5): if t.other_players[abs_pos]['status'] == 1: sheet_name = preflop_state.get_reverse_sheetname(abs_pos, t) self.assertEqual('12R4C5', sheet_name)
def test_preflop_state1(self): strategy = 'snowie1' # preflop t, p, gui_signals, h, logger = init_table('tests/screenshots/76s.png', strategy=strategy) p = StrategyHandler() p.read_strategy(strategy) l = MagicMock() t.totalPotValue = 0.5 t.equity = 0.5 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) 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, gui_signals, h, logger = init_table('tests/screenshots/76ss.png', strategy=strategy) 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)
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)
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)
def test_preflop_round2_2(self): t, p, gui_signals, h, logger = init_table( 'tests/screenshots/107232845_PreFlop_1.png', round_number=1) p = StrategyHandler() p.read_strategy('Pokemon4') l = MagicMock() t.totalPotValue = 0.5 t.equity = 0.5 t.checkButton = False d = Decision(t, h, p, l) t.isHeadsUp = True t.gameStage = "PreFlop" d.__init__(t, h, p, l) d.preflop_override(t, logger, h, p) self.assertEqual(t.first_raiser_utg, 4)
def __init__(self, write_update, L): self.logger = logging.getLogger('genetic_algo') self.logger.setLevel(logging.DEBUG) self.output = '' p = StrategyHandler() p.read_strategy() p_name = p.current_strategy self.logger.debug("Strategy to analyse: " + p_name) self.load_log(p_name, L) self.improve_strategy(L, p) if (self.modified and write_update == True) or write_update == "Force": p.save_strategy_genetic_algorithm() config = ConfigObj("config.ini") config['last_strategy'] = p.current_strategy config.write() self.logger.info("Genetic algorithm: New strategy saved")
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')
def init_table(file,round_number=0, strategy='vid_ps_2'): LOG_FILENAME = 'testing.log' logger = logging.getLogger('tester') gui_signals = MagicMock() p = StrategyHandler() p.read_strategy(strategy_override=strategy) h = main.History() u = UpdateChecker() cursor = u.mongodb.internal.find() c = cursor.next() preflop_url = c['preflop_url'] h.preflop_sheet = pd.read_excel(preflop_url, sheetname=None) game_logger = GameLogger() mouse = MouseMoverTableBased(p.selected_strategy['pokerSite']) t = main.TableScreenBased(p,gui_signals,game_logger,0.0) t.entireScreenPIL = Image.open(file) t.get_top_left_corner(p) t.get_dealer_position() t.get_my_funds(h,p) t.get_my_cards(h) t.get_table_cards(h) t.get_round_number(h) h.round_number=round_number t.init_get_other_players_info() t.get_other_player_names(p) t.get_other_player_funds(p) t.get_other_player_pots() t.get_other_player_status(p,h) t.check_for_checkbutton() t.check_for_call() t.check_for_betbutton() t.check_for_allincall() t.get_current_call_value(p) t.get_current_bet_value(p) t.check_fast_fold(h, p, mouse) p = MagicMock() gui_signals = MagicMock() t.get_round_pot_value(h) t.get_bot_pot(p) t.check_for_button() t.get_lost_everything(h, t, p, gui_signals) t.get_total_pot_value(h) #t.totalPotValue = 0.5 #t.abs_equity = 0.5 #t.equity = 0.5 return t,p,gui_signals,h,logger
def init_table(file,round_number=0, strategy='Pokemon4'): LOG_FILENAME = 'testing.log' logger = logging.getLogger('tester') gui_signals = MagicMock() p = StrategyHandler() p.read_strategy(strategy_override=strategy) h = main.History() u = UpdateChecker() cursor = u.mongodb.internal.find() c = cursor.next() preflop_url = c['preflop_url'] h.preflop_sheet = pd.read_excel(preflop_url, sheetname=None) game_logger = GameLogger() t = main.TableScreenBased(p,gui_signals,game_logger,0.0) t.entireScreenPIL = Image.open(file) t.get_top_left_corner(p) t.get_dealer_position() t.get_my_funds(h,p) t.get_my_cards(h) t.get_table_cards(h) t.get_round_number(h) h.round_number=round_number t.init_get_other_players_info() t.get_other_player_names(p) t.get_other_player_funds(p) t.get_other_player_pots() t.get_other_player_status(p,h) t.check_for_checkbutton() t.check_for_call() t.check_for_betbutton() t.check_for_allincall() t.get_current_call_value(p) t.get_current_bet_value(p) p = MagicMock() gui_signals = MagicMock() t.totalPotValue = 0.5 t.equity = 0.5 return t,p,gui_signals,h,logger
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)
from testing.test_engine import init_table from decisionmaker.current_hand_memory import History, CurrentHandPreflopState from gui.gui_qt_ui import Ui_Pokerbot from decisionmaker.montecarlo_python import run_montecarlo_wrapper #t, p, gui_signals, h, logger = init_table('testing/screenshots/751235173_PreFlop_0.png') #t, p, gui_signals, h, logger = init_table('testing/screenshots/ps_7.png') t, p, gui_signals, h, logger = init_table('testing/screenshots_ps_real_money/269141380_Flop_0.png', strategy='vid_ps_3_real_money') #t, p, gui_signals, h, logger = init_table('pics/old/error.png') p = StrategyHandler() #p.current_strategy = 'pokemon' p.current_strategy = 'vid_ps_2' p.read_strategy('vid_ps_2') #p.read_strategy('pokemon') mouse = MouseMoverTableBased(p.selected_strategy['pokerSite']) p.selected_strategy['gather_player_names'] = 1 h.game_number_on_screen = '1' ready = 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_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 \
def run(self): #pdb.set_trace() #To debug in a thread, has to use set_trace() h = History() #preflop_url = u.get_preflop_sheet_url() #KevinY preflop_url = 'preflop.xlsx' h.preflop_sheet = pd.read_excel(preflop_url, sheetname=None) self.game_logger.clean_database() p = StrategyHandler() p.read_strategy() preflop_state = CurrentHandPreflopState() p.fast_fold_decision_turned_check = False 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 #pdb.set_trace() ready_screenshot = False ready_screenshot = t.take_screenshot(True, p) # to see if first round, to improve speed if (not hasattr(h, 'round_number') or h.round_number == 0): ready = ready_screenshot and \ t.get_top_left_corner(p) and \ t.check_for_imback(mouse) and \ t.get_other_player_names(p,h) and \ t.get_my_cards(h) and \ t.get_dealer_position() and \ t.get_round_number(h) and \ t.check_fast_fold(h, p, mouse) ready = ready_screenshot and \ t.get_new_hand(mouse, h, p) and \ t.get_table_cards(h) and \ t.upload_collusion_wrapper(p, h) and \ t.check_for_button() and \ t.get_round_number(h) and \ t.init_get_other_players_info() 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 p.fast_fold_decision_turned_check == True: self.logger.info("Fast fold decision turned check") mouse_target = 'Check' p.fast_fold_decision_turned_check = False 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 * 2, t.tlc[1] + 650 * 2) 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 ===========")
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 ===========")
def run(self): log = logging.getLogger(__name__) h = History() preflop_url, preflop_url_backup = self.updater.get_preflop_sheet_url() 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() mongo = MongoManager() table_scraper_name = None #while True: for i in range(1): # reload table if changed config = ConfigObj("config.ini") ready = False fast_fold = False while (not ready): p.read_strategy() t = TableScreenBased(p, self.game_logger, version) ready = t.load_table() and \ t.get_lost_everything(h, t, p) and \ t.get_new_hand(h, p) and \ t.get_table_cards() and \ t.get_dealer_position() if ready and (not t.check_fast_fold(h)): fast_fold = True break ready = ready and\ t.check_for_button() and \ t.get_round_number(h) and \ t.init_get_other_players_info() and \ t.get_other_player_status(p, h) 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() and \ t.get_round_pot_value() and \ t.get_current_call_value() and \ t.get_current_bet_value() config = ConfigObj("config.ini") if not fast_fold: m = run_montecarlo_wrapper(p, config, t, self.game_logger, preflop_state, h) d = Decision(t, h, p, self.game_logger) d.make_decision(t, h, p, self.game_logger) decision = d.decision 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))) 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() 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) log.info("=========== round end ===========") else: decision = DecisionTypes.fold log.info("+++++++++++++++++++++++ Decision: " + str(decision) + "+++++++++++++++++++++++")