SRL Archive - Test corner

TEST: New Compass routines


WT-Fakawi

2006-09-27 10:58:13

Just to show you guys we are not pining for the fjords I quickly wrote a very crude new Compass routine, based on simple colorfinding of the compass needle. I am not sure whether it is a stable color, but this wont be a problem to implement ofcourse.

Please test this little script. It is far from done yet (No failsafes…) but it works on my machine!

program NewCompass;
{.include SRL/SRL.scar}

Function NewCompass(Direction: string): boolean;
begin
Case lowercase(Direction) of
'n':
begin
repeat
KeyDown(VK_RIGHT);
wait(10+Random(10));
until FindColor(x,y,723587,567,14,567,14);
KeyUp(VK_RIGHT);
Result:=True;
end;
'e':
begin
repeat
KeyDown(VK_RIGHT);
wait(10+Random(10));
until FindColor(x,y,723587,572,21,572,21);
KeyUp(VK_RIGHT);
Result:=True;
end;
's':
begin
repeat
KeyDown(VK_RIGHT);
wait(10+Random(10));
until FindColor(x,y,723587,565,26,565,26);
KeyUp(VK_RIGHT);
Result:=True;
end;
'w':
begin
repeat
KeyDown(VK_RIGHT);
wait(10+Random(10));
until FindColor(x,y,723587,559,20,559,20);
KeyUp(VK_RIGHT);
Result:=True;
end;
end
end;


begin
HowManyPlayers:=1;

NumberOfPlayers(HowManyPlayers);

Players[0].Name :='';
Players[0].Pass :='';
Players[0].Nick :='';
Players[0].Active:=True;

SetupSRL;
//LoginPlayer;
MouseSpeed:=15;
Wait(1000);
If NewComPass('n') then writeln('North Found');
Wait(3000);
if NewComPass('e') then writeln('East Found');
Wait(3000);
if NewComPass('s') then writeln('South Found');
Wait(3000);
if NewComPass('w') then writeln('West Found');
end.

More to come. Anyone that can enhance the newcompass or has a better idea, please, now is the time to be creative. We need your help.

Wizzup?

2006-09-27 11:03:06

Procedure Face(Side:String);

Var Fx, Fy, Dx, Dy : Integer;
Var ComMark: Integer;


Begin

MarkTime(ComMark);
Case LowerCase(Side) Of

'n' : Begin Fx := 566; Fy := 13; End;
'e' : Begin Fx := 573; Fy := 20; End;
's' : Begin Fx := 566; Fy := 27; End;
'w' : Begin Fx := 560; Fy := 19; End;
End;

KeyDown(VK_RIGHT);
Repeat
Wait(1);
Until ( (FindColor(Dx,Dy,723587,Fx,Fy,Fx,Fy))
Or (TimeFromMark(ComMark) > 12000) );
KeyUp(VK_Right);
End;

Starblaster100

2006-09-27 11:13:32


program New;
{.include SRL/SRL.scar}

Function Face(Side:String): Boolean;
Var
Fx, Fy, Dx, Dy : Integer;
ComMark: Integer;
Begin
MarkTime(ComMark);
Case LowerCase(Side) Of
'n' : Begin Fx := 566; Fy := 13; End;
'e' : Begin Fx := 573; Fy := 20; End;
's' : Begin Fx := 566; Fy := 27; End;
'w' : Begin Fx := 560; Fy := 19; End;
end;
Repeat
KeyDown(VK_RIGHT);
wait(1);
If(FindColor(Dx,Dy,723587,Fx,Fy,Fx,Fy))then
begin
Result := True;
break;
end;
Until(TimeFromMark(ComMark) > 12000);
KeyUp(VK_Right);
End;

begin
SetupSRL;
If Face('n')then Writeln('found north');
If Face('e')then Writeln('found east');
If Face('s')then Writeln('found south');
If Face('w')then Writeln('found west');
end.

done.

WT-Fakawi

2006-09-27 11:14:55

yes yes. Wizz'ones it is!

Yakman

2006-09-27 13:18:49

its works quite well for me, i tried it on my slowest computer, which i have to turn off solve box and sandwich lady and it still works,

its a good idea with the find colors, i havent changed the numbers into colors to see what they look like yet, i guessing that GetRS2MinimapCompassAngle doesnt work anymore

i remember a old Face( procedure from osi used bitmaps to find the angle, bit this way is better because it compiles and runs faster


repeat
keydown(
wait(1)
its probably best not to put a keydown inside the loop because it might be detectable, someone pressing the same key every 1 milliseconds, put it outside the loop

keydown(
repeat
wait(1)

bobert5696

2006-09-27 17:36:11

works perfect, ive tested for about 20 min now, never messed up :) (was using wizzup's)

Mr. Freeweed

2006-09-27 19:03:17

From: Wizzup?
Procedure Face(Side:String);

Var Fx, Fy, Dx, Dy : Integer;
Var ComMark: Integer;


Begin

MarkTime(ComMark);
Case LowerCase(Side) Of

'n' : Begin Fx := 566; Fy := 13; End;
'e' : Begin Fx := 573; Fy := 20; End;
's' : Begin Fx := 566; Fy := 27; End;
'w' : Begin Fx := 560; Fy := 19; End;
End;

Repeat
KeyDown(VK_RIGHT);
Wait(1);
Until ( (FindColor(Dx,Dy,723587,Fx,Fy,Fx,Fy))
Or (TimeFromMark(ComMark) > 12000) );
KeyUp(VK_Right);
End;



Thanks I didnt even have to recode most of my scripts and down with setrun though its an easy fix. I thought you retired fawaki? just cant stop writing code I see. =)

EDIT: Whats up with the you havnt posted in awhile please talk to us annoucement hum?

masquerader

2006-09-28 00:02:44

im very proud to release this, as i worked pretty much all day on it, and went though three different prototypes until i came up with this.

i am proud to release: findsrlcompassangle

program New;
{.include srl/srl.scar}

function closeto(x1,y1,x2,y2:integer):boolean;
begin
if((trunc(abs(x1-x2))<=2)and(trunc(abs(y1-y2))<=2))then
result:=true;
end;

function findsrlcompassangle:integer;
//returns degrees counter-clockwise compass is rotated
//by masquerader
var
i,j:integer;
points, tics,final:tpointarray;
south:integer;
begin
findcolorsspiraltolerance(566,20,points,920735,548, 0,585, 38,0);
for i:=0 to getarraylength(points)-1 do
begin
x:=points[i].x;
y:=points[i].y;
if((x<559)or(x>573)or(y<11)or(y>28))then
begin
setarraylength(tics,getarraylength(tics)+1);
tics[getarraylength(tics)-1].x:=x;
tics[getarraylength(tics)-1].y:=y;
end;
end;
if(getarraylength(tics)=0)then
begin
writeln('something went wrong, couldnt find any tics');
terminatescript;
end;

setarraylength(final,1);
final[0].x:=tics[0].x
final[0].y:=tics[0].y;

for i:=1 to getarraylength(tics)-1 do
begin
for j:=0 to getarraylength(final)-1 do
begin
if(closeto(tics[i].x,tics[i].y,final[j].x,final[j].y))then
break;

if(j=getarraylength(final)-1)then
begin
setarraylength(final,getarraylength(final)+1);
final[getarraylength(final)-1].x:=tics[i].x
final[getarraylength(final)-1].y:=tics[i].y;
end;
end;

end;
if(getarraylength(final)<>3)then
writeln('something went wrong, couldnt find the 3 compass tics');

// writeln('compass tics:');
// for i:=0 to getarraylength(final)-1 do
// writeln(inttostr(i)+' : '+inttostr(final[i].x)+','+inttostr(final[i].y));


if((distance(final[0].x,final[0].y,final[1].x,final[1].y)<22)and
(distance(final[0].x,final[0].y,final[2].x,final[2].y)<22))then
south:=0
else
if((distance(final[1].x,final[1].y,final[0].x,final[0].y)<22)and
(distance(final[1].x,final[1].y,final[2].x,final[2].y)<22))then
south:=1
else
if((distance(final[2].x,final[2].y,final[0].x,final[0].y)<22)and
(distance(final[2].x,final[2].y,final[1].x,final[1].y)<22))then
south:=2;

// writeln('south one is: '+inttostr(south));
x:=final[south].x-566;
y:=final[south].y-21;

result:=round(degrees(arctan2(y,x)));
result:=result-90;

if((x>0)and(y>0))then //n-e
result:=result*-1;
if((x>0)and(y<0))then //e-s
result:=result-90;
if((x<0)and(y<0))then //s-w
result:=result*-1;
if((x<0)and(y>0))then //w-n
result:=result-90;

result:=trunc(fixd(result));

end;

begin
writeln(inttostr(findsrlcompassangle));
end.

theres only two conditions: dont ask how it works (because i cant tell you) and dont complain how slow it is

Mad Cow

2006-09-28 02:15:59

THATS BLODDY BRILLIANT!

Works rather well indeed.

Good work,
Mad Cow

WhiteShadow

2006-09-28 05:23:03

Yay this forum responds quickly. Good ideas, if i have time, I'll try to contribute some stuff. xP

Omg, masquerader you must be teh best here at TPointArrays. xP

ruler

2006-09-28 09:51:40

dont do plz!!!
repeat
KeyDown(VK_RIGHT);
wait(10+Random(10));
until FindColor(x,y,723587,567,14,567,14);
KeyUp(VK_RIGHT);


very dectable. See with i have complete visability to the events your producing. I see why early version of scar where dected. The code has the issue:

[09:45:44:0328] Event out java.awt.event.KeyEvent[KEY_PRESSED,keyCode=39,keyText=Right,keyChar=Undefined keyChar,keyLocation=KEY_LOCATION_STANDARD] on canvas0
[09:45:44:0421] Event out java.awt.event.KeyEvent[KEY_PRESSED,keyCode=39,keyText=Right,keyChar=Undefined keyChar,keyLocation=KEY_LOCATION_STANDARD] on canvas0
[09:45:44:0531] Event out java.awt.event.KeyEvent[KEY_PRESSED,keyCode=39,keyText=Right,keyChar=Undefined keyChar,keyLocation=KEY_LOCATION_STANDARD] on canvas0
[09:45:44:0625] Event out java.awt.event.KeyEvent[KEY_PRESSED,keyCode=39,keyText=Right,keyChar=Undefined keyChar,keyLocation=KEY_LOCATION_STANDARD] on canvas0
[09:45:44:0750] Event out java.awt.event.KeyEvent[KEY_RELEASED,keyCode=39,keyText=Right,keyChar=Undefined keyChar,keyLocation=KEY_LOCATION_STANDARD] on canvas0

form this scar script i wrote, I AM A NUB AT SCAR

program NewCompass;


begin

sleep(3000);
KeyDown(VK_RIGHT);
sleep(100);
KeyDown(VK_RIGHT);
sleep(100);
KeyDown(VK_RIGHT);
sleep(100);
KeyDown(VK_RIGHT);
sleep(100);
KeyDown(VK_RIGHT);
sleep(100);
KeyUp(VK_RIGHT);

end.

I suggest instead to alwasy do a keyup after a keydown or you will be dected.

Also never use keydown/ keyup on keys that are "typing keys".

Wizzup?

2006-09-28 10:04:29

yes i just noticed. :)

The chagnes have already been made in the SvN though. No worries.

CamHart

2006-11-27 20:44:29

Only works with N W E S so nothign with differen't angles like masquander's angle finder (which could remove the need for useing this, atleast with RRW) but i figured i could post it here.

program New;
{.Include SRL\SRL\Extended\xColor.Scar}
{.Include SRL\SRL.Scar}

Function ArrayDifference(one, two:Array of Integer):Integer;
Var mylength, c, different:integer;
Begin
different:= 0;
mylength:= Min(GetArrayLength(one), GetArrayLength(two));
For c:=0 to (mylength - 1) Do
Begin
If(One[c] <> Two[c])Then
different:= different + 1;
End;
Result:= different;
End;

Function CameraMoving:Boolean;
Var
c, v:Integer;
SColor, FColor: Array [0..30] of Integer;
Begin
v:= 0;
For c:= 13 to 43 Do
Begin
SColor[v]:= GetColor(593, c);
v:= v + 1;
End;
Wait(100);
v:= 0;
For c:= 13 to 43 Do
Begin
FColor[v]:= GetColor(593, c);
v:= v + 1;
End;
If(ArrayDifference(SColor, FColor) > 5)Then
Begin
Result:= true;
End Else
Begin
v:= 0;
For c:= 13 to 43 Do
Begin
SColor[v]:= GetColor(686, c);
v:= v + 1;
End;
Wait(100);
v:= 0;
For c:= 13 to 43 Do
Begin
FColor[v]:= GetColor(686, c);
v:= v + 1;
End;
If(ArrayDifference(SColor, FColor) > 5)Then
Result:= true;
End;
End;

Function ShortWay(Direction:String):Boolean;
Var
QuadOne, QuadTwo, QuadThree, QuadFour:TPointArray;
GetMax: Integer;
Begin
FindColorsTolerance(QuadTwo, 920735, 552, 7, 566, 19, 80);
FindColorsTolerance(QuadOne, 920735, 566, 7, 579, 19, 80);
FindColorsTolerance(QuadThree, 920735, 552, 19, 566, 31, 80);
FindColorsTolerance(QuadFour, 920735, 566, 19, 579, 31, 80);//4341941}
{FindColorsTolerance(QuadTwo, 4341941, 552, 7, 566, 19, 80);
FindColorsTolerance(QuadOne, 4341941, 566, 7, 579, 19, 80);
FindColorsTolerance(QuadThree, 4341941, 552, 19, 566, 31, 80);
FindColorsTolerance(QuadFour, 4341941, 566, 19, 579, 31, 80);//4341941 }
GetMax := Max(Max(GetArrayLength(QuadOne), GetArrayLength(QuadTwo)),Max(GetArrayLength(QuadThree), GetArrayLength(QuadFour)));
Writeln('');
Writeln('Max: '+IntToStr(GetMax));
Writeln('One: '+IntToStr(GetArrayLength(QuadOne)));
Writeln('Two: '+IntToStr(GetArrayLength(QuadTwo)));
Writeln('Three :'+IntToStr(GetArrayLength(QuadThree)));
Writeln('Four: '+IntToStr(GetArrayLength(QuadFour)));
If(StrGet(Direction, 1) = 'n')Then
Begin
//Result:= ((GetArrayLength(QuadTwo) + GetArrayLength(QuadThree)) > (GetArrayLength(QuadOne) + GetArrayLength(QuadFour)));
If((GetMax = GetArrayLength(QuadTwo)) or (GetMax = GetArrayLength(QuadThree)))Then
Result:= true;
End Else
If(StrGet(Direction, 1) = 'e')Then
Begin
//Result:= ((GetArrayLength(QuadThree) + GetArrayLength(QuadFour)) < (GetArrayLength(QuadOne) + GetArrayLength(QuadTwo)));
If((GetMax = GetArrayLength(QuadThree)) or (GetMax = GetArrayLength(QuadFour)))Then
Result:= true;
End Else
If(StrGet(Direction, 1) = 'w')Then
Begin
//Result:= ((GetArrayLength(QuadOne) + GetArrayLength(QuadTwo)) < (GetArrayLength(QuadThree) + GetArrayLength(QuadFour)));
If((GetMax = GetArrayLength(QuadOne)) or (GetMax = GetArrayLength(QuadTwo)))Then
Result:= true;
End Else
If(StrGet(Direction, 1) = 's')Then
Begin
//Result:= ((GetArrayLength(QuadFour) + GetArrayLength(QuadOne)) > (GetArrayLength(QuadTwo) + GetArrayLength(QuadThree)));
If((GetMax = GetArrayLength(QuadOne)) or (GetMax = GetArrayLength(QuadFour)))Then
Result:= true;
End Else
Begin
Writeln('Compass direction must start with first letter "n", "e", "s", "w"');
Exit;
Result:= false;
End;
End;


Function FindCompassDirectionColors(Direction: String):Boolean;
Var c:integer;
Begin
If(StrGet(Direction, 1) = 'n')Then
Begin //bottom //west //east
If(FindColor(x, y, 920735, 564, 30, 569, 36) and FindColor(x, y, 920735, 546, 16, 556, 22) and FindColor(x, y, 920735, 576, 16, 584, 23))Then
Result:= True;
End Else
If(StrGet(Direction, 1) = 'w')Then
Begin
If(FindColor(x, y, 920735, 564, 30, 569, 36) and FindColor(x, y, 920735, 546, 16, 556, 22) and (Not (FindColor(x, y, 920735, 576, 16, 584, 23))))Then
Result:= True;
End Else
If(StrGet(Direction, 1) = 'e')Then
Begin
If(FindColor(x, y, 920735, 564, 30, 569, 36) and (Not (FindColor(x, y, 920735, 546, 16, 556, 25))) and FindColor(x, y, 920735, 576, 16, 584, 23))Then
Result:= True;
End Else
If(StrGet(Direction, 1) = 's')Then
Begin
If((Not (FindColor(x, y, 920735, 564, 30, 569, 36))) and FindColor(x, y, 920735, 546, 16, 556, 22) and FindColor(x, y, 920735, 576, 16, 584, 23))Then
Result:= True;
End;
End;

Function Compass(Direction: String):Boolean;
var
TheKey:Boolean;
Begin
Direction:= Lowercase(Direction);
TheKey:= ShortWay(Direction);
If(Not (FindCompassDirectionColors(Direction)))Then
Begin
If(TheKey)Then
Begin
KeyDown(VK_Right);
End
Else
Begin
KeyDown(VK_Left);
End;
Repeat
If( (Not (CameraMoving)) {and (Random(10) < 2)} and (Not (FindCompassDirectionColors(Direction))) )Then
Begin
ActivateClient;
TheKey:= ShortWay(Direction);
If(TheKey)Then
Begin
KeyDown(VK_Right);
End
Else
Begin
KeyDown(VK_Left);
End;
End;
Wait(1);
Until(FindCompassDirectionColors(Direction));
If(TheKey)Then
Begin
KeyUp(VK_Right);
End
Else
Begin
KeyUp(VK_Left);
End;
End;
End;

begin
SetupSRL;
ActivateClient;
Compass('n');
end.

m0u53m4t

2006-11-30 10:48:36

how flawless is it?

Arr0w

2006-11-30 11:23:09

Worked for me a bit off center though ( wroks betetr than the last one )