SRL Archive - SRL Suggestions

Forester fix


NCDS

2010-10-08 00:10:51

InForesterRandom was broken, obviously causing SolveForester to fail.

Current InForesterRandom:

function InForesterRandom: Boolean;
var
Count, fX, fY, X, Y: Integer;
Pts: TPointArray;
begin
if (FindColor(X, Y, 60909, MMCX - 20, MMCY - 20, MMCX + 20, MMCY + 20)) then //Exists NPC dots
if (not(InBlack)) then //No black in Forester
begin
FindColorsTolerance(Pts, 60909, MMX1, MMY1, MMX2, MMY2, 0);
Count := Length(Pts);
if (Count < 10) then Exit; //More than 10 NPC dots (pheasants)
if (CountColorTolerance(clWhite, MMX1, MMY1, MMX2, MMY2, 50) < 20) then //No white walls
begin
ForesterCenter(fX, fY);
{$ifdef Simba}
FilterPointsDist(pts,0,50,fx,fy);
{$else}
FilterPointsPie(Pts, 0.0, 360.0, 0.0, 50.0, fX, fY);
{$endif}
Result := (Length(Pts) = Count); //All NPC's concentrated in centre
end;
end;
end;

Colors were outdated, and the NPC dots simply are not focused around the center anymore.

Fixed:

function InForesterRandom: Boolean;
var
Count, X, Y: Integer;
Pts: TPointArray;
begin
if (FindColor(X, Y, 62965, MMCX - 20, MMCY - 20, MMCX + 20, MMCY + 20)) then //Exists NPC dots
if (not(InBlack)) then //No black in Forester
begin
FindColorsTolerance(Pts, 62965, MMX1, MMY1, MMX2, MMY2, 0);
Count := Length(Pts);
if (Count < 10) then Exit; //More than 10 NPC dots (pheasants)
Result := (Length(Pts) = Count);
end;
end;

Succesful debug:

Compiled succesfully in 624 ms.
SRL Compiled in 0 msec
Forester: We should talk to the freaky forester.
Forester: Kill The 3 Tailed Pheasant.
Forester: Killed Pheasant.
Forester: Leaving Forester.
Forester: Forester random solved.
Successfully executed.

Wizzup?

2010-10-08 03:49:55

Applied. I really wonder why there was that ifdef simba filterpointsdist else filterpointspie, though.

Did you check it for false positives too? Or is that very unlikely?

Also, been out for a bit; is 62965 the new background colour for NPCs?

NCDS

2010-10-08 06:28:26

From: Wizzup?
Applied. I really wonder why there was that ifdef simba filterpointsdist else filterpointspie, though.

Did you check it for false positives too? Or is that very unlikely?

Also, been out for a bit; is 62965 the new background colour for NPCs?


I ran it once when it wasn't in the random and it returned negative, but that's it.

62965 is just the most common color for NPC dots I could find.

Thanks for the fast commit :)

Gu3st...

2010-10-08 13:44:06

if (Count < 10) then Exit;                                                //More than 10 NPC dots (pheasants)
Result := (Length(Pts) = Count);
can be made into
Result := (Count > 10);                                                //More than 10 NPC dots (pheasants)

Nava2

2010-10-08 14:23:28

From: Zyt3x
if (Count < 10) then Exit;                                                //More than 10 NPC dots (pheasants)
Result := (Length(Pts) = Count);
can be made into
Result := (Count > 10);                                                //More than 10 NPC dots (pheasants)


Result := (Count >= 10);

;)

TRiLeZ

2010-10-08 15:21:56

What are you talking about? The NPCs are still centre oriented…

Also, the npc dot colour didn't change. It's still 60909.

Your function would return true if there was an npc around the centre of the minimap and also if there was more than 10 npcs on the minimap.

Your function even returned true when I was in the rat pit, below varrock.

A reason why it could have been failing previously was the white wall counting mechanism. At the end of August, I changed the count of 20 to 40, to account players and whatnot, and it worked, but since I didn't have an SVN account at that time, I couldn't commit it so I posted it but it was never committed and was forgotten of.

I made a new function:

function InForesterRandom: Boolean;
var
Count, fX, fY: Integer;
Pts: TPointArray;
begin
if (CountDots('npc') > 10) and (not InBlack) and
(CountColorTolerance(clWhite, MMX1, MMY1, MMX2, MMY2, 50) < 40) then //White walls
begin
Pts := GetMiniMapDots('npc');
Count := Length(Pts);
ForesterCenter(fX, fY);
{$ifdef Simba}
FilterPointsDist(pts,0,50,fx,fy);
{$else}
FilterPointsPie(Pts, 0.0, 360.0, 0.0, 50.0, fX, fY);
{$endif}
Result := (Length(Pts) = count);
end;
end;

Which works beautifully. Any last words before I commit this?

tarajunky

2010-10-08 15:30:34

FYI, I was getting false positives in Varrock West Bank with the new Forester detection.

Wanted

2010-10-08 15:41:49

Here is a more efficient

function InForesterRandom: Boolean;
var
Count, fX, fY: Integer;
Pts: TPointArray;
begin
if (CountColorTolerance(15726327, MMX1, MMY1, MMX2, MMY2, 30) < 40) then //White walls
if (not (InBlack)) then
begin
Pts := GetMiniMapDots('npc');
Count := Length(Pts);
if (Count < 10) then
Exit;
if (not (ForesterCenter(fX, fY))) then
Exit;
{$ifdef Simba}
FilterPointsDist(pts,0,50,fx,fy);
{$else}
FilterPointsPie(Pts, 0.0, 360.0, 0.0, 50.0, fX, fY);
{$endif}
Result := (Length(Pts) = count);
end;
end;

Short circuit evaluation.
More accurate wall color average lower tolerance.
Only calls the NPC dot collection one time.

We probably need another layer to the function to avoid false detections like what Tara's saying.

Also you can't do Result := Count > 9, it's not the same ;) the NPC dots before and after the filter need to be the same.

TRiLeZ

2010-10-08 16:36:56


function InForesterRandom: Boolean;
var
Count, fX, fY, CTS: Integer;
Hue, Sat: Extended;
Pts: TPointArray;
begin
GetColorspeed2Modifiers(Hue, Sat);
CTS := GetColorToleranceSpeed;
if (CountColorTolerance(15726327, MMX1, MMY1, MMX2, MMY2, 30) < 40) and //White walls
(not (InBlack)) then
begin
Pts := GetMiniMapDots('npc');
Count := Length(Pts);
if (Count < 10) then
Exit;
if (not (ForesterCenter(fX, fY))) then
Exit;
{$ifdef Simba}
FilterPointsDist(pts,0,50,fx,fy);
{$else}
FilterPointsPie(Pts, 0.0, 360.0, 0.0, 50.0, fX, fY);
{$endif}
if (Length(Pts) = count) then
begin
SetColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.67, 1.68);
if (PercentColorMM(1397036, 8) > 10) then
Result := True;
end;
end;
SetColorToleranceSpeed(CTS);
SetColorspeed2Modifiers(Hue, Sat);
end;

That code also checks to see how much of the minimap is covered in trees. Returns true if it's >10%.

Committing this now.

Wanted

2010-10-08 16:38:57

Why not use short circuit?

if (CountColorTolerance(15726327, MMX1, MMY1, MMX2, MMY2, 30) < 40) and //White walls
(not (InBlack)) then

->

if (CountColorTolerance(15726327, MMX1, MMY1, MMX2, MMY2, 30) < 40) then //White walls
if (not (InBlack)) then

TRiLeZ

2010-10-08 16:44:31

From: IceFire908
Why not use short circuit?

if (CountColorTolerance(15726327, MMX1, MMY1, MMX2, MMY2, 30) < 40) and //White walls
(not (InBlack)) then

->

if (CountColorTolerance(15726327, MMX1, MMY1, MMX2, MMY2, 30) < 40) then //White walls
if (not (InBlack)) then


What's the difference? I just like using less if statements if they aren't needed.

Wanted

2010-10-08 16:47:24

From: TRiLeZ
What's the difference? I just like using less if statements if they aren't needed.


It's important to stagger functions for efficiency, is you use and statements it will needlessly call every function in the statement if one of them fails already.

TRiLeZ

2010-10-08 16:52:42

From: IceFire908
It's important to stagger functions for efficiency, is you use and statements it will needlessly call every function in the statement if one of them fails already.



program new;

function a: boolean;
begin
Writeln('a');
Result := False;
end;

function b: boolean;
begin
Writeln('b');
Result := False;
end;

begin
if (a and b) then
Writeln('k');
end.

If one of the conditions is false, it will exit the statement.

Wanted

2010-10-08 16:59:05

Very interesting

program new;

function a: boolean;
begin
Wait(1000);
Writeln('a');
Result := False;
end;

function b: boolean;
begin
Wait(1000);
Writeln('b');
Result := False;
end;

function c: Boolean;
begin
Wait(1000);
Writeln('c');
Result := False;
end;

var
T: Integer;

begin
T := GetSystemTime;
if (a and b and c) then
Writeln('k');
WriteLn(GetSystemTime - T);
end.

Simba :

Compiled succesfully in 15 ms.
a
1107
Successfully executed.

SCAR 3.25

Successfully compiled (78 ms)
a
998
Successfully executed (998 ms)

but SCAR 3.23 and older

Successfully compiled (2568 ms)
a
b
c
2995
Successfully executed

Nice find.

NCDS

2010-10-08 17:24:14

Not going to lie, Squancy's main just got this random last night as I was going to bed and it failed so he asked me to fix it quick. So I fixed it, quick.

From: TRiLeZ
What are you talking about? The NPCs are still centre oriented…

I had it fail multiple times due to not finding NPC's before I removed the FilterPoints**.

From: TRiLeZ

Also, the npc dot colour didn't change. It's still 60909.


From: TRiLeZ

I made a new function:

function InForesterRandom: Boolean;
var
Count, fX, fY: Integer;
Pts: TPointArray;
begin
if (CountDots('npc') > 10) and (not InBlack) and
(CountColorTolerance(clWhite, MMX1, MMY1, MMX2, MMY2, 50) < 40) then //White walls
begin
Pts := GetMiniMapDots('npc');
Count := Length(Pts);
ForesterCenter(fX, fY);
{$ifdef Simba}
FilterPointsDist(pts,0,50,fx,fy);
{$else}
FilterPointsPie(Pts, 0.0, 360.0, 0.0, 50.0, fX, fY);
{$endif}
Result := (Length(Pts) = count);
end;
end;

Which works beautifully. Any last words before I commit this?

That's the original one jumbled into a single if..then with 20 changed to 40?

Nice to see people have the time to hop on this, but no one else seems to have the time to actually fix a random..

TRiLeZ

2010-10-08 18:17:22

From: NCDS
Nice to see people have the time to hop on this, but no one else seems to have the time to actually fix a random..


People are working on fixing the random solvers…

Naum

2010-10-08 18:30:56

We like to fix randoms by making sure the "fixes" actually work..

tarajunky

2010-10-08 20:01:55

Geez guys, he's fixed more randoms in the last month that others have in the last year. Cut him some slack.

Overtime

2010-10-09 00:08:15

The only reason "some" of the randoms are working is because of me and someone else. And maybe a couple of other people that keep sending him randoms.

But i guess most of ya'll forgot that he has MSI on his hands too.

And of course everyone just bashes his fixes, but they don't do anything to help fix them. :/

I believe he has fixed 5? or maybe a little more.

Anyways, keep up the work NCDS, your fix worked for me.

NCDS

2010-10-09 21:29:34

From: Squancy

Anyways, keep up the work NCDS, your fix worked for me.


Thanks, but no big deal.

I messed up. I should have just waited till morning to post it so I could have tested it better, and been able to think more clearly.

Anyway, I'm over it.

Wizzup?

2010-10-10 06:05:58

From: TRiLeZ
What are you talking about? The NPCs are still centre oriented…

Also, the npc dot colour didn't change. It's still 60909.

Your function would return true if there was an npc around the centre of the minimap and also if there was more than 10 npcs on the minimap.

Your function even returned true when I was in the rat pit, below varrock.

A reason why it could have been failing previously was the white wall counting mechanism. At the end of August, I changed the count of 20 to 40, to account players and whatnot, and it worked, but since I didn't have an SVN account at that time, I couldn't commit it so I posted it but it was never committed and was forgotten of.

I made a new function:

function InForesterRandom: Boolean;
var
Count, fX, fY: Integer;
Pts: TPointArray;
begin
if (CountDots('npc') > 10) and (not InBlack) and
(CountColorTolerance(clWhite, MMX1, MMY1, MMX2, MMY2, 50) < 40) then //White walls
begin
Pts := GetMiniMapDots('npc');
Count := Length(Pts);
ForesterCenter(fX, fY);
{$ifdef Simba}
FilterPointsDist(pts,0,50,fx,fy);
{$else}
FilterPointsPie(Pts, 0.0, 360.0, 0.0, 50.0, fX, fY);
{$endif}
Result := (Length(Pts) = count);
end;
end;

Which works beautifully. Any last words before I commit this?


Yeah. Once again, why use FilterPointsDist in Simba, and FilterPointsPie in SCAR?

TRiLeZ

2010-10-10 13:29:26

From: Wizzup?
Yeah. Once again, why use FilterPointsDist in Simba, and FilterPointsPie in SCAR?


I wasn't the one who came up with the idea of doing that, so I just left it like that.

Wanted

2010-10-10 14:41:52

From: Wizzup?
Yeah. Once again, why use FilterPointsDist in Simba, and FilterPointsPie in SCAR?


Ask Raymond, lol?