tarajunky
2007-09-21 16:01:38
I have been using an array based color search strategy in my Chickenkiller and VEM scripts for about 6 months, and it works very well.
Most FindObj type procedures are based on searching for a color with tolerance. So, you find all the colors of that type and systematically move the mouse to each spot to check the uptext.
This strategy extends that functionality by then saving positive 'hits' to an array. The next time you search, it will first look for each of these exact known colors in the array. If none of them are found it will then revert back to a tolerance based scan. I also made it so that when a known color is found again, it will move that color forward in search priority within the array.
Here is an annotated example from my miner…
This approach allows your script to 'learn' which colors best match the object you want to find as it runs. This is especially helpful for colors that either move around a little bit and change due to the background behind them, or for colors that are sometime hidden and sometimes there depending on the position and angle of the screen.
Most FindObj type procedures are based on searching for a color with tolerance. So, you find all the colors of that type and systematically move the mouse to each spot to check the uptext.
This strategy extends that functionality by then saving positive 'hits' to an array. The next time you search, it will first look for each of these exact known colors in the array. If none of them are found it will then revert back to a tolerance based scan. I also made it so that when a known color is found again, it will move that color forward in search priority within the array.
Here is an annotated example from my miner…
Function FindCopper:boolean;
var x,y,TestColor,a,l,m,i,red,green,blue:integer;
var p: array of Tpoint;
begin
FFlag(0);
Wait(50);
Status('Finding Copper');
l:=GetArrayLength(CopperColors); //Checks known colors first
if l>0 then
begin
for i:= 0 to l-1 do
begin
FindColorsSpiralTolerance(MSCX,MSCY,p,CopperColors[i],MSX1,MSY1,MSX2,MSY2,0);
m:=GetArrayLength(p);
if m>0 then
begin
for a:= 0 to m-1 do
begin
if CheckAndClick(p[a].x,p[a].y) then //Moves mouse to position, checks uptext and clicks if correct.
begin
result:=true;
if i>0 then //if the color is not in the first position of the array...
begin // Swap found color with the one ahead of it in the array
m:=CopperColors[i-1];
CopperColors[i-1]:=CopperColors[i];
CopperColors[i]:=m;
end;
exit; // We found our color, so we exit the function completely.
end;
end;
end;
end;
end;
//We didn't find any known colors, so continue on to the tolerance search
FindColorsSpiralTolerance(MSCX,MSCY,p,4153992,MSX1,MSY1,MSX2,MSY2,25);
l:=GetArrayLength(p);
if l>0 then
begin
for i:= 0 to l-1 do
begin
TestColor:=GetColor(p[i].x,p[i].y); //Additional autocoloring to reduce wrong points. (Optional)
red:=(TestColor mod 256);
green:=((TestColor/256) mod 256);
blue:=((TestColor/256) / 256);
if ((green-blue)<=46) then if ((green-blue)>=24) then
if ((red-green)>=26) then if ((red-green)<=51) then
if ((red-blue)>55) then if ((red-blue)<=94) then
begin
Wait(20);
ClickColor:=GetColor(p[i].x,p[i].y);
if CheckAndClick(p[i].x,p[i].y) then //Move mouse, check uptext and click
begin
result:=true;
FindColorsSpiralTolerance(x,y,p,ClickColor,MSX1,MSY1,MSX2,MSY2,0);
if GetArrayLength(p)<20 then //Make sure that the color is somewhat rare, and doesn't take up half the screen
begin
a:=GetArrayLength(CopperColors);
for i:= 0 to a-1 do
begin
if ClickColor=CopperColors[i] then //If color is already in the array...
begin
if i>0 then
begin // Move it up one spot in the array search priority
m:=CopperColors[i-1];
CopperColors[i-1]:=CopperColors[i];
CopperColors[i]:=m;
end;
exit;
end;
end;
// if it's not in the array yet, then add it to the end of the array
SetArrayLength(CopperColors,a+1);
CopperColors[a]:=ClickColor;
Writeln(IntToStr(ClickColor)+' added to Copper Color array');
end;
exit;
end;
end;
end;
end;
end;This approach allows your script to 'learn' which colors best match the object you want to find as it runs. This is especially helpful for colors that either move around a little bit and change due to the background behind them, or for colors that are sometime hidden and sometimes there depending on the position and angle of the screen.

140 ms, drawing and convering to a T2DBoolArray included. Still need to tweak the treshholds a bit.