def __init__( self, window ): self.window = window self.windowRect = win32gui.GetWindowRect( window ) win32gui.SetForegroundWindow( window ) rect = win32gui.GetClientRect( window ) self.upper_left = win32gui.ClientToScreen( window, (rect[0], rect[1])) self.lower_right = win32gui.ClientToScreen( window, (rect[2], rect[3])) self.rect = self.upper_left + self.lower_right self.x, self.y = self.upper_left self.table = Table( self ) self.bet = 0 from strategy.default import DefaultStrategy self.strategy = DefaultStrategy( self )
class PokerBot( object ): def __init__( self, window ): self.window = window self.windowRect = win32gui.GetWindowRect( window ) win32gui.SetForegroundWindow( window ) rect = win32gui.GetClientRect( window ) self.upper_left = win32gui.ClientToScreen( window, (rect[0], rect[1])) self.lower_right = win32gui.ClientToScreen( window, (rect[2], rect[3])) self.rect = self.upper_left + self.lower_right self.x, self.y = self.upper_left self.table = Table( self ) self.bet = 0 from strategy.default import DefaultStrategy self.strategy = DefaultStrategy( self ) def start( self ): while True: self.readState() time.sleep( .5 ) def readState( self ): self.frame = Utils.screenshot( self.rect ) self.table.read() if self.table.isModified: logging.debug( 'Table: %s', self.table ) print "" print "+------" print "| %s" % self.table.state_name print "+--" print "| STACK: %s, POT: %s" % ( self.table.amount, self.table.pot ) if len( self.table.cards ): print "| CARDS: %s" % ', '.join( [ ''.join( c ) for c in self.table.cards ] ) if len( self.table.my_cards ) and self.table.my_cards[0] and self.table.my_cards[1]: print "| HAND : %s" % ', '.join( [ ''.join( c ) for c in self.table.my_cards ] ) if self.table.isNowMe: decision = self.strategy.make_decision() # TODO call_value = ( Utils.parse_float( self.table.call_value ) if self.table.call_action == 'call' else .04 ) or .04 print "+-" if decision == 2: print "| RAISE" self.bet += call_value self._raise() elif self.table.call_action == 'wait': print "| WAIT" self._call() else: if decision == 1: print "| CALL" self.bet += call_value self._call() else: print "| FOLD" self._fold() print "+---" def _fold( self ): self.click( self.table.BUTTON_FOLD_ATTR[1] ) def _call( self ): self.click( self.table.BUTTON_CALL_ATTR[1] ) def _raise( self ): if 3 in self.table.buttons: self.click( self.table.BUTTON_RAISE_ATTR[1] ) else: self._call() def click( self, cord ): Utils.mouse_click( cord[0] + self.x, cord[1] + self.y ) Utils.mouse_move( self.x, self.y ) def __cursorPos( self ): x, y = win32api.GetCursorPos() return ( x - self.x, y - self.y )