SRL Archive - SRL Archives

Function InBlack: Boolean; UPDATED!


JuKKa

2007-09-11 10:05:04

LOL this is my second function i updated, This time i made it a little less code and also my opinnion better here let me explain:

With mine you can use it at the mining guild, Stronghold and any other black areas without returning TRUE!

The old "InBlack" checked with "GetColor" it could return true in most black areas.

But with mine you use "FindColorsTolerance" to search for the black color "0" and then it will return in percent how much black there is on the MM, And if it returns over the insterted number it will then result True.

Of course mine might be 0-15 msec slower but its alot more relieable (When using in places with a black minimap)


function InBlack: Boolean; // random detector. Checks for 4 black dots in MM.
begin
if (GetColor(650, 155) = 0) then
begin
if ((GetColor(650, 145) = 0) and
(GetColor(650, 135) = 0) and
(GetColor(650, 125) = 0)) then
begin
Result := True;
Exit;
end
else
Result := False;
end
if (GetColor(650, 15) = 0) then
begin
if ((GetColor(650, 25) = 0) and
(GetColor(650, 35) = 0) and
(GetColor(650, 45) = 0)) then
begin
Result := True;
Exit;
end
else
Result := False;
end
if (GetColor(580, 82) = 0) then
begin
if ((GetColor(590, 82) = 0) and
(GetColor(600, 82) = 0) and
(GetColor(610, 82) = 0)) then
begin
Result := True;
Exit;
end
else
Result := False;
end
if (GetColor(714, 82) = 0) then
begin
if ((GetColor(704, 82) = 0) and
(GetColor(694, 82) = 0) and
(GetColor(684, 82) = 0)) then
begin
Result := True;
Exit;
end
else
Result := False;
end
end;

As u can see the old one has ALOT of code when mine is 1/3 of that.

heres mine:

Function InBlackInPut(AtPercent: Integer): Boolean;
Var
Black: TPointArray;
Percent, AllColors, BlackColors: Integer;
Begin
FindColorsTolerance(Black, 0, MMX1, MMY1, MMX2, MMY2, 0);
BlackColors:= GetArrayLength(Black);
AllColors := BlackColors + 26565;
Percent:= (BlackColors * 100) / AllColors;
If(Percent >= AtPercent)Then
Result:= True;
End;

Shortly how to use:
Function InBlackInPut(Percent: Integer): Boolean;

You insert a percent (integer) when it finds more black (in percent) it will return true!

20-30 is a good number.

And i would be honoured if this would be added in the SRL 4!

Who was it that loved to see when function get reduced by XX amount of lines?

n3ss3s

2007-09-11 10:13:18

Looks good, —> SRL?

Pentti

2007-09-11 10:35:09

Btw, you dont need:
else
Result := False;

Ja vittu mul on tänää synttärit! Muhaha. :D

JuKKa

2007-09-11 10:39:10

From: Pentti
Btw, you dont need:
else
Result := False;

Ja vittu mul on tänää synttärit! Muhaha. :D


I dont have eighter? The one in SRL has it though

VITTU ONNEE :D! mulla oli eile :D:D ;) nykyää oon 15 :P

Pentti

2007-09-11 10:55:38

From: JuKKa
I dont have eighter? The one in SRL has it though

VITTU ONNEE :D! mulla oli eile :D:D ;) nykyää oon 15 :P

Aijaa. No myöhäset onnittelut sullekki. :D

And oh, that above was from SRL… I should have known because it looked terrible. :D Haha, yours is better. But does it work in essence mining rooms?

JuKKa

2007-09-11 11:01:28

From: Pentti

I should have known because it looked terrible. :D Haha, yours is better. But does it work in essence mining rooms?


I have no idea, Havent tested but im 80% sure it does, With the right inputted percent

Wizzup?

2007-09-11 13:01:17

From: JuKKa
LOL this is my second function i updated, This time i made it a little less code and also my opinnion better here let me explain:

With mine you can use it at the mining guild, Stronghold and any other black areas without returning TRUE!

The old "InBlack" checked with "GetColor" it could return true in most black areas.

But with mine you use "FindColorsTolerance" to search for the black color "0" and then it will return in percent how much black there is on the MM, And if it returns over the insterted number it will then result True.

Of course mine might be 0-15 msec slower but its alot more relieable (When using in places with a black minimap)


function InBlack: Boolean; // random detector. Checks for 4 black dots in MM.
begin
if (GetColor(650, 155) = 0) then
begin
if ((GetColor(650, 145) = 0) and
(GetColor(650, 135) = 0) and
(GetColor(650, 125) = 0)) then
begin
Result := True;
Exit;
end
else
Result := False;
end
if (GetColor(650, 15) = 0) then
begin
if ((GetColor(650, 25) = 0) and
(GetColor(650, 35) = 0) and
(GetColor(650, 45) = 0)) then
begin
Result := True;
Exit;
end
else
Result := False;
end
if (GetColor(580, 82) = 0) then
begin
if ((GetColor(590, 82) = 0) and
(GetColor(600, 82) = 0) and
(GetColor(610, 82) = 0)) then
begin
Result := True;
Exit;
end
else
Result := False;
end
if (GetColor(714, 82) = 0) then
begin
if ((GetColor(704, 82) = 0) and
(GetColor(694, 82) = 0) and
(GetColor(684, 82) = 0)) then
begin
Result := True;
Exit;
end
else
Result := False;
end
end;

As u can see the old one has ALOT of code when mine is 1/3 of that.

heres mine:

Function InBlackInPut(AtPercent: Integer): Boolean;
Var
Black: TPointArray;
Percent, AllColors, BlackColors: Integer;
Begin
FindColorsTolerance(Black, 0, MMX1, MMY1, MMX2, MMY2, 0);
BlackColors:= GetArrayLength(Black);
AllColors := BlackColors + 26892;
Percent:= (BlackColors * 100) / AllColors;
If(Percent >= AtPercent)Then
Result:= True;
End;

Shortly how to use:
Function InBlackInPut(Percent: Integer): Boolean;

You insert a percent (integer) when it finds more black (in percent) it will return true!

20-30 is a good number.

And i would be honoured if this would be added in the SRL 4!

Who was it that loved to see when function get reduced by XX amount of lines?


15ms is alot.

BTW, I take it that 26892 is the amount of pixels on the MM?
Then do this:

AllColors := 26892;
BlackColors := Length(Black);
Percent := BlackColors / AllColors * 100; // Should be extended.


But really, FindColorsTolerance which has to 'write' alot of points to the result is slow. :)

I get the point, but InBlack is only for Randoms that are totally black, like Pinball for example, or quiz.

JuKKa

2007-09-11 13:53:02

From: Wizzup?

I get the point, but InBlack is only for Randoms that are totally black, like Pinball for example, or quiz.


Yes but if u call it in places like dwarfen mine, Stronghold it could return true and resulting the player to false.

Wizzup?

2007-09-11 14:16:24

From: JuKKa
Yes but if u call it in places like dwarfen mine, Stronghold it could return true and resulting the player to false.


Yes, thats why it could be an good addition, not to antirandoms, but to a different core (MapWalk?) include.

Did you consider my small different way of getting the percent?

R0b0t1

2007-09-11 16:50:32

Wizzup? seems more active…

Nice function, but I don't use InBlack that liberally.

Bobarkinator

2007-09-11 21:07:56

I thought InBlack only checked the center of the Minimap?

JuKKa

2007-09-11 23:18:47

From: Wizzup?
Did you consider my small different way of getting the percent?


Like so?

Function InBlackInPut(AtPercent: Extended): Boolean;
Var
Black: TPointArray;
AllColors, BlackColors: Integer;
Percent: Extended;
Begin
FindColorsTolerance(Black, 0, MMX1, MMY1, MMX2, MMY2, 0);
AllColors := 26565;
BlackColors := Length(Black);
Percent := BlackColors / AllColors * 100;
If(Percent >= AtPercent)Then
Result:= True;
End;

Pyro

2007-09-12 01:37:38

I know you said it COULD return true. But have you tried it? So far 0 false returns while in mining guild.///

JuKKa

2007-09-12 01:55:54

From: Pyro
I know you said it COULD return true. But have you tried it? So far 0 false returns while in mining guild.///


Odd.. i tested it once and returned true, But i know it has problems in the stronghold area.

Whatever but i think this is a bit more relieable function than the one in SRL, And alot less code too, Though wizzup might be right that its a bit slow…

However im gonna use this in my upcoming guild miner ;) just to be safe ..

Wizzup?

2007-09-12 02:04:56

From: JuKKa
Like so?

Function InBlackInPut(AtPercent: Extended): Boolean;
Var
Black: TPointArray;
AllColors, BlackColors: Integer;
Percent: Extended;
Begin
FindColorsTolerance(Black, 0, MMX1, MMY1, MMX2, MMY2, 0);
AllColors := 26892;
BlackColors := Length(Black);
Percent := BlackColors / AllColors * 100;
If(Percent >= AtPercent)Then
Result:= True;
End;


Yes, like that.

JuKKa

2007-09-12 02:09:48

Found a small error AllColors should be: '26565'

R0b0t1

2007-09-12 17:23:05

Wanna know how to speed a lot of stuff up?


Have freddy turn it into bytecode. (Like obfuscated scripts?)