Random move

Asked by Antonín Ušelík

Hello, I have a problem with code....

I make a farm bot for a game... and Im trying to make it little bit more random.
and my random move doesnt work... Its get stuck and doesnt move with screen
Can you help me please where I make a misstake?

Thanks for answer
this is my codeimport random
Settings.MouseMoveDelay=0.25
Z1 = Region(270,285,1235,544)
Z2 = Region(478,417,423,376)
Z3 = Region(195,219,1309,611)
for z in range (10):
    for x in range (1000 ) :
        rndtime = random.randrange(0,1000)
        rndtime = rndtime/1000
        if exists(Pattern("smrt.png").similar(0.90)):
            click(Pattern("smrt.png").similar(0.90).targetOffset(-40,41),2)
            click(Pattern("oprava.png").similar(0.90),2)
            click("pomoc.png",2)
            click("speedup.png",2)
            while exists(Pattern("opravaspeedup.png"),2):
                    click(Pattern("opravaspeedup.png").similar(0.80).targetOffset(-225,-53),2)
                    wait(1+rndtime)
            click(Pattern("oprava finish.png").similar(0.90).targetOffset(311,11),2)
            wait(1+rndtime)
            click(Pattern("poslat.png").similar(0.90).targetOffset(-18,-132),5)
            click(Pattern("go.png").similar(0.90),5)
            wait(Pattern("přílet.png").similar(0.90),3600)
            z=z+1
        else:
            wait(0.1+rndtime)
        if Z1.exists(Pattern("wing-1.png").similar(0.90)):
            Z1.click(Pattern("wing-3.png").similar(0.90).targetOffset(-102,-3))
            if exists("attack-1.png",2):
                click(Pattern("attack-2.png").targetOffset(99,8),2)
                wait(1+rndtime)
                wait("battle.png", 55)
                wait(6+rndtime)
                x=x+1
            else:
                wait(3+rndtime)
                type(Key.ESC)
                wait(1+rndtime)
                if exists("noyes.png",2):
                    click("no.png")
                    w = int(Z2.w * random.random())
                    h = int(Z2.h * random.random())
                    Z2.click(Location(w + Z2.x,h + Z2.y))
                else:
                    wait(0.25+rndtime)
        else:
            wd = int(Z3.w * random.random())
            hd = int(Z3.h * random.random())
            wu = int(Z3.w * random.random())
            hu = int(Z3.w * random.random())
            Z3.mouseMove(Location(wd + Z3.x,hd + Z3.y))
            mouseDown(Button.LEFT)
            wait(0.5)
            Z3.mouseMove(Location(wu + Z3.x,hu + Z3.y))
            mouseUp(Button.LEFT)

 Thanks for help

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Antonín Ušelík
Solved:
Last query:
Last reply:
Revision history for this message
Manfred Hampl (m-hampl) said :
#1

Without looking into details of your click and wait logic:

Modifying the counter of a "for ... in range()" loop (in your case x and z) inside the loop is nonsense.

Are you sure that your definition of rndtime makes sense?
In Python 2.7 "/" is integer division, so I assume that the value always will be zero.

Revision history for this message
Antonín Ušelík (darthharold) said :
#2

hello, I figured out... thanks for info with rndtime I dont know it... this is code how I change it...

import random
Settings.MouseMoveDelay=0.25
Z1 = Region(270,285,1235,544)
for z in range (10):
    for x in range (1000 ) :
        if exists(Pattern("smrt.png").similar(0.90)):
            click(Pattern("smrt.png").similar(0.90).targetOffset(-40,41),2)
            click(Pattern("oprava.png").similar(0.90),2)
            click("pomoc.png",2)
            click("speedup.png",2)
            while exists(Pattern("opravaspeedup.png"),2):
                    click(Pattern("opravaspeedup.png").similar(0.80).targetOffset(-225,-53),2)
                    wait(1+rndtime)
            click(Pattern("oprava finish.png").similar(0.90).targetOffset(311,11),2)
            wait(1 + random.random())
            click(Pattern("poslat.png").similar(0.90).targetOffset(-18,-132),5)
            click(Pattern("go.png").similar(0.90),5)
            wait(Pattern("přílet.png").similar(0.90),3600)
            z=z+1
        else:
            wait(0.1 + random.random())
        if Z1.exists(Pattern("wing-1.png").similar(0.90)):
            Z1.click(Pattern("wing-3.png").similar(0.90).targetOffset(-102,-3))
            if exists("attack-1.png",2):
                click(Pattern("attack-2.png").targetOffset(99,8),2)
                wait(1 + random.random())
                wait("battle.png", 55)
                wait(6 + random.random())
                x=x+1
            else:
                wait(3 + random.random())
                type(Key.ESC)
                wait(1 + random.random())
                if exists("noyes.png",2):
                    click("no.png")
                    Z2 = Region(631,494,195,215)
                    w = int(Z2.w * random.random())
                    h = int(Z2.h * random.random())
                    Z2.click(Location(w + Z2.x,h + Z2.y))
                else:
                    wait(0.25 + random.random())
        else:
            Z3 = Region(195,219,1309,611)
            wd = int(Z3.w * random.random())
            hd = int(Z3.h * random.random())
            wu = int(Z3.w * random.random())
            hu = int(Z3.h * random.random())
            dragDrop(Location(wd+Z3.x,hd+Z3.y),Location(wu+Z3.x,hu+Z3.y))