P
P
PosikGG2021-06-09 23:13:46
Python
PosikGG, 2021-06-09 23:13:46

Why does the algorithm always output D?

This code compares screenshots from the game.
The whole point is that the game has a simulator in which you need to press the keys that are highlighted in red on the plate.
When comparing, the code always produces "D".
Why?

from PIL import ImageGrab
from PIL import Image, ImageChops
import time

rage=True

while rage:
    time.sleep(5)
    box1=(1049,884,1253,1016)
    ImageGrab.grab(box1).save('box1.png') 
    image_1=Image.open('box1.png')
    image_2=Image.open('q.png')
    image_3=Image.open('w.png')
    image_4=Image.open('e.png')
    image_5=Image.open('a.png')
    image_6=Image.open('s.png')
    
    result=ImageChops.difference(image_1, image_2).getbbox()

    if result==None:
        print("Q")
    else:
        result=ImageChops.difference(image_1, image_3).getbbox()
        if result==None:
            print("W")
        else:
            result=ImageChops.difference(image_1, image_4).getbbox()
            if result==None:
                print("E")
            else:
                result=ImageChops.difference(image_1, image_5).getbbox()
                if result==None:
                    print("A")
                else:
                    result=ImageChops.difference(image_1, image_6).getbbox()
                    if result==None:
                        print("S")
                    else:
                        print("D")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2021-06-09
@twistfire92

apparently because result never evaluates to None

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question