SRL Archive - SRL Archives

Drill Demon Solver fixed by TRiLeZ


TRiLeZ

2009-11-22 03:36:03

When I logged into one of my autoing accounts, I noticed it was in the drill demon random, so I decided to fix it…

It took me a few hours to fix it, and I'm finally done!!


We should talk to Damien.
Star
1: Push-up mat
2: Star Jump mat
3: Sit-up mat
4: Jog mat
Star
1: Jog mat
2: Sit-up mat
3: Push-up mat
4: Star Jump mat
Jog
1: Jog mat
2: Star Jump mat
3: Sit-up mat
4: Push-up mat
Jog
1: Star Jump mat
2: Jog mat
3: Sit-up mat
4: Push-up mat
Sit
1: Star Jump mat
2: Jog mat
3: Push-up mat
4: Sit-up mat
Demon random solved!
Successfully executed



{*******************************************************************************
function NoSignObstruction: Boolean;
by: Sumilion & ZephyrsFury, little modifiction by TRiLeZ
Description: Checks if the signs are fully visible.
*******************************************************************************}
function NoSignObstruction: Boolean;
var
arP: TPointArray;
ararP: T2DPointArray;
arC: TIntegerArray;
b: TBox;
i, j, x, y: Integer;
begin
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.12, 0.16);
try
FindColorsSpiralTolerance(MSX1, MSCY, arP, 6257516, MSX1, MSY1, MSX2, MSY2, 10);
if (Length(arP) = 0) then Exit;

ararP := TPAtoATPA(arP, 45);

if (Length(ararP) <> 4) then Exit;

for i := 0 to High(ararP) do
begin
SetLength(arP, 0);

b := GetTPABounds(ararP[i]);
for x := b.x1 - 1 to b.x2 + 1 do
begin
SetLength(arP, Length(arP) + 2);
arP[High(arP) - 1] := Point(x, b.y1 - 1);
arP[High(arP)] := Point(x, b.y2 + 1);
end;
for y := b.y1 - 1 to b.y2 + 1 do
begin
SetLength(arP, Length(arP) + 2);
arP[High(arP) - 1] := Point(b.x1 - 1, y);
arP[High(arP)] := Point(b.x2 + 1, y);
end;

arC := GetColors(arP);

for j := 0 to High(arC) do
begin
SetColorspeed2Modifiers(0.1, 0.58); // filling
Result := SimilarColors(3695936, arC[j], 4);
if not Result then
begin
SetColorSpeed2Modifiers(0.02, 0.09); // rims
Result := SimilarColors(3368054, arC[j], 8);
if (not(Result)) then Exit;
end;
end;

end;

finally
ColorToleranceSpeed(1);
SetColorspeed2Modifiers(0.2, 0.2);
end;
end;

{*******************************************************************************
function DemonCenter: Boolean;
by: TRiLeZ
Description: Walks to the center of the random.
*******************************************************************************}
function DemonCenter: Boolean;
var
cts, H, F: Integer;
arP: TPointarray;
P: TPoint;
SarP: T2DPointArray;
begin
cts := GetColorToleranceSpeed;
Mouse(543, 24, 12, 12, true);
Wait(150 + Random(200));
SetAngle(True);
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.77, 2.5);
if not FindColorsTolerance(arP, 3433847, MSX1, MSY1, MSX2, MSY2, 4) then
begin
Writeln('DemonCenter - Could not find the board colors.');
Exit;
end;

H := High(arP);
SarP := TPAtoATPA(arP, 50);
F := High(SarP);

if ((arP[0].x < MSCX) and (arP[H].x < MSCX)) or ((arP[0].x > MSCX) and
(arP[H].x > MSCX)) then
begin
if (arP[0].x < MSCX) and (arP[H].x < MSCX) then
begin
Writeln('DemonCenter - We are at the edge of the random area, fixing position.');
Mouse(MiddleTPA(SarP[Round(F/2)]).x, MiddleTPA(SarP[Round(F/2)]).y + 60, 10, 10, False);
WaitOption('Walk', 400);
Wait(2000);
FFlag(0);
Wait(2000 + Random(250));
end else
if (arP[0].x > MSCX) and (arP[H].x > MSCX) then
begin
Writeln('DemonCenter - We are at the edge of the random area, fixing position.');
Mouse(MiddleTPA(SarP[F]).x, MiddleTPA(SarP[F]).y + 60, 10, 10, False);
WaitOption('Walk', 400);
Wait(2000);
FFlag(0);
Wait(2000 + Random(250));
end;
if not FindColorsTolerance(arP, 3433847, MSX1, MSY1, MSX2, MSY2, 4) then
begin
Writeln('DemonCenter - Could not find the board colors.');
Exit;
end;
end;

Result := Length(arP) > 0;
P := MiddleTPA(arP);
if (IsUpText('Walk')) then
Mouse(P.X, P.Y + 50, 0, 0, True)
else
begin
Mouse(P.X, P.Y + 50, 0, 0, False);
ChooseOption('Walk');
end;
Wait(2000);
FFlag(0);
Wait(2000 + Random(250));
ColorToleranceSpeed(cts);
end;

{*******************************************************************************
procedure IdentifySigns(var JogIndex, StarIndex, SitIndex, PushIndex: Integer);
by: Sumilion, little modification by TRiLeZ
Description: Gets the actions on the signs.
*******************************************************************************}

procedure IdentifySigns(var JogIndex, StarIndex, SitIndex, PushIndex: Integer);
var
i, MinLength, MaxWidth: Integer;
arP: TPointArray;
ararP: T2DPointArray;
arColors: TIntegerArray;
b: TBox;
begin
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.12, 0.16);
FindColorsSpiralTolerance(MSX1, MSCY, arP, 6257516, MSX1, MSY1, MSX2, MSY2, 10);

ararP := TPAtoATPA(arP, 45);
if (Length(ararP) <> 4) then
Exit;

MinLength := 999;
for i := 0 to High(ararP) do
begin
if (Length(ararP[i]) < Minlength) then
begin
MinLength := Length(ararP[i]);
JogIndex := i + 1;
end;
end;

for i := 0 to High(ararP) do
begin
if (i = JogIndex - 1) then Continue;

b := GetTPABounds(ararP[i]);

if ((b.x2 - b.x1) > MaxWidth) then
begin
MaxWidth := b.x2 - b.x1;
PushIndex := i + 1;
end;
end;

for i := 0 to High(ararP) do
begin
if (i = JogIndex - 1) then Continue;
if (i = PushIndex - 1) then Continue;

arColors := GetColors(ararP[i]);
ClearSameIntegers(arColors);

if (Length(arColors) = 2) then
StarIndex := i + 1;
if (Length(arColors) = 1) then
SitIndex := i + 1;
end;
end;

{*******************************************************************************
function demon_GetTask: string;
by: TRiLeZ & Nielsie95
Description: Reads from Damien what we should do.
*******************************************************************************}

function demon_GetTask: string;
var
dx, dy, t, cts, q: Integer;
Tasks: TStringArray;
DRed, DBlack, TPA: TPointArray;
Demon: T2DPointArray;
begin
if not FindNPCChatText('Sergeant Damien', Nothing) then
begin
Writeln('We should talk to Damien.');
MarkTime(t);
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
repeat
SetColorspeed2Modifiers(0.1, 1.35);
FindColorsTolerance(DRed, 988783, MSX1, MSY1, MSX2, MSY2, 4);
SetColorspeed2Modifiers(0, 0);
FindColorsTolerance(DBlack, 789517, MSX1, MSY1, MSX2, MSY2, 3);
if (Length(DRed) > 0) and (Length(DBlack) > 0) then
begin
TPA := CombineTPA(DRed, DBlack);
Demon := SplitTPAEx(TPA, 20, 20);
SortATPAFrom(Demon, Point(MSCX, MSCY));
for q := 0 to High(Demon) do
begin
MiddleTPAEx(Demon[q], dx, dy);
MMouse(dx, dy, 2, 2);
if WaitUpText('Talk', 150) then
begin
GetMousePos(dx, dy);
Mouse(dx, dy, 0, 0, false);
Break;
end;
end;
end;
Wait(150 + Random(50));
until ChooseOption('to Se') or (TimeFromMark(t) > 30000);
ColorToleranceSpeed(cts);

if (TimeFromMark(t) > 30000) then
begin
Writeln('Can''t find Damien.');
LogOut
Exit;
end;

MarkTime(t);
while not FindNPCChatText('Sergeant Damien', Nothing) and
(TimeFromMark(t) < 30000) do
Wait(500 + Random(100));

if (TimeFromMark(t) > 30000) then
begin
Writeln('Failed to talk to Damien.');
LogOut;
Exit;
end;
end;

T := GetSystemTime;
while (not(FindNPCChatText('this mat', Nothing))) and
(ClickContinue(True, True)) and (GetSystemTime - T < 30000) do
Wait(100);

Tasks := ['jog', 'star', 'sit', 'push'];
for t := 0 to 3 do
if FindNPCChatText(Tasks[t], Nothing) then
begin
Result := Capitalize(Tasks[t]);
Break;
end;

if (Result = '') then
begin
Writeln('Can''t find what Damien wants us to do.');
LogOut;
Exit;
end;

ClickContinue(True, True);
ClickContinue(True, False);
end;

{*******************************************************************************
function PerformTask(TaskIndex: Integer): Boolean;
by: TRiLeZ
Description: Performs the correct workout.
*******************************************************************************}

function PerformTask(TaskIndex: Integer): Boolean;
var
arP: TPointArray;
tmpCTS, t, cx, cy: Integer;
SarP: T2DPointArray;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.12, 0.16);

if not(FindColorsTolerance(arP, 6257516, MSX1, MSY1, MSX2, MSY2, 10)) then
begin
Writeln('Failed to find the signs, no object found.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

SarP := TPAtoATPA(arP, 45);

if (Length(SarP) <> 4) then
begin
Writeln('Wrong Array Length, failed to find the mat.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
LogOut;
Exit;
end;

MiddleTPAEx(SarP[TaskIndex - 1], cx, cy);
MMouse(cx, cy + 65, 5, 5);
Wait(100 + Random(100));
if (IsUpText('ise mat')) then
begin;
Result := True;
GetMousePos(cx, cy);
Mouse(cx, cy, 0, 0, True);
Flag;
MarkTime(t);
while not FindNPCChatText('Sergeant Damien', Nothing) and
(TimeFromMark(t) < 20000) do
Wait(100 + Random(100));

if (TimeFromMark(t) > 20000) then
begin
Writeln('Task Timeout');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
LogOut;
Exit;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;

{*******************************************************************************
function GetSigns(var JogIndex, StarIndex, SitIndex, PushIndex: Integer): Boolean;
by: Sumilion & ZephyrsFury, little modification by TRiLeZ
Description: Handles the getting of the signs.
*******************************************************************************}

function GetSigns(var JogIndex, StarIndex, SitIndex, PushIndex: Integer): Boolean;
var
C, I: Integer;
begin
c := 0;
if not DemonCenter then
begin
Writeln('Failed to find the demon center.');
LogOut;
Exit;
end;
Mouse(543, 24, 12, 12, true);
Wait(150 + Random(200));
SetAngle(False);
JogIndex := 0;
StarIndex :=0;
SitIndex := 0;
PushIndex := 0;

while ((JogIndex = 0) or (StarIndex = 0) or (SitIndex = 0) or (PushIndex = 0)) and (c < 50) do
begin
JogIndex := 0; StarIndex := 0; SitIndex := 0; PushIndex := 0;
try
if (NoSignObstruction) then
IdentifySigns(JogIndex, StarIndex, SitIndex, PushIndex);
except end;
if ((JogIndex = 0) or (StarIndex = 0) or (SitIndex = 0) or (PushIndex = 0)) then
begin
Inc(c);
if ((c mod 7) = 0) then
MakeCompass('N');
if (c >= 50) then Break;
if (c mod 3 = 0) then
case Random(2) of
0:
begin
KeyDown(vk_Right);
Wait(60 + Random(25));
KeyUp(vk_Right);
end;
1:
begin
KeyDown(vk_Left);
Wait(60 + Random(25));
KeyUp(vk_Left);
end;
end;
Wait(150 + Random(150));
end;
end;
Mouse(543, 24, 12, 12, true);
Wait(150 + Random(200));
SetAngle(True);
Result := (JogIndex > 0) and (StarIndex > 0) and (SitIndex > 0) and (PushIndex > 0);

for i := 0 to 3 do
begin
if (JogIndex - 1 = i) then
Writeln(IntToStr(JogIndex) + ': Jog mat');
if (StarIndex - 1 = i) then
Writeln(IntToStr(StarIndex) + ': Star Jump mat');
if (PushIndex - 1 = i) then
Writeln(IntToStr(PushIndex) + ': Push-up mat');
if (SitIndex - 1 = i) then
Writeln(IntToStr(SitIndex) + ': Sit-up mat');
end;
end;

{*******************************************************************************
function SolveDemon: Boolean;
by: Sumilion
Description: Main solving procedure.
*******************************************************************************}

function SolveDemon: Boolean;
var
Task: string;
JogIndex, StarIndex, SitIndex, PushIndex, t: Integer;
begin
TakeScreen('Found Demon');
ClickContinue(True, True);
SetAngle(true);
MarkTime(t);
MakeCompass('N');
repeat;
Task := demon_GetTask;
Writeln(Task);

if (not(GetSigns(JogIndex, StarIndex, SitIndex, PushIndex))) then
begin
WriteLn('Could not identify demon signs.');
LogOut;
Exit;
end;

case Task of
'Jog': PerformTask(JogIndex);
'Star': PerformTask(StarIndex);
'Sit': PerformTask(SitIndex);
'Push': PerformTask(PushIndex);
end;

Wait(100 + Random(200));

if FindNPCChatText('Wrong exercise', Nothing) then
Writeln('Wrong exercise.');

until FindNPCChatText('actually', Nothing) or (TimeFromMark(t) > 5 * 60 * 1000);

if (TimeFromMark(t) > 5 * 60 * 1000) then
begin
Writeln('We''ve been in the demon random for 5 minutes. It failed.');
LogOut;
Exit;
end;

Writeln('Demon random solved!');
Result := True;
ClickContinue(True, True);
Wait(10000);
end;

The first problem that I noticed with the old solver was the the Demon finding function was so slow that it couldn't talk to the Demon (I was wearing red). I fixed that by using a T2DPointArray using the black and red colours of the Demon.

The next problem was that DemonCenter was broken so I had to change some colours, tolerance and modifiers around to make it work again (maybe more than that, I don't remember).

I did the same thing with IdentifySigns as DemonCenter.

I then changed GetSigns around a little bit.

I then remade most of PerformTask. It seemed like it wouldn't even have worked when the solver had been made.

After all of that hard work, I finally made the solver work! Hopefully, better than before. :D

ZephyrsFury

2009-11-22 09:48:17

Thanks for this. :)

It's having trouble talking to Damien and clicking the centre though. It seems the black colour (Damien's horns I assume) isn't being found so talking to Damien ends up failing. Clicking the centre of the random doesn't seem to be working for me either.

I also noticed that when you're already in a convo with Damien but the jog, sit, star jump, w/e text isn't there the solver quits rather than clicking continue until those actions appear.

You should add this to line 223:


T := GetSystemTime;
while (not(FindNPCChatText('this mat', Nothing))) and (ClickContinue(True, True)) and (GetSystemTime - T < 30000) do
Wait(100);

Good work though. :)

Wanted

2009-11-22 09:52:32

If someone can give me some definitive code, I can test this with the account I have in it right now.

TRiLeZ

2009-11-22 17:13:27

It worked perfect for me… Could someone give me an account so I can do some further testing?

Wanted

2009-11-23 12:39:59

Just tested.

Looks like walk to center worked, but then it failed right after.

Star
Could not identify demon signs.

JAD

2009-11-23 16:58:27

s/modifiction by TRiLeZ/modification by TRiLeZ/

:)

TRiLeZ

2009-11-23 19:56:26

I just updated the solver, I increased the tolerance of a lot of things and changed the board colours because 2 sections of the ground were the same colour as the boards. Another feature I added was I made the solver walk more in the centre of the random if its at the west or east edge of the random area and then try to find the centre of the random (to make DemonCenter more accurate).

Give thanks to ZephyrsFury for lending me an account. :)

Wanted

2009-11-23 20:07:09

From: TRiLeZ
I just updated the solver, I increased the tolerance of a lot of things and changed the board colours because 2 sections of the ground were the same colour as the boards. Another feature I added was I made the solver walk more in the centre of the random if its at the west or east edge of the random area and then try to find the centre of the random (to make DemonCenter more accurate).

Give thanks to ZephyrsFury for lending me an account. :)


Will test soon

Wanted

2009-11-23 20:56:43

program New;

{.Include SRL\SRL\Misc\SMART.SCAR}
{.Include SRL\SRL.SCAR}

var
T: LongInt;

begin
Smart_Server := 38;
Smart_Members := False;
Smart_Signed := True;
Smart_SuperDetail := False;
SetUpSRL;
Wait(1000);
T := GetSystemTime;
SolveDemon;
WriteLn(GetSystemTime - T);
end.

Successfully compiled (4799 ms)
SRL Compiled in 31 msec
SMART Initialized.
Loaded: Server 38, Members: False, Signed: True, Super Detail: False.
Push
Could not identify demon signs.
43328
Successfully executed

Still doesn't work.

ZephyrsFury

2009-11-25 00:38:14

Got an account in the random today, decide to try run it. Made some modifcations to your version up there:


//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- » Drill Demon Solver Routines --//
//-----------------------------------------------------------------//
// * function NoSignObstruction: Boolean; // * by Sumilion, ZephyrsFury & TRiLeZ
// * function DemonCenter: Boolean; // * by TRiLeZ
// * procedure IdentifySigns(var JogIndex, StarIndex, SitIndex, PushIndex: Integer); // * by Sumilion & TRiLeZ
// * function demon_GetTask: string; // * by TRiLeZ & Nielsie95
// * function PerformTask(TaskIndex: Integer): Boolean; // * by Sumilion
// * function GetSigns(var JogIndex, StarIndex, SitIndex, PushIndex: Integer): Boolean; // * by Sumilion , ZephyrsFury & TRiLez
// * function SolveDemon: Boolean; // * by Sumilion
//-----------------------------------------------------------------//

{*******************************************************************************
function NoSignObstruction: Boolean;
by: Sumilion & ZephyrsFury, little modifiction by TRiLeZ
Description: Checks if the signs are fully visible.
*******************************************************************************}
function NoSignObstruction: Boolean;
var
arP: TPointArray;
ararP: T2DPointArray;
arC: TIntegerArray;
b: TBox;
i, j, x, y: Integer;
begin
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.12, 0.16);
try
FindColorsSpiralTolerance(MSX1, MSCY, arP, 6257516, MSX1, MSY1, MSX2, MSY2, 10);
if (Length(arP) = 0) then Exit;

ararP := SplitTPA(arP, 10);

if (Length(ararP) <> 4) then Exit;

for i := 0 to High(ararP) do
begin
SetLength(arP, 0);

b := GetTPABounds(ararP[i]);
for x := b.x1 - 1 to b.x2 + 1 do
begin
SetLength(arP, Length(arP) + 2);
arP[High(arP) - 1] := Point(x, b.y1 - 1);
arP[High(arP)] := Point(x, b.y2 + 1);
end;
for y := b.y1 - 1 to b.y2 + 1 do
begin
SetLength(arP, Length(arP) + 2);
arP[High(arP) - 1] := Point(b.x1 - 1, y);
arP[High(arP)] := Point(b.x2 + 1, y);
end;

arC := GetColors(arP);

for j := 0 to High(arC) do
begin
SetColorspeed2Modifiers(0.1, 0.58); // filling
Result := SimilarColors(3695936, arC[j], 4);
if not Result then
begin
SetColorSpeed2Modifiers(0.06, 0.15); // rims
Result := SimilarColors(2971495, arC[j], 11);
if (not(Result)) then Exit;
end;
end;

end;

finally
ColorToleranceSpeed(1);
SetColorspeed2Modifiers(0.2, 0.2);
end;
end;

{*******************************************************************************
function DemonCenter: Boolean;
by: TRiLeZ
Description: Walks to the center of the random.
*******************************************************************************}

function DemonCenter: Boolean;
var
cts, H, F: Integer;
arP: TPointarray;
P: TPoint;
SarP: T2DPointArray;
begin
cts := GetColorToleranceSpeed;
Mouse(543, 24, 12, 12, true);
Wait(150 + Random(200));
SetAngle(True);
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.77, 2.5);
if not FindColorsTolerance(arP, 3433847, MSX1, MSY1, MSX2, MSY2, 6) then
begin
Writeln('DemonCenter - Could not find the board colors.');
Exit;
end;

H := High(arP);
SarP := TPAtoATPA(arP, 50);
F := High(SarP);

if ((arP[0].x < MSCX) and (arP[H].x < MSCX)) or ((arP[0].x > MSCX) and
(arP[H].x > MSCX)) then
begin
if (arP[0].x < MSCX) and (arP[H].x < MSCX) then
begin
Writeln('DemonCenter - We are at the edge of the random area, fixing position.');
Mouse(MiddleTPA(SarP[Round(F/2)]).x, MiddleTPA(SarP[Round(F/2)]).y + 60, 10, 10, False);
WaitOption('Walk', 400);
Wait(2000);
FFlag(0);
Wait(2000 + Random(250));
end else
if (arP[0].x > MSCX) and (arP[H].x > MSCX) then
begin
Writeln('DemonCenter - We are at the edge of the random area, fixing position.');
Mouse(MiddleTPA(SarP[F]).x, MiddleTPA(SarP[F]).y + 60, 10, 10, False);
WaitOption('Walk', 400);
Wait(2000);
FFlag(0);
Wait(2000 + Random(250));
end;
if not FindColorsTolerance(arP, 3433847, MSX1, MSY1, MSX2, MSY2, 4) then
begin
Writeln('DemonCenter - Could not find the board colors.');
Exit;
end;
end;

Result := Length(arP) > 0;
P := MiddleTPA(arP);
if (IsUpText('Walk')) then
Mouse(P.X, P.Y + 50, 0, 0, True)
else
begin
Mouse(P.X, P.Y + 50, 0, 0, False);
ChooseOption('Walk');
end;
Wait(2000);
FFlag(0);
Wait(2000 + Random(250));
ColorToleranceSpeed(cts);
end;

{*******************************************************************************
procedure IdentifySigns(var JogIndex, StarIndex, SitIndex, PushIndex: Integer);
by: Sumilion, little modification by TRiLeZ
Description: Gets the actions on the signs.
*******************************************************************************}

procedure IdentifySigns(var JogIndex, StarIndex, SitIndex, PushIndex: Integer);
var
i, MinLength, MaxWidth: Integer;
arP: TPointArray;
ararP: T2DPointArray;
arColors: TIntegerArray;
b: TBox;
begin
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.12, 0.16);
FindColorsSpiralTolerance(MSX1, MSCY, arP, 6257516, MSX1, MSY1, MSX2, MSY2, 10);

ararP := TPAtoATPA(arP, 45);
if (Length(ararP) <> 4) then
Exit;

MinLength := 999;
for i := 0 to High(ararP) do
begin
if (Length(ararP[i]) < Minlength) then
begin
MinLength := Length(ararP[i]);
JogIndex := i + 1;
end;
end;

for i := 0 to High(ararP) do
begin
if (i = JogIndex - 1) then Continue;

b := GetTPABounds(ararP[i]);

if ((b.x2 - b.x1) > MaxWidth) then
begin
MaxWidth := b.x2 - b.x1;
PushIndex := i + 1;
end;
end;

for i := 0 to High(ararP) do
begin
if (i = JogIndex - 1) then Continue;
if (i = PushIndex - 1) then Continue;

arColors := GetColors(ararP[i]);
ClearSameIntegers(arColors);

if (Length(arColors) = 2) then
StarIndex := i + 1;
if (Length(arColors) = 1) then
SitIndex := i + 1;
end;
end;

{*******************************************************************************
function demon_GetTask: string;
by: TRiLeZ & Nielsie95
Description: Reads from Damien what we should do.
*******************************************************************************}

function demon_GetTask: string;
var
dx, dy, t, cts, q: Integer;
Tasks: TStringArray;
DRed, DBlack, TPA: TPointArray;
Demon: T2DPointArray;
begin
if not FindNPCChatText('Sergeant Damien', Nothing) then
begin
Writeln('We should talk to Damien.');
MarkTime(t);
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
repeat
SetColorspeed2Modifiers(0.1, 1.35);
FindColorsTolerance(DRed, 988783, MSX1, MSY1, MSX2, MSY2, 4);
SetColorspeed2Modifiers(0, 0);
FindColorsTolerance(DBlack, 789517, MSX1, MSY1, MSX2, MSY2, 3);
if (Length(DRed) > 0) and (Length(DBlack) > 0) then
begin
TPA := CombineTPA(DRed, DBlack);
Demon := SplitTPAEx(TPA, 20, 20);
SortATPAFrom(Demon, Point(MSCX, MSCY));
for q := 0 to High(Demon) do
begin
MiddleTPAEx(Demon[q], dx, dy);
MMouse(dx, dy, 2, 2);
if WaitUpText('Talk', 150) then
begin
GetMousePos(dx, dy);
Mouse(dx, dy, 0, 0, false);
Break;
end;
end;
end;
Wait(150 + Random(50));
until ChooseOption('to Se') or (TimeFromMark(t) > 30000);
ColorToleranceSpeed(cts);

if (TimeFromMark(t) > 30000) then
begin
Writeln('Can''t find Damien.');
LogOut
Exit;
end;

MarkTime(t);
while not FindNPCChatText('Sergeant Damien', Nothing) and
(TimeFromMark(t) < 30000) do
Wait(500 + Random(100));

if (TimeFromMark(t) > 30000) then
begin
Writeln('Failed to talk to Damien.');
LogOut;
Exit;
end;
end;

T := GetSystemTime;
while (not(FindNPCChatText('this mat', Nothing))) and
(ClickContinue(True, True)) and (GetSystemTime - T < 30000) do
Wait(100);

Tasks := ['jog', 'star', 'sit', 'push'];
for t := 0 to 3 do
if FindNPCChatText(Tasks[t], Nothing) then
begin
Result := Capitalize(Tasks[t]);
Break;
end;

if (Result = '') then
begin
Writeln('Can''t find what Damien wants us to do.');
LogOut;
Exit;
end;

ClickContinue(True, True);
ClickContinue(True, False);
end;

{*******************************************************************************
function PerformTask(TaskIndex: Integer): Boolean;
by: Sumilion
Description: Performs the correct workout.
*******************************************************************************}

function PerformTask(TaskIndex: Integer): Boolean;
var
arP, arAP: TPointArray;
arC, arUC: TIntegerArray;
ararP: T2DPointArray;
tmpCTS, i, j, arL, arL2, t: Integer;
X, Y, Z: Extended;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.06, 0.15);

if not(FindColorsTolerance(arP, 2971495, MSX1, MSY1, MSX2, MSY2, 11)) then
begin
Writeln('Failed to find the signs, no object found.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

arC := GetColors(arP);
arUC := arC;
ClearSameIntegers(arUC);
arL := High(arUC);
arL2 := High(arC);

for i := 0 to arL do
begin
ColorToXYZ(arC[i], X, Y, Z);

if (X >= 6.61) and (X <= 19.45) and (Y >= 7.00) and (Y <= 20.47) and (Z >= 2.28) and (Z <= 6.43) then
begin
for j := 0 to arL2 do
begin
if (arUC[i] = arC[j]) then
begin
SetLength(arAP, Length(arAP) + 1);
arAP[High(arAP)] := arP[j];
end;
end;
end;
end;

ararP := SplitTPAEx(arAP, 10, 10);
arL := High(ararP);
SetLength(arP, 0);

for i := 0 to arL do
begin
if (Length(ararP[i]) < 100) then Continue;
if (Length(ararP[i]) > 250) then Continue;
SetLength(arP, Length(arP) + 1);
arP[High(arP)] := MiddleTPA(ararP[i]);
end;

SortTPAFrom(arP, Point(MSX1, MSCY));

if (Length(arP) <> 4) then
begin
Writeln('Wrong Array Length, failed to find the mat.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
LogOut;
Exit;
end;

MMouse(arP[TaskIndex - 1].x, arP[TaskIndex - 1].y + 65, 5, 5);
Wait(100 + Random(100));
if (IsUpText('Exercise')) then
begin;
Result := True;
GetMousePos(arP[TaskIndex - 1].x, arP[TaskIndex - 1].y);
Mouse(arP[TaskIndex - 1].x, arP[TaskIndex - 1].y, 0, 0, True);
Flag;
MarkTime(t);
while not FindNPCChatText('Sergeant Damien', Nothing) and
(TimeFromMark(t) < 20000) do
Wait(100 + Random(100));

if (TimeFromMark(t) > 20000) then
begin
Writeln('Task Timeout');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
LogOut;
Exit;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;

{*******************************************************************************
function GetSigns(var JogIndex, StarIndex, SitIndex, PushIndex: Integer): Boolean;
by: Sumilion & ZephyrsFury, little modification by TRiLeZ
Description: Handles the getting of the signs.
*******************************************************************************}

function GetSigns(var JogIndex, StarIndex, SitIndex, PushIndex: Integer): Boolean;
var
C, I: Integer;
begin
c := 0;
if not DemonCenter then
begin
Writeln('Failed to find the demon center.');
LogOut;
Exit;
end;
Mouse(543, 24, 12, 12, true);
Wait(150 + Random(200));
SetAngle(False);
JogIndex := 0;
StarIndex :=0;
SitIndex := 0;
PushIndex := 0;

while ((JogIndex = 0) or (StarIndex = 0) or (SitIndex = 0) or (PushIndex = 0)) and (c < 50) do
begin
JogIndex := 0; StarIndex := 0; SitIndex := 0; PushIndex := 0;
try
if (NoSignObstruction) then
IdentifySigns(JogIndex, StarIndex, SitIndex, PushIndex);
except end;
if ((JogIndex = 0) or (StarIndex = 0) or (SitIndex = 0) or (PushIndex = 0)) then
begin
Inc(c);
if (c = 20) then
MakeCompass('N');
if (c >= 40) then Break;
if (c mod 3 = 0) then
if (c < 20) then
begin
KeyDown(vk_Right);
Wait(60 + Random(25));
KeyUp(vk_Right);
end else
begin
KeyDown(vk_Left);
Wait(60 + Random(25));
KeyUp(vk_Left);
end;
Wait(150 + Random(150));
end;
end;
Mouse(543, 24, 12, 12, true);
Wait(150 + Random(200));
SetAngle(True);
Result := (JogIndex > 0) and (StarIndex > 0) and (SitIndex > 0) and (PushIndex > 0);

for i := 0 to 3 do
begin
if (JogIndex - 1 = i) then
Writeln(IntToStr(JogIndex) + ': Jog mat');
if (StarIndex - 1 = i) then
Writeln(IntToStr(StarIndex) + ': Star Jump mat');
if (PushIndex - 1 = i) then
Writeln(IntToStr(PushIndex) + ': Push-up mat');
if (SitIndex - 1 = i) then
Writeln(IntToStr(SitIndex) + ': Sit-up mat');
end;
end;

{*******************************************************************************
function SolveDemon: Boolean;
by: Sumilion
Description: Main solving procedure.
*******************************************************************************}

function SolveDemon: Boolean;
var
Task: string;
JogIndex, StarIndex, SitIndex, PushIndex, t: Integer;
begin
TakeScreen('Found Demon');
ClickContinue(True, True);
SetAngle(true);
MarkTime(t);
MakeCompass('N');
repeat;
Task := demon_GetTask;
Writeln(Task);

if (not(GetSigns(JogIndex, StarIndex, SitIndex, PushIndex))) then
begin
WriteLn('Could not identify demon signs.');
LogOut;
Exit;
end;

case Task of
'Jog': PerformTask(JogIndex);
'Star': PerformTask(StarIndex);
'Sit': PerformTask(SitIndex);
'Push': PerformTask(PushIndex);
end;

Wait(100 + Random(200));

if FindNPCChatText('Wrong exercise', Nothing) then
Writeln('Wrong exercise.');

until FindNPCChatText('actually', Nothing) or (TimeFromMark(t) > 10 * 60 * 1000);

if (TimeFromMark(t) > 10 * 60 * 1000) then
begin
Writeln('We''ve been in the demon random for 10 minutes. It failed.');
LogOut;
Exit;
end;

Writeln('Demon random solved!');
Result := True;
ClickContinue(True, True);
Wait(10000);
end;

I used Sumilion's PerformTask function because I couldn't get your one to work and Sum's only needed a new colour and tolerance to work.

If anyone can confirm if this works I'll commit it. (I'll prob commit it anyway since it has a better chance of working than the old one at least).

TRiLeZ

2009-12-05 19:21:28

YoHoJo gave me an account the the Demon random and I got to test the Demon Solver again. There was only one problem, DemonCenter. I just had to decrease the tolerance to identify the boards. :D Now it works beautifully.


//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- » Drill Demon Solver Routines --//
//-----------------------------------------------------------------//
// * function NoSignObstruction: Boolean; // * by Sumilion, ZephyrsFury & TRiLeZ
// * function DemonCenter: Boolean; // * by TRiLeZ
// * procedure IdentifySigns(var JogIndex, StarIndex, SitIndex, PushIndex: Integer); // * by Sumilion & TRiLeZ
// * function demon_GetTask: string; // * by TRiLeZ & Nielsie95
// * function PerformTask(TaskIndex: Integer): Boolean; // * by Sumilion
// * function GetSigns(var JogIndex, StarIndex, SitIndex, PushIndex: Integer): Boolean; // * by Sumilion , ZephyrsFury & TRiLez
// * function SolveDemon: Boolean; // * by Sumilion
//-----------------------------------------------------------------//

{*******************************************************************************
function NoSignObstruction: Boolean;
by: Sumilion & ZephyrsFury, little modifiction by TRiLeZ
Description: Checks if the signs are fully visible.
*******************************************************************************}
function NoSignObstruction: Boolean;
var
arP: TPointArray;
ararP: T2DPointArray;
arC: TIntegerArray;
b: TBox;
i, j, x, y: Integer;
begin
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.12, 0.16);
try
FindColorsSpiralTolerance(MSX1, MSCY, arP, 6257516, MSX1, MSY1, MSX2, MSY2, 10);
if (Length(arP) = 0) then Exit;

ararP := SplitTPA(arP, 10);

if (Length(ararP) <> 4) then Exit;

for i := 0 to High(ararP) do
begin
SetLength(arP, 0);

b := GetTPABounds(ararP[i]);
for x := b.x1 - 1 to b.x2 + 1 do
begin
SetLength(arP, Length(arP) + 2);
arP[High(arP) - 1] := Point(x, b.y1 - 1);
arP[High(arP)] := Point(x, b.y2 + 1);
end;
for y := b.y1 - 1 to b.y2 + 1 do
begin
SetLength(arP, Length(arP) + 2);
arP[High(arP) - 1] := Point(b.x1 - 1, y);
arP[High(arP)] := Point(b.x2 + 1, y);
end;

arC := GetColors(arP);

for j := 0 to High(arC) do
begin
SetColorspeed2Modifiers(0.1, 0.58); // filling
Result := SimilarColors(3695936, arC[j], 4);
if not Result then
begin
SetColorSpeed2Modifiers(0.06, 0.15); // rims
Result := SimilarColors(2971495, arC[j], 11);
if (not(Result)) then Exit;
end;
end;

end;

finally
ColorToleranceSpeed(1);
SetColorspeed2Modifiers(0.2, 0.2);
end;
end;

{*******************************************************************************
function DemonCenter: Boolean;
by: TRiLeZ
Description: Walks to the center of the random.
*******************************************************************************}

function DemonCenter: Boolean;
var
cts, H, F: Integer;
arP: TPointarray;
P: TPoint;
SarP: T2DPointArray;
begin
cts := GetColorToleranceSpeed;
Mouse(543, 24, 12, 12, true);
Wait(150 + Random(200));
SetAngle(True);
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.77, 2.5);
if not FindColorsTolerance(arP, 3433847, MSX1, MSY1, MSX2, MSY2, 4) then
begin
Writeln('DemonCenter - Could not find the board colors.');
Exit;
end;

H := High(arP);
SarP := TPAtoATPA(arP, 50);
F := High(SarP);

if ((arP[0].x < MSCX) and (arP[H].x < MSCX)) or ((arP[0].x > MSCX) and
(arP[H].x > MSCX)) then
begin
if (arP[0].x < MSCX) and (arP[H].x < MSCX) then
begin
Writeln('DemonCenter - We are at the edge of the random area, fixing position.');
Mouse(MiddleTPA(SarP[Round(F/2)]).x, MiddleTPA(SarP[Round(F/2)]).y + 60, 10, 10, False);
WaitOption('Walk', 400);
Wait(2000);
FFlag(0);
Wait(2000 + Random(250));
end else
if (arP[0].x > MSCX) and (arP[H].x > MSCX) then
begin
Writeln('DemonCenter - We are at the edge of the random area, fixing position.');
Mouse(MiddleTPA(SarP[F]).x, MiddleTPA(SarP[F]).y + 60, 10, 10, False);
WaitOption('Walk', 400);
Wait(2000);
FFlag(0);
Wait(2000 + Random(250));
end;
if not FindColorsTolerance(arP, 3433847, MSX1, MSY1, MSX2, MSY2, 4) then
begin
Writeln('DemonCenter - Could not find the board colors.');
Exit;
end;
end;

Result := Length(arP) > 0;
P := MiddleTPA(arP);
if (IsUpText('Walk')) then
Mouse(P.X, P.Y + 50, 0, 0, True)
else
begin
Mouse(P.X, P.Y + 50, 0, 0, False);
ChooseOption('Walk');
end;
Wait(2000);
FFlag(0);
Wait(2000 + Random(250));
ColorToleranceSpeed(cts);
end;

{*******************************************************************************
procedure IdentifySigns(var JogIndex, StarIndex, SitIndex, PushIndex: Integer);
by: Sumilion, little modification by TRiLeZ
Description: Gets the actions on the signs.
*******************************************************************************}

procedure IdentifySigns(var JogIndex, StarIndex, SitIndex, PushIndex: Integer);
var
i, MinLength, MaxWidth: Integer;
arP: TPointArray;
ararP: T2DPointArray;
arColors: TIntegerArray;
b: TBox;
begin
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.12, 0.16);
FindColorsSpiralTolerance(MSX1, MSCY, arP, 6257516, MSX1, MSY1, MSX2, MSY2, 10);

ararP := TPAtoATPA(arP, 45);
if (Length(ararP) <> 4) then
Exit;

MinLength := 999;
for i := 0 to High(ararP) do
begin
if (Length(ararP[i]) < Minlength) then
begin
MinLength := Length(ararP[i]);
JogIndex := i + 1;
end;
end;

for i := 0 to High(ararP) do
begin
if (i = JogIndex - 1) then Continue;

b := GetTPABounds(ararP[i]);

if ((b.x2 - b.x1) > MaxWidth) then
begin
MaxWidth := b.x2 - b.x1;
PushIndex := i + 1;
end;
end;

for i := 0 to High(ararP) do
begin
if (i = JogIndex - 1) then Continue;
if (i = PushIndex - 1) then Continue;

arColors := GetColors(ararP[i]);
ClearSameIntegers(arColors);

if (Length(arColors) = 2) then
StarIndex := i + 1;
if (Length(arColors) = 1) then
SitIndex := i + 1;
end;
end;

{*******************************************************************************
function demon_GetTask: string;
by: TRiLeZ & Nielsie95
Description: Reads from Damien what we should do.
*******************************************************************************}

function demon_GetTask: string;
var
dx, dy, t, cts, q: Integer;
Tasks: TStringArray;
DRed, DBlack, TPA: TPointArray;
Demon: T2DPointArray;
begin
if not FindNPCChatText('Sergeant Damien', Nothing) then
begin
Writeln('We should talk to Damien.');
MarkTime(t);
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
repeat
SetColorspeed2Modifiers(0.1, 1.35);
FindColorsTolerance(DRed, 988783, MSX1, MSY1, MSX2, MSY2, 4);
SetColorspeed2Modifiers(0, 0);
FindColorsTolerance(DBlack, 789517, MSX1, MSY1, MSX2, MSY2, 3);
if (Length(DRed) > 0) and (Length(DBlack) > 0) then
begin
TPA := CombineTPA(DRed, DBlack);
Demon := SplitTPAEx(TPA, 20, 20);
SortATPAFrom(Demon, Point(MSCX, MSCY));
for q := 0 to High(Demon) do
begin
MiddleTPAEx(Demon[q], dx, dy);
MMouse(dx, dy, 2, 2);
if WaitUpText('Talk', 150) then
begin
GetMousePos(dx, dy);
Mouse(dx, dy, 0, 0, false);
Break;
end;
end;
end;
Wait(150 + Random(50));
until ChooseOption('to Se') or (TimeFromMark(t) > 30000);
ColorToleranceSpeed(cts);

if (TimeFromMark(t) > 30000) then
begin
Writeln('Can''t find Damien.');
LogOut
Exit;
end;

MarkTime(t);
while not FindNPCChatText('Sergeant Damien', Nothing) and
(TimeFromMark(t) < 30000) do
Wait(500 + Random(100));

if (TimeFromMark(t) > 30000) then
begin
Writeln('Failed to talk to Damien.');
LogOut;
Exit;
end;
end;

T := GetSystemTime;
while (not(FindNPCChatText('this mat', Nothing))) and
(ClickContinue(True, True)) and (GetSystemTime - T < 30000) do
Wait(100);

Tasks := ['jog', 'star', 'sit', 'push'];
for t := 0 to 3 do
if FindNPCChatText(Tasks[t], Nothing) then
begin
Result := Capitalize(Tasks[t]);
Break;
end;

if (Result = '') then
begin
Writeln('Can''t find what Damien wants us to do.');
LogOut;
Exit;
end;

ClickContinue(True, True);
ClickContinue(True, False);
end;

{*******************************************************************************
function PerformTask(TaskIndex: Integer): Boolean;
by: Sumilion
Description: Performs the correct workout.
*******************************************************************************}

function PerformTask(TaskIndex: Integer): Boolean;
var
arP, arAP: TPointArray;
arC, arUC: TIntegerArray;
ararP: T2DPointArray;
tmpCTS, i, j, arL, arL2, t: Integer;
X, Y, Z: Extended;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.06, 0.15);

if not(FindColorsTolerance(arP, 2971495, MSX1, MSY1, MSX2, MSY2, 11)) then
begin
Writeln('Failed to find the signs, no object found.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

arC := GetColors(arP);
arUC := arC;
ClearSameIntegers(arUC);
arL := High(arUC);
arL2 := High(arC);

for i := 0 to arL do
begin
ColorToXYZ(arC[i], X, Y, Z);

if (X >= 6.61) and (X <= 19.45) and (Y >= 7.00) and (Y <= 20.47) and (Z >= 2.28) and (Z <= 6.43) then
begin
for j := 0 to arL2 do
begin
if (arUC[i] = arC[j]) then
begin
SetLength(arAP, Length(arAP) + 1);
arAP[High(arAP)] := arP[j];
end;
end;
end;
end;

ararP := SplitTPAEx(arAP, 10, 10);
arL := High(ararP);
SetLength(arP, 0);

for i := 0 to arL do
begin
if (Length(ararP[i]) < 100) then Continue;
if (Length(ararP[i]) > 250) then Continue;
SetLength(arP, Length(arP) + 1);
arP[High(arP)] := MiddleTPA(ararP[i]);
end;

SortTPAFrom(arP, Point(MSX1, MSCY));

if (Length(arP) <> 4) then
begin
Writeln('Wrong Array Length, failed to find the mat.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
LogOut;
Exit;
end;

MMouse(arP[TaskIndex - 1].x, arP[TaskIndex - 1].y + 65, 5, 5);
Wait(100 + Random(100));
if (IsUpText('Exercise')) then
begin;
Result := True;
GetMousePos(arP[TaskIndex - 1].x, arP[TaskIndex - 1].y);
Mouse(arP[TaskIndex - 1].x, arP[TaskIndex - 1].y, 0, 0, True);
Flag;
MarkTime(t);
while not FindNPCChatText('Sergeant Damien', Nothing) and
(TimeFromMark(t) < 20000) do
Wait(100 + Random(100));

if (TimeFromMark(t) > 20000) then
begin
Writeln('Task Timeout');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
LogOut;
Exit;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;

{*******************************************************************************
function GetSigns(var JogIndex, StarIndex, SitIndex, PushIndex: Integer): Boolean;
by: Sumilion & ZephyrsFury, little modification by TRiLeZ
Description: Handles the getting of the signs.
*******************************************************************************}

function GetSigns(var JogIndex, StarIndex, SitIndex, PushIndex: Integer): Boolean;
var
C, I: Integer;
begin
c := 0;
if not DemonCenter then
begin
Writeln('Failed to find the demon center.');
LogOut;
Exit;
end;
Mouse(543, 24, 12, 12, true);
Wait(150 + Random(200));
SetAngle(False);
JogIndex := 0;
StarIndex :=0;
SitIndex := 0;
PushIndex := 0;

while ((JogIndex = 0) or (StarIndex = 0) or (SitIndex = 0) or (PushIndex = 0)) and (c < 50) do
begin
JogIndex := 0; StarIndex := 0; SitIndex := 0; PushIndex := 0;
try
if (NoSignObstruction) then
IdentifySigns(JogIndex, StarIndex, SitIndex, PushIndex);
except end;
if ((JogIndex = 0) or (StarIndex = 0) or (SitIndex = 0) or (PushIndex = 0)) then
begin
Inc(c);
if (c = 20) then
MakeCompass('N');
if (c >= 40) then Break;
if (c mod 3 = 0) then
if (c < 20) then
begin
KeyDown(vk_Right);
Wait(60 + Random(25));
KeyUp(vk_Right);
end else
begin
KeyDown(vk_Left);
Wait(60 + Random(25));
KeyUp(vk_Left);
end;
Wait(150 + Random(150));
end;
end;
Mouse(543, 24, 12, 12, true);
Wait(150 + Random(200));
SetAngle(True);
Result := (JogIndex > 0) and (StarIndex > 0) and (SitIndex > 0) and (PushIndex > 0);

for i := 0 to 3 do
begin
if (JogIndex - 1 = i) then
Writeln(IntToStr(JogIndex) + ': Jog mat');
if (StarIndex - 1 = i) then
Writeln(IntToStr(StarIndex) + ': Star Jump mat');
if (PushIndex - 1 = i) then
Writeln(IntToStr(PushIndex) + ': Push-up mat');
if (SitIndex - 1 = i) then
Writeln(IntToStr(SitIndex) + ': Sit-up mat');
end;
end;

{*******************************************************************************
function SolveDemon: Boolean;
by: Sumilion
Description: Main solving procedure.
*******************************************************************************}

function SolveDemon: Boolean;
var
Task: string;
JogIndex, StarIndex, SitIndex, PushIndex, t: Integer;
begin
TakeScreen('Found Demon');
ClickContinue(True, True);
SetAngle(true);
MarkTime(t);
MakeCompass('N');
repeat;
Task := demon_GetTask;
Writeln(Task);

if (not(GetSigns(JogIndex, StarIndex, SitIndex, PushIndex))) then
begin
WriteLn('Could not identify demon signs.');
LogOut;
Exit;
end;

case Task of
'Jog': PerformTask(JogIndex);
'Star': PerformTask(StarIndex);
'Sit': PerformTask(SitIndex);
'Push': PerformTask(PushIndex);
end;

Wait(100 + Random(200));

if FindNPCChatText('Wrong exercise', Nothing) then
Writeln('Wrong exercise.');

until FindNPCChatText('actually', Nothing) or (TimeFromMark(t) > 10 * 60 * 1000);

if (TimeFromMark(t) > 10 * 60 * 1000) then
begin
Writeln('We''ve been in the demon random for 10 minutes. It failed.');
LogOut;
Exit;
end;

Writeln('Demon random solved!');
Result := True;
ClickContinue(True, True);
Wait(10000);
end;

TRiLeZ

2009-12-09 17:56:16

Jagex changed the color of the Demon's horns. =/ I guess they don't like my solver. At least now his horns are all one color :D


{*******************************************************************************
function demon_GetTask: string;
by: TRiLeZ & Nielsie95
Description: Reads from Damien what we should do.
*******************************************************************************}

function demon_GetTask: string;
var
dx, dy, t, cts, q: Integer;
Tasks: TStringArray;
DRed, DBlack, TPA: TPointArray;
Demon: T2DPointArray;
begin
if not FindNPCChatText('Sergeant Damien', Nothing) then
begin
Writeln('We should talk to Damien.');
MarkTime(t);
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
repeat
SetColorspeed2Modifiers(0.1, 1.35);
FindColorsTolerance(DRed, 988783, MSX1, MSY1, MSX2, MSY2, 4);
SetColorspeed2Modifiers(0, 3.71);
FindColorsTolerance(DBlack, 855309, MSX1, MSY1, MSX2, MSY2, 3);
if (Length(DRed) > 0) and (Length(DBlack) > 0) then
begin
TPA := CombineTPA(DRed, DBlack);
Demon := SplitTPAEx(TPA, 20, 20);
SortATPAFrom(Demon, Point(MSCX, MSCY));
for q := 0 to High(Demon) do
begin
MiddleTPAEx(Demon[q], dx, dy);
MMouse(dx, dy, 2, 2);
if WaitUpText('Talk', 150) then
begin
GetMousePos(dx, dy);
Mouse(dx, dy, 0, 0, false);
Break;
end;
end;
end;
Wait(150 + Random(50));
until ChooseOption('to Se') or (TimeFromMark(t) > 30000);
ColorToleranceSpeed(cts);

if (TimeFromMark(t) > 30000) then
begin
Writeln('Can''t find Damien.');
LogOut
Exit;
end;

MarkTime(t);
while not FindNPCChatText('Sergeant Damien', Nothing) and
(TimeFromMark(t) < 30000) do
Wait(500 + Random(100));

if (TimeFromMark(t) > 30000) then
begin
Writeln('Failed to talk to Damien.');
LogOut;
Exit;
end;
end;

T := GetSystemTime;
while (not(FindNPCChatText('this mat', Nothing))) and
(ClickContinue(True, True)) and (GetSystemTime - T < 30000) do
Wait(100);

Tasks := ['jog', 'star', 'sit', 'push'];
for t := 0 to 3 do
if FindNPCChatText(Tasks[t], Nothing) then
begin
Result := Capitalize(Tasks[t]);
Break;
end;

if (Result = '') then
begin
Writeln('Can''t find what Damien wants us to do.');
LogOut;
Exit;
end;

ClickContinue(True, True);
ClickContinue(True, False);
end;

855309 is the new horn color, which you'll see has tolerance just incase the color slightly changes.

Wanted

2009-12-09 21:08:45

Why were you using the horn color? Wouldn't it be a lot better to use the red demon skin?

TRiLeZ

2009-12-09 23:32:26

From: IceFire908
Why were you using the horn color? Wouldn't it be a lot better to use the red demon skin?


Accuracy. (I'm using a T2DPointArray)

Wanted

2009-12-09 23:33:38

From: TRiLeZ
Accuracy. (I'm using a T2DPointArray)


Yea, wouldn't it be more accurate to use something that takes up 80% of his body surface area and do MiddleTPA?

TRiLeZ

2009-12-10 00:04:34

From: IceFire908
Yea, wouldn't it be more accurate to use something that takes up 80% of his body surface area and do MiddleTPA?


He's wearing green camo so… the best I can get is about 40% of his body with one color.

It used one color before I changed this solver up. The problem with using one color is that if the character is also wearing the same color, the mouse would go over the char then to the demon then to…. once the mouse got to the demon, the demon had already moved on. Maybe that was just the function that went slow. But anyways, my function is very accurate, fast and works.

footballjds

2009-12-10 00:10:47

TRiLeZ,
If you're having trouble with it recognizing your character as the Demon i suggest "skipping" your character(SkipBox). Even better if you found the Demon's yellow dot on the MM and used that point along with some math(slightly complicated) to figure out his apprx. MS location. From that you can then search for him :p
just ideas

marpis

2009-12-10 04:27:24

From: footballjds
TRiLeZ,
If you're having trouble with it recognizing your character as the Demon i suggest "skipping" your character(SkipBox). Even better if you found the Demon's yellow dot on the MM and used that point along with some math(slightly complicated) to figure out his apprx. MS location. From that you can then search for him :p
just ideas


Good idea, there's already a function
FindObjectViaMM()
Or something like that, that uses MMtoMS() :)

footballjds

2009-12-11 12:30:16

yeah, i knew there was MMto MS but its not 100% accurate. but it sure helps :D
i didn't know there was a FindObjectViaMM()… there wasn't last time i was around (6months?)

TRiLeZ

2009-12-11 23:48:42

I'll work on making a better Demon solver when I have time and when I have another account in the Demon random.

Is anyone going to commit my latest update to the solver? We want to have the least amount of broken / slightly broken random solver don't we?

ZephyrsFury

2009-12-12 02:50:28

From: TRiLeZ
I'll work on making a better Demon solver when I have time and when I have another account in the Demon random.

Is anyone going to commit my latest update to the solver? We want to have the least amount of broken / slightly broken random solver don't we?


Its in my SRL, I'll commit when I get the change. Anyway, the key solver functions seem to work fine (such as the sigh identification). There's no point in making a new one, just fixing up any remaining bugs in the current one.