简体   繁体   English

pyatuo gui Piano Tiles 机器人问题

[英]pyatuo gui Piano Tiles bot issues

Here is some code I wrote for a piano tiles bot using pyauto gui.这是我使用 pyauto gui 为 piano tiles 机器人编写的一些代码。 I would like it to simply beat the game automatically.我希望它能自动击败游戏。 Some relevant information: I have double checked all of the pixels that the bot will check to see if the color is black.一些相关信息:我已经仔细检查了机器人将检查颜色是否为黑色的所有像素。 I do this with the following: pyautogui.pixel(1196,650)[0] == 43. The main issue here is that when I run the program with the piano tiles app open and it will just click the first tile and then click the same square again and lose the game.我使用以下方法执行此操作:pyautogui.pixel(1196,650)[0] == 43。这里的主要问题是,当我在打开钢琴块应用程序的情况下运行程序时,它只会单击第一个块,然后单击同一个方块再次输掉比赛。 I also cannot quit the program by pressing q which i dont understand why.我也不能通过按 q 退出程序,我不明白为什么。 I am running this all on my macbook pro and I am new to programming so any advice helps!我在我的 macbook pro 上运行这一切,我是编程新手,所以任何建议都有帮助! The piano tiles website I have been using is http://tanksw.com/piano-tiles/ .我一直使用的 piano tiles 网站是http://tanksw.com/piano-tiles/ Thanks in advance!提前致谢!

import time
import keyboard
import random

#Tile 1 position: x=1196 y=650
#Tile 2 position: x=1301 y=650
#Tile 3 position: x=1386 y=650
#Tile 4 position: x=1507 y=650

# while True:q
#     print(pyautogui.position())
#     time.sleep(1)

def click(x,y):
    pyautogui.position(x,y)
    pyautogui.click()
    time.sleep(.01)

while keyboard.is_pressed("q") == False:

    while True:
        pyautogui.moveTo(1196,650)
        if pyautogui.pixel(1196,650)[0] == 43:
            click(1196,650)
        elif pyautogui.moveTo(1301,650):
            if pyautogui.pixel(1301, 650)[0] == 43:
                click(1301, 650)
        elif pyautogui.moveTo(1386,650):
            if pyautogui.pixel(1386, 650)[0] == 43:
                    click(1386, 650)
        elif pyautogui.moveTo(1507,650):
            if pyautogui.pixel(1507, 650)[0] == 43:
                    click(1507, 650)```

To fix the KeyBoard issue, change it to要解决键盘问题,请将其更改为

while True:
    pyautogui.moveTo(1196,650)
    if pyautogui.pixel(1196,650)[0] == 43:
        click(1196,650)
    elif pyautogui.moveTo(1301,650):
        if pyautogui.pixel(1301, 650)[0] == 43:
            click(1301, 650)
    elif pyautogui.moveTo(1386,650):
        if pyautogui.pixel(1386, 650)[0] == 43:
                click(1386, 650)
    elif pyautogui.moveTo(1507,650):
        if pyautogui.pixel(1507, 650)[0] == 43:
                click(1507, 650)

Edit:编辑:

    if (keyboard.is_pressed("q")):
        break

For the other issue, try adding a longer delay, this would be added because the blocks don't just disappear, the slide down the grid, therefor the color won't change for a little bit.对于另一个问题,尝试添加更长的延迟,这是因为块不会消失,滑下网格,因此颜色不会改变一点点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM