def get_stack(self, window, threshold=None, image=False): stack = window.crop(self.stack_box) if image: return stack if not threshold: threshold = self.ocr_threshold stack = graphics.recognize_digits(stack, threshold) return stack
def own_stack(window): stack_img = own_stack_image(window) # stack_img.show() stack = graphics.recognize_digits(stack_img) return stack return img
def pot(window): pot_img = pot_image(window) # pot_img.show() white = graphics.colour_ratio(pot_img, "White", w_thres=500) if white < 0.01: return pot = graphics.recognize_digits(pot_img) return pot
def get_actions(window, *args, **kwargs): if not is_my_turn(window): return Action("Fold", fast_fold(window)), Action("CC", None), Action("BR", None) fold_act = Action("Fold", True) cc_img, val_img = get_cc_images(window) if val_img: val = graphics.recognize_digits(val_img, 100, *args, **kwargs) print("Call val: %s" % val) cc_act = Action("Call", val) else: cc_act = Action("Check", None) br_img, val_img, type_img = get_br_images(window) val = graphics.recognize_digits(val_img, 100, *args, **kwargs) if len(graphics.split_characters(type_img)) < 4: br_act = Action("Bet", val) else: br_act = Action("Raise", val) return fold_act, cc_act, br_act
def get_bet(self, window, threshold=None, image=False): bet = window.crop(self.bet_box) # if image: return bet if not threshold: threshold = self.ocr_threshold bet_np = graphics.pil_to_np(bet) white = graphics.colour_ratio(bet_np, "White") if white < 0.01: return None else: ## THIS PART IS BUGGED AS F**K, but seems to work for now ## No idea yet how to detect green poker chips to crop the image. for i in range(bet_np.shape[1] // 2, bet_np.shape[1]): col = bet_np[:, i:i + 1] max_red_ratio = graphics.max_colour_ratio(col, "Red") max_green_ratio = graphics.max_colour_ratio(col, "Red") # green?!?! if max_red_ratio > 0.5: # print("Max red ratio in each pixel in column %d is: %.3f" % (i, max_red_ratio)) bet = bet.crop((0, 0, i, bet.height)) break if max_green_ratio > 0.334: # print("Max green ratio in column %d is: %.3f" % (i, max_green_ratio)) bet = bet.crop((0, 0, i - 1, bet.height)) break for i in range(bet_np.shape[1] // 2, -1, -1): col = bet_np[:, i:i + 1] max_red_ratio = graphics.max_colour_ratio(col, "Red") max_green_ratio = graphics.max_colour_ratio(col, "Red") # green?!?! if max_red_ratio > 0.5: # print("Max red ratio in each pixel in colum %d is : %.3f" % (i, max_red_ratio)) bet = bet.crop((i + 1, 0, bet.width, bet.height)) break if max_green_ratio > 0.334: # print("Max green ratio in column %d is: %.3f" % (i, max_green_ratio)) bet = bet.crop((i - 1, 0, bet.width, bet.height)) break # bet.show() if image: return bet bet = graphics.recognize_digits(bet, threshold) return bet
def create_image_with_info(): threshold = 115 font_size = 17 # window = game_window() window = game_window(path="images/game/s7.png") window.show() pot = money.pot_image(window) if graphics.colour_ratio(pot, "White") >= 0.01: pot = graphics.recognize_digits(pot, threshold) else: pot = "NO POT!" draw = PIL.ImageDraw.Draw(window) font = PIL.ImageFont.truetype("font.ttf", font_size) draw.text((330, 270), "POT SIZE: %s" % pot, (255, 0, 0), font=font) del draw own_stack = money.own_stack_image(window) own_stack = graphics.recognize_digits(own_stack, threshold) draw = PIL.ImageDraw.Draw(window) font = PIL.ImageFont.truetype("font.ttf", font_size) draw.text((330, 435), "MY STACK: %s" % own_stack, (255, 0, 0), font=font) del draw seat = dealer.find_dealer_seat(window) loc = dealer.DEALER_OFFSETS[seat] loc = (loc[0] - 60, loc[1] + 20) draw = PIL.ImageDraw.Draw(window) font = PIL.ImageFont.truetype("font.ttf", font_size) draw.text(loc, "DEALER HERE (player %d)!" % (seat + 1), (255, 0, 0), font=font) del draw for j in range(5): p = players.Player(j) if p.is_in_game(window): text = "PLAYER IS ACTIVE" else: text = "PLAYER INACTIVE" draw = PIL.ImageDraw.Draw(window) font = PIL.ImageFont.truetype("font.ttf", font_size) loc = (p.card_box.left - 20, p.card_box.top - 20) draw.text(loc, text, (255, 0, 0), font=font) del draw stack = window.crop(p.stack_box) stack = graphics.recognize_digits(stack, threshold) draw = PIL.ImageDraw.Draw(window) font = PIL.ImageFont.truetype("font.ttf", font_size) loc = (p.stack_box.left - 20, p.stack_box.top + 20) draw.text(loc, "STACK: %s" % stack, (255, 0, 0), font=font) del draw bet = window.crop(p.bet_box) bet_np = graphics.pil_to_np(bet) white = graphics.colour_ratio(bet_np, "White") if white < 0.01: text = "NO BETS HERE!" else: for i in range(bet_np.shape[1] // 2, bet_np.shape[1]): col = bet_np[:, i:i + 1] max_red_ratio = graphics.max_colour_ratio(col, "Red") max_green_ratio = graphics.max_colour_ratio(col, "Red") if max_red_ratio > 0.5: print("Max red ratio in each pixel in column %d is: %.3f" % (i, max_red_ratio)) bet = bet.crop((0, 0, i, bet.height)) break if max_green_ratio > 0.334: print("Max green ratio in column %d is: %.3f" % (i, max_green_ratio)) bet = bet.crop((0, 0, i - 1, bet.height)) break for i in range(bet_np.shape[1] // 2, -1, -1): col = bet_np[:, i:i + 1] max_red_ratio = graphics.max_colour_ratio(col, "Red") if max_red_ratio > 0.5: print("Max red ratio in each pixel in colum %d is : %.3f" % (i, max_red_ratio)) bet = bet.crop((i + 1, 0, bet.width, bet.height)) break text = "PLACED A BET: %s" % graphics.recognize_digits( bet, threshold) draw = PIL.ImageDraw.Draw(window) font = PIL.ImageFont.truetype("font.ttf", font_size) loc = (p.bet_box.left - 40, p.bet_box.top - 20 + (int(j == 2) * 40)) draw.text(loc, text, (255, 0, 0), font=font) # my_card = cards. window.show()