Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

not able to find items on specific screen area

I’m new to python and I wonder whether it is possible to capture objects on SPECIFIC screen area. I’m trying to make a poker odds calculator that automatically checks the cards and provides you with the information on your chances of winning (like on this website https://www.cardschat.com/poker/tools/poker-odds-calculator/ ). I wrote a code that checks whether there is king of hearts or ace of hearts in your hand, and if so, then in case of Ace of hearts it changes my cards (in the script) to ace of hearts and ace of diamonds. Similar situation in case of kings. So the task is to check BOTH my cards and set them in variables card_one and card_two, then calculate the chance of winning, then check the flop (first three cards on the table and add them to variables (you will need to change "2h", "qh", "4h", "10c", "6c" to variables)) and calculate the chances of winning, then the fourth card and calculations and the fifth card and calculations and wait for new cards and do the same tasks. I honestly have no idea how to capture objects from specific area, it just captures all the objects on the screen.
Here’s the code:

import pied_poker as pp
import numpy as np
import pyautogui
import time
np.random.seed(420)
def find_item_on_screen(card_image, card_one, card_two, card_type) -> bool:
    try:
        pyautogui.locateOnScreen(card_image, confidence=0.9)
        print(f"{card_type}!")
        p1 = pp.Player('Artur', pp.Card.of(card_one, card_two))
        p2 = pp.Player('Opponent', pp.Card.of()) 
        community_cards = pp.Card.of("2h", "qh", "4h", "10c", "6c")
        print(p1)
        print(f'Community cards: {community_cards}')
        simulator = pp.PokerRound.PokerRoundSimulator(community_cards=community_cards, players=[p1, p2], total_players=2)
        num_simulations = 10000
        simulation_result=simulator.simulate(n=num_simulations, n_jobs=1)
        print(simulation_result.probability_of(pp.Probability.PlayerWins(p1)))
        return True
    except pyautogui.ImageNotFoundException:
        print(f"No {card_type}")
        return False

def check_king():
    locate_item = 'KH.png'
    card_one = "kh"
    card_two = "kd"
    card_type = 'KING'
    find_item_on_screen(locate_item, card_one, card_two, card_type)    

def check_aces(): 
    locate_item = 'AH.png'
    card_one = "ah"
    card_two = "ad"
    card_type = 'ACES'
    find_item_on_screen(locate_item, card_one, card_two, card_type)

check_king() 
check_aces()

looked for the same projects on the internet, there weren’t ones

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use the region parameter.

pyautogui.locateOnScreen(card_image, confidence=0.9)
# whole screen

pyautogui.locateOnScreen(card_image, confidence=0.9, region = (left,top,width,height)
# only the part in the region
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading