Jump to content

Recommended Posts

hmm...functions are bad huh? i am only using 2 fuctions in the search process and they are both used at every (x,y) location. their inputs are all variables ($x,$y) both are pretty small variables only 3 digits per var.

Err, no. Functions are good, functions are your friend, functions make things clear. Just that they require a little bit of time to do their work. :angry:

Saying that I don't think that this is your problem. As I said, its the basic algorithm.

Looking at you code - Chickens, Feathers - what makes me think that this is to do with a game? B)

First, some immeditate answers. If JdeB's fix doesn't work also add

Global $WAITCOUNT

at the beginning of the program

Second line 26 & 35 should be

MouseClick("left",$X,$Y, 1, 0)

Third lines 88 & 103 should be

MouseMove($X,$Y,0)

All of the above might shave a few milliseconds off the time, so on to the algorithm. I'm going to illustrate what I think you are doing. I'm going to simplify things by forgetting the feather checking and wait processing for a moment. I'm also going to forget about the step 10, and use step 1 instead. Just multiply every number in my example by 10 to get your actual pixel coordinates

Consider that the area that we are searching looks like this, where a "." denotes no chicken, and the "*" denotes the chicken

_ 0 1 2 3 4 5 6 7 8
0 . . . . . . . . . 
1 . . . . . . . . . 
2 . . . . . . . . . 
3 . . . . . . . . . 
4 . . . . * . . . . 
5 . . . . . . . . . 
6 . . . . . . . . . 
7 . . . . . . . . . 
8 . . . . . . . . . 
9 . . . . . . . . .

OK, what happens is we check (0,0), (0,1), ..., (4,3) all without success. Next we check (4,4) - bingo! We do the mouseclick and go to sleep for 4.1 seconds. When we wake up we check (4,5), then (4,6), ..., (8,9) before starting checking (0,0), (0,1), etc.

Is this what you intend? Notice that during the sleep period after clickin' the chickin then you aren't searching for the feather. Is this OK?

Notice also once we have found the chicken at (4,4) and woken up from our sleep then we immediately check for a feather at (4,4). Is this sensible?

Finally, from the code snippet posted, then after the first ten cycles you always process the ";stuff in here is kinda long/messy, i took it out" at every pixel! Is this what you want?

Over to you :whistle:

GrahamS

Link to post
Share on other sites

JdeB:

You could, for testings purpose, put a MsgBox(4092,'debug', '$WAITCOUNT:' & $WAITCOUNT) statement after line 127... just to see if the F2 works....

ya, that was going to be my next step. Perhaps the F2 does work but somewhere in my code the $WAITCOUNT gets reset before it enters the WAITCOUNT loop.

ill try your idea and let ya know what happens.

GrahamS:

once again, thanks for the detailed response!

Hmm...Where to start...

Looking at you code - Chickens, Feathers - what makes me think that this is to do with a game? 

heh, ya... you got me. but before you jump to any conclusions let me explain my MASTER plan:

Plan:

i wanted to create a 'bot' that would pretty much stay online 24/7. I am not doing this to get a edge in playing the game but to test/have fun with my coding skills. I am very much a visual thinker and if I can 'see' my code does stuff I actually enjoy the coding. [which is why i love working matrices]

once I have this 'bot' made that collects feathers i will make another that picks up arrows, who knows how many bots...just lots doing pointless stuff. Once I have 2-3 bots running around i will make a master bot that will send commands via in-game messages [this is the hard part, i will have to make a code to 'read' pixels as text]. The master bot will send messages to all the gather bots and request how many items they have picked up, what their status is, how many times they gotten lost, etc... I also plan to add a small degree of AI to the bots [iE: if they cant find enough feathers: lower the step size so that it is more likely to find them]

the master bot will also stay online 24/7 and possible interact with real life players, asking trivial questions and such. I was also thinking about making a 'taxi bot' that would go around giving tours of the area these are all ideas, more than likely ill just get tire of coding and move onto my home-made jet engine project next

anyway, thats the plan. Back to the coding:

Second line 26 & 35 should be

CODE 

MouseClick("left",$X,$Y, 1, 0)

I dont have the help file with me but what would that do? does that click at (x,y) once with speed as 0?

I forgot to add that this 'game' I am making the bots for doesnt exactly like the use of bots...so I am trying to simulate human interactions as much as possible and a human clicking at non-human speeds will draw attention [if they even check for that kind of stuff]

Third lines 88 & 103 should be

CODE 

MouseMove($X,$Y,0)

Same goes with this, I want to have some slowness to the mouse movement so that it appears as if a human is and the controls. but! if it moves too slow the condition will become false [chicken walks out of the way] by the time the mouse gets there and I will never be able to click on the chicken. Anyone know what the fastest a human scroll speed is? 5?

When we wake up we check (4,5), then (4,6), ..., (8,9) before starting checking (0,0), (0,1), etc.

Is this what you intend? Notice that during the sleep period after clickin' the chickin then you aren't searching for the feather. Is this OK?

Actuallyyes, bc of the above mention problem [chicken walks out of the way b4 it clicks] lots of chickens escape my clicker. But, if the chicken walks to the right it will be caught on the next pass [step size as a factor here]

Notice also once we have found the chicken at (4,4) and woken up from our sleep then we immediately check for a feather at (4,4). Is this sensible?

yup, assuming i can kill the chicken it will drop a feather.

Finally, from the code snippet posted, then after the first ten cycles you always process the ";stuff in here is kinda long/messy, i took it out" at every pixel! Is this what you want?

I believe so. 10 cycles takes longer than you might think. Assuming that if found a few chickens/feathers along the way 10 cycles is almost 1-3 mins, if the 'bot' stands still for longer than 5mins with mouse movement it will be forced to logoff. So, ever 2-3 minutes I check to see if the bot has clicked on anything if no, it tries to center itself on the map again. [this is also hard, I have to work against the game designers anit-bot system. the map is different every time you look at it, so i have to do a pixel search to find a known location, then judge where i should go from that location to get back to the chicken farm. after 4hours of running the bot got lost in a cow farm...so this still needs work!]

oh wait, i just re-read your Q. and I think I understand what you are asking. I suppose I dont need to check if the bot hasnt clicked anywhere until the end of the cycle. At first I had it at every pixel so that I could force it to go into the loop when i pressed F2.

I am going copy your nice little picture here and try and 'draw' what I am dealing with:

_ 0 1 2 3 4 5 6 7 8
0 . . . . . . . . . 
1 . . . . . . . . . 
2 . . . . . . . . . 
3 . . . . . . . . . 
4 . . . . + . . . . 
5 . . . . . . . . . 
6 . . . . . . . . . 
7 . . . . . . . . . 
8 . . . . . . * . . 
9 . . . . . . . . .

+-bot

*-chicken

normally my search starts at 0,0 and ends 9,8 like you said. But!, I want to change this to s spiraling motion starting at the (+). The (+) will not always be in the same pixel location it will have to be where the bot IS. i want to search the pixels closest to the bot first bc the closer the chicken is to the bot the fast the bot can attack it.

assuming i start and the (+) (3,4) my next pixel should be (3,5) then (4,5) then (4,4)

(4,3)

(3,3)

(3,4)

(3,5)

(3,6)

(4,6)....spiral continues...

i think that will solve a few problems. i would have to reset the cycle once i clicked so that it would start searching the pixels closest to the bot.

In case you were going to post a loop sequence that would make that spiral pattern, dont. I want to see if I can make one up on my own. But I might be coming back here for help.....

Oi, there is SOOO much more I could try and explain but I think I will stop here. I have a headache and I am sure you do also after all this

thanks again everyone, your help is much appreciated!

EDIT:

Fixed some typos...man I cant type with out word :whistle:

Also, I set my 'bot' to do its thing before I started my I came back just now and they guy was still going! yay! Total time elapse of about 5-6hrs. Not bad B)

Edited by Wallfire

:cheer: awww...wheres the chick?

Link to post
Share on other sites

heh, ya... you got me. but before you jump to any conclusions let me explain my MASTER plan:

Not a problem B) Hey, I once used AutoIt to write a bot for a game but don't tell anyone :whistle: But it was only once and the therapy is going well - just taking it a day at a time :angry:

I dont have the help file with me but what would that do? does that click at (x,y) once with speed as 0?From the help file

[optional]the speed to move the mouse in the range 1 (fastest) to 100 (slowest). A speed of 0 will move the mouse instantly. Default speed is 10.

I forgot to add that this 'game' I am making the bots for doesnt exactly like the use of bots...so I am trying to simulate human interactions as much as possible and a human clicking at non-human speeds will draw attention [if they even check for that kind of stuff]

OK, I understand

In case you were going to post a loop sequence that would make that spiral pattern, dont. I want to see if I can make one up on my own. But I might be coming back here for help.....

Actually I've just coded one myself, but I'll keep it to myself - although it might be fun to see how close it is to yours

EDIT:

Fixed some typos...man I cant type with out word 

I know, my posts are full of typos (plus most the the edits I make to my posts are to correct typos).

Hmm, an idea for the text editor add-on guys. An AutoIt spelling checker and an AutoIt autocorrect facility (As a programmer, my fingers have "dyslexia" on certain words - I always seem to type flase in booleans - don't know why)

GrahamS

Link to post
Share on other sites

Hmm, an idea for the text editor add-on guys. An AutoIt spelling checker and an AutoIt autocorrect facility

What text editor?

If the editor works with ControlGetText(...) then auto-correction might be do-able.

If using TextPad, I have dictionary syntax coloring file (for highlighting misspelled words).

Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to post
Share on other sites

Alright. i tried to think of a alogrith for a sprial...couldnt think of a easy way to do it. but i did come up with another way. its really close to a sprial i call it a ripple pattern, or a 'wave'. actually, it is a sprial...all i would need to is re-arange the order in which it does the edges

looks kinda like this:

% 0 0 0 0 0 0 0   
% 0 1 1 1 1 1 0 
% 0 1 0 0 0 1 0
% 0 1 0 9 0 1 0 
% 0 1 0 0 0 1 0
% 0 1 1 1 1 1 0 
% 0 0 0 0 0 0 0

the #9 indicates where the ripple orginates and the #1 indicates what sectors are being looked at. i didnt write the code in AutoIt [forgive me :whistle: ] i wrote it in MATLAB which is the languge i know the most about. it also has a really nice debugger system, along with easy handling of matrices.

here is what code i came up with. you should be able to figure out all the commands used, i used mainly for and if loops. The '%' is the comment out command in matlab, just like ';' in autoit. i added some comments in the code to help explain the logic.

:lmao::P:(;););):D:mad::mad::mad::mad:

Just before i was going to copy in what i have, i thought of a way of making my pattern FASTER. the way i have it now works great for a squre matrix: as long as all 4 edges reach the end at the same time.

Then i realised that in my 'bot' project this will not be the case, the ripple point of orgion (9) will be moving and the scanning area is not square. so i changed the code so that if a edge hit the wall of a matrix it would not move, allowing the other edges to finish scanning the area.

BUT! having the edges sit there and scan the same edge over and over again untill the other edges finish scanning is taking up time, so now im re-writing it so that it will only scan the edge once if it is on the wall. after that it will no longer scan along thoe edge but continue to let the other edges scan untill they hit their wall.

incase i still have a few brain cells not doing their job, let me wake/shake them up:

:mad::mad::mad:

btw, now i remeber why i dont like matlab so much...

ERROR:??? Index exceeds matrix dimensions. <--ARGH!!

if i see another one of these.... :whistle:

*goes back to coding...*

ill post again when i have a finished code.

EDIT::

ok, yay! B):evil::angry:

i finally got the sprial pattern working. it is still in MATLAB but the alogrithm works great. here is the code. it is longer than i was expecting [~200lines] but i cant think of more efficent way of doing it.

tell me what you think:

%//////////////File Name////////////////
%/////Wave maker
%////////////////////////////////////
%  Object of wave maker is to produce a scanning pattern that looks like this:

%(1,1)  x->
% |    top
% 0 0 0 0 0 0 0         y
% 0 1 1 1 1 1 0         |
% 0 1 0 0 0 1 0 -(3,7)  V
% 0 1 0 9 0 1 0  right
% 0 1 0 0 0 1 0
% 0 1 1 1 1 1 0 
% 0 0 0 0 0 0 0 -(7,7)  
%   bottom

% #9 - center of wave
% #1- the sector being scanned
% #0- sector NOT being currently scanned

%LOGIC:
% +Start at point (StartY,StartX)
% +Before Scanning each edge of the ripple add one value to the radus of
% the ripple(r).
% +Each edge of the ribble is define by either Mesh(Max/Min)(X/Y)
% +Check to make sure that the radius will not exceed
% matrix dimensions. if it does, replace Mesh(Max/Min)(X/Y) with
% Total(Min/Max)(X/Y)
% +Scan each edge of the ripple, if it finds a 1 make it a 5 
% NOTE: all points are listed as 1, this way i can see if any points are
% being skipped in the scanning process.
% NOTE: MATLAB the x axis going from left to right and y-axis top to bottom.
%with the (1,1) in the upper left hand corner.

% begin program:
clc         %clear command prompt
clear all   %delted all varibles

%Input varibles
StartY=5;
StartX=2;

%define varibles
T= zeros(11,11) + 1; %makes mesh all (0 + 1)'s
T(StartY,StartX)=9;
TotalMaxX=11;
TotalMinX=1;
TotalMaxY=11;
TotalMinY=1;
iStep=1;
%Distance from (Y,X) to top edge
TopDist=StartY-1;
%Distance from (Y,X) to the bottom edge
BotDist=TotalMaxY-StartY;
%Distance from Y,X to the left edge
LefDist=StartX-1;
%Distance form (Y,X) to the right edge
RigDist=TotalMaxX-StartX;

for r=1:1:11 %increase Ripple radius   
    
    %set the scanning surface
    ScanMaxX=StartX + r; 
    ScanMinX=StartX - r; 
    ScanMinY=StartY - r; 
    ScanMaxY=StartY + r; 
    
    %Start moving about the mesh
    
    % %Top Edge
    if ScanMinY >= TotalMinY
        
        %Set point for top-left corner in bound
        if r <= LefDist
            STARTSCAN=StartX -r;
        end
        
        %Set point for top-right corner in bound
        if r <= RigDist 
            STOPSCAN=StartX+r;
        end
        
        %Set point for top-left corner out of bound
        if r > LefDist
            STARTSCAN= StartX-LefDist;
        end
        
        %Set point for top-right out of bound  
        if r > RigDist
            STOPSCAN=StartX+RigDist;
        end
        
        %Scan the Top Edge
        for x= STARTSCAN:iStep:STOPSCAN
            y=ScanMinY; 
            if T(y,x)==1
                T(y,x)=5;
            end            
        end
    end
    
    %bottom edge
    if ScanMaxY <= TotalMaxY
        
        %set point for left-bottom in bound
        if  r <= LefDist
            STARTSCAN=StartX-r ;          
        end
        
        %set point for left-bottom out of bounds
        if r > LefDist    
            STARTSCAN=StartX-LefDist   ;  
        end
        
        %set point for right-bottom in bound
        if r <= RigDist;
            STOPSCAN= StartX+r     ;      
        end
        
        %set point for right-bottom out of bound
        if  r >  RigDist
            STOPSCAN=TotalMaxX  ;    
        end
        
        %Scan the bottom edge
        for x= STARTSCAN:iStep:STOPSCAN 
            y=ScanMaxY;         
            if T(y,x)==1
                T(y,x)=5;
            end
        end
    end
        
    %left edge
    if ScanMinX >= TotalMinX %checks to see if that edge is past the matrix
        
        %set point for top-left corner in bounds
        if r <= TopDist  
            SCANSTART=StartY-r;
        end      
        
        %set point for top-left corner out of bounds
        if r >= TopDist        
            SCANSTART=StartY-TopDist;          
        end        
        
        %set point for left-bottom corner of edge out of bounds
        if r > BotDist          
            SCANSTOP=StartY+BotDist;
        end
        
        %set point for left-bottom corner of edge in bounds
        if r <= BotDist 
            SCANSTOP=StartY+r;
        end
        %Scan the left edge
        for y= SCANSTART:iStep:SCANSTOP
            x=ScanMinX; 
            if T(y,x)==1
                T(y,x)=5;
            end            
        end
        
    end
        
    %right edge
    if ScanMaxX <= RigDist  + StartX
        
        % set point upper-right within bounds
        if StartY - r < TopDist        
            STARTSCAN=StartY-r;
        end
        
        %set point upper-right out of bounds
        if r > TopDist                 
            STARTSCAN=StartY-TopDist;
        end
        
        % set point lower-right in bounds
        if r <= BotDist                
            STOPSCAN=StartY+r;
        end
        
        %set pointlower-right out of bounds
        if    r+StartY > TotalMaxY      
            STOPSCAN=StartY+BotDist;
            
        end
        
        %Scan the right edge
        for y= STARTSCAN:iStep:STOPSCAN            
            x=ScanMaxX; 
            if T(y,x)==1
                T(y,x)=5;
            end            
        end
    end
end
T       %displays (T)
%end program :)

the only problem i can see with it is the corners get scaned twice, i can easliy fix this but i will leave it for now.

Edited by Wallfire

:cheer: awww...wheres the chick?

Link to post
Share on other sites

forgot to add to my previous post:

can anyone think of a easier way of making the sprial pattern? the orgion of spiral has to be a varaible and it needs to be done as quick as possible. [which means less code lines, correct?]

let me know if you see a flaw in what i have, or have any Qs regarding MATLAB.

:cheer: awww...wheres the chick?

Link to post
Share on other sites

Basically looks OK.

A few small thoughts...

Don't know if MATLAB has an else clause, but assuming that it has then:

%Set point for top-left corner in bound
       if r <= LefDist
           STARTSCAN=StartX -r;
       end
       
       [snip]
       
       %Set point for top-left corner out of bound
       if r > LefDist
           STARTSCAN= StartX-LefDist;
       end

can be simplified to

if r <= LefDist
           STARTSCAN=StartX -r;
       else
           STARTSCAN= StartX-LefDist;
       end

But LefDist = StartX-1 so we have

if r <= LefDist
           STARTSCAN=StartX -r;
       else
           STARTSCAN= 1;
       end

Similarly for STOPSCAN

Next, note that during a "ripple" the start and stop values for the top and bottom edges are the same, (as are the start and stop values for the left and right edges), so only calculate them once.

Also, the value y doesn't change in the following loop

for x= STARTSCAN:iStep:STOPSCAN
           y=ScanMinY; 
           if T(y,x)==1
               T(y,x)=5;
           end            
       end

So you assign the value ScanMinY to y (STOPSCAN - STARTSCAN+1) times. Wastefull, so move it outside the loop as follows:

y=ScanMinY; 
       for x= STARTSCAN:iStep:STOPSCAN
           if T(y,x)==1
               T(y,x)=5;
           end            
       end

If you want to impress your friends, y=ScanMinY; is called a loop invariant, and loop invariants can always be removed from within the loop safely.

So the core of your program would look like this

%set the scanning surface
   ScanMaxX=StartX + r; 
   ScanMinX=StartX - r; 
   ScanMinY=StartY - r; 
   ScanMaxY=StartY + r; 
   
   %Start moving about the mesh
   
   %Set point for top-left corner in bound
   if r <= LefDist
      HORSTARTSCAN=StartX -r;
   else
      HORSTARTSCAN= 1;
   end
       
   %Set point for top-right corner in bound
   if r <= RigDist 
      HORSTOPSCAN=StartX+r;
   else
      HORSTOPSCAN=TotalMaxX;
   end

   % Moved again, its invariant across the top & bottom edges
   y=ScanMinY; 

   % %Top Edge
   if ScanMinY >= TotalMinY
       
       %Scan the Top Edge
       for x= HORSTARTSCAN:iStep:HORSTOPSCAN
           if T(y,x)==1
               T(y,x)=5;
           end            
       end
   end
   
   %bottom edge
   if ScanMaxY <= TotalMaxY
       %Scan the bottom edge
       for x= HORSTARTSCAN:iStep:HORSTOPSCAN 
           if T(y,x)==1
               T(y,x)=5;
           end
       end
   end
       
   %set point for top-left corner in bounds
   if r <= TopDist  
      VERSCANSTART=StartY-r;
   else
      VERSCANSTART=1;          
   end        
       
   %set point for left-bottom corner of edge out of bounds
   if r > BotDist          
      VERSCANSTOP=TotalMaxY;
   else
      VERSCANSTOP=StartY+r;
   end

   x=ScanMinX; 

   %left edge
   if ScanMinX >= TotalMinX %checks to see if that edge is past the matrix
       
       %Scan the left edge
       for y= VERSCANSTART:iStep:VERSCANSTOP
           if T(y,x)==1
               T(y,x)=5;
           end            
       end
       
   end
       
   %right edge
   if ScanMaxX <= RigDist  + StartX
       %Scan the right edge
       for y= VERSTARTSCAN:iStep:VERSTOPSCAN            
           if T(y,x)==1
               T(y,x)=5;
           end            
       end
   end

Stopping the corners being done twice can be done by adding 1 to VERSCANSTART and subtracting 1 from VERSCANSTOP

HTH

GrahamS

Link to post
Share on other sites

hey thanks, that did help. here are a few responses/comments:

Don't know if MATLAB has an else clause, but assuming that it has then:

yup, sure does. i never seem to remember to use them tho. one day i will learn....

Next, note that during a "ripple" the start and stop values for the top and bottom edges are the same, (as are the start and stop values for the left and right edges), so only calculate them once.

hmm...assuming the the pair of edges are both being scaned yes, they do share the same stop and start points. but if an edge is not being scanned, it will not need a start/stop point....again smart thinking,nice B)

So you assign the value ScanMinY to y (STOPSCAN - STARTSCAN+1) times. Wastefull, so move it outside the loop as follows:

yup, i knew about that one. when designing the pattern i had at first multiple, multiple for loops and i was cutting/pasting all over the place. i stuck the 'y=' statement in there to make sure that it was moved with the correct for statement. i planned on taking it out, but i was so excited about the code working that i forgot about it.

Stopping the corners being done twice can be done by adding 1 to VERSCANSTART and subtracting 1 from VERSCANSTOP

yup :whistle:

thanks again!

when i re-write this into my auto-it script i am going to have the startX/Y locations randomly selected from the area. think that will help? ill play with it and see.

:cheer: awww...wheres the chick?

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...