SRL Archive - Senior Scripts and Snippets

BeeKeeper Random Solver


Town

2007-10-14 20:55:17

This was pretty much a full days work, which in total was about 6 hours of the better part of my day. Most of which was trying things that didn't work and I just had to scrap and start over.

But– I got it working perfectly now. I'm not sure if the SRL needs a solver in it, if not I'll just post it down in the snippets forum.

If some of the code looks kind of funny it's because I did part of it about a month ago and the rest of it today so I may have forgotten a thing or two. Either way, it works. If something is very wrong then let me know.

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

var
x, y: Integer;
Bee: Array[0..3] of Integer;
BoxArray: TBoxArray;
Done: Array[0..3] of Boolean;

procedure DeclareDTMs;
begin
Bee[3] := DTMFromString('78DA63DCC6C0C0709D0105AC5DB890811F483' +
'302F17F20603C0F64BC4555B36CF62CB81A10609C0324DEA1AA59' +
'3C633AAA9A2940E226AA9A6DAB57A1AAB90C246EA1AA99DCD989A' +
'20600DCDF158B');
Bee[2] := DTMFromString('78DA6364666460F8C08002440405192481345' +
'086E13F10303E07321EA2AAD9B369135C0D0830CA02590F50D5AC' +
'9C3B17558D2290F50555CDCCFE3E54354F1830D4EC58BB16450D0' +
'045CA132D');
Bee[1] := DTMFromString('78DA6364656460B8C48002766FDCC8C00FA48' +
'1320CFF8180F12590710C55CDA15D3BE16A4080F10990B883AAE6' +
'E89E3DA86A9480ACE3A86A56CD9B8BAA460DC8BA8BAA66D6847E5' +
'435FF31EDDAB96E2DAA1A5E4CBBB6AC5A89A2060093191BA1');
Bee[0] := DTMFromString('78DA639CCDC0C0708701055CBF7491811F483' +
'302F17F2060AC05329EA3AA7970FB365C0D0830760289CBA86A9E' +
'3F7982AA662690388DAAE6C2C993A86AD600896BA86AF66DD982A' +
'A662BA67B56CF9F8FAA660E90788DAA66D7860D286A0066D81EFE' +
'');
SetArrayLength(BoxArray, 11);
BoxArray[0].x1 := 0;
BoxArray[0].y1 := 0;
BoxArray[0].x2 := 26;
BoxArray[0].y2 := 338;
BoxArray[1].x1 := 0;
BoxArray[1].y1 := 0;
BoxArray[1].x2 := 515;
BoxArray[1].y2 := 50;
BoxArray[2].x1 := 495;
BoxArray[2].y1 := 31;
BoxArray[2].x2 := 516;
BoxArray[2].y2 := 338;
BoxArray[3].x1 := 19;
BoxArray[3].y1 := 304;
BoxArray[3].x2 := 515;
BoxArray[3].y2 := 337;
BoxArray[4].x1 := 86;
BoxArray[4].y1 := 226;
BoxArray[4].x2 := 516;
BoxArray[4].y2 := 304;
BoxArray[5].x1 := 179;
BoxArray[5].y1 := 28;
BoxArray[5].x2 := 193;
BoxArray[5].y2 := 226;
BoxArray[6].x1 := 325;
BoxArray[6].y1 := 27;
BoxArray[6].x2 := 340;
BoxArray[6].y2 := 226;
BoxArray[7].x1 := 191;
BoxArray[7].y1 := 71;
BoxArray[7].x2 := 326;
BoxArray[7].y2 := 77;
BoxArray[8].x1 := 191;
BoxArray[8].y1 := 123;
BoxArray[8].x2 := 325;
BoxArray[8].y2 := 131;
BoxArray[9].x1 := 191;
BoxArray[9].y1 := 174;
BoxArray[9].x2 := 325;
BoxArray[9].y2 := 185;
BoxArray[10].x1 := 426;
BoxArray[10].y1 := 192;
BoxArray[10].x2 := 516;
BoxArray[10].y2 := 338;
end;

function ConvertTPAToBox(TPA: TPointArray): TBoxArray;
var
i: Integer;
begin
SetArrayLength(Result, GetArrayLength(TPA));
for i := 0 to GetArrayLength(TPA) - 1 do
begin
Result[i].X1 := TPA[i].x - 1; Result[i].X2 := TPA[i].x + 1;
Result[i].Y1 := TPA[i].y - 1; Result[i].Y1 := TPA[i].y + 1;
end;
end;

function AddBoxArray(Box1, Box2: TBoxArray): TBoxArray;
var
i: Integer;
begin
SetArrayLength(Result, GetArrayLength(Box1));
for i := 0 to GetArrayLength(Box2) - 1 do
begin
SetArrayLength(Result, GetArrayLength(Result) + 1);
Result[GetArrayLength(Result) - 1].X1 := Box2[i].X1;
Result[GetArrayLength(Result) - 1].X2 := Box2[i].X2;
Result[GetArrayLength(Result) - 1].Y1 := Box2[i].Y1;
Result[GetArrayLength(Result) - 1].Y2 := Box2[i].Y2;
end;
end;

procedure TalkTo; // Talks to Bee Keeper
var
Points: TPointArray;
i: Integer;
PointBox: TBoxArray;
begin
if (not (LoggedIn)) then Exit;
FindColorsTolerance(Points, 10329514, MSX1, MSY1, MSX2, MSY2, 30);
PointBox := ConvertTPAToBox(Points);
BoxArray := AddBoxArray(PointBox, BoxArray);
FindColorsTolerance(Points, 5000274, MSCX + 20, MSCY - 35, MSCX + 65, MSCY + 35, 25);
if (GetArrayLength(Points) = 0) then Logout;
if (not (LoggedIn)) then Exit;
for i := 0 to GetArrayLength(Points) - 1 do
begin
MMouse(Points[i].x, Points[i].y, 2, 2);
Wait(250 + Random(450));
if (IsUpText('alk')) then Break;
if (i = GetArrayLength(Points) - 1) then
begin
Logout;
Exit;
end;
end;
GetMousePos(x, y);
Mouse(x, y, 2, 2, true);
MarkTime(i);
repeat
if (ClickToContinue) then MarkTime(i);
Wait(1000 + Random(1000));
until (TimeFromMark(i) > 8000);
end;

procedure MovePiece(Num: Integer);
begin
case Num of
1: MouseBox(138, 279, 159, 292, True);
2: MouseBox(191, 268, 209, 284, True);
3: MouseBox(303, 281, 328, 288, True);
4: MouseBox(357, 283, 380, 289, True);
end;
end;

procedure MoveToCorner(Num: Integer); // Moves each piece to the corner so they aren't overlapping
var
p, i: Integer;
begin
if (not (LoggedIn)) then Exit;
case Num of
1: begin
repeat
MovePiece(1);
for i := 0 to 4 do
begin
Wait(100 + Random(400));
if (FindDTM(Bee[Num - 1], x, y, MSX1, MSY1, MSX2, 80)) then Break;
end;
until (FindDTM(Bee[Num - 1], x, y, MSX1, MSY1, MSX2, 80));
repeat
MovePiece(3);
for i := 0 to 4 do
begin
Wait(100 + Random(400));
if (FindDTM(Bee[Num - 1], x, y, MSX1, MSY1, 100, 80)) then
begin
Done[0] := True;
Exit;
end;
end;
until (FindDTM(Bee[Num - 1], x, y, MSX1, MSY1, 100, 80));
end;
2: begin
repeat
MovePiece(3);
for i := 0 to 4 do
begin
Wait(100 + Random(400));
if (FindDTM(Bee[Num - 1], x, y, MSX1, MSY1, 105, MSY2)) then Break;
end;
until (FindDTM(Bee[Num - 1], x, y, MSX1, MSY1, 105, MSY2));
repeat
MovePiece(2);
for i := 0 to 4 do
begin
Wait(100 + Random(400));
if (FindDTM(Bee[Num - 1], x, y, MSX1, 190, 105, 230)) then
begin
Done[1] := True;
Exit;
end;
end;
until (FindDTM(Bee[Num - 1], x, y, MSX1, 190, 105, 230));
end;
3: begin
repeat
MovePiece(1);
for i := 0 to 4 do
begin
Wait(100 + Random(400));
if (FindDTM(Bee[Num - 1], x, y, MSX1, MSY1, MSX2, 85)) then Break;
end;
until (FindDTM(Bee[Num - 1], x, y, MSX1, MSY1, MSX2, 85));
repeat
MovePiece(4);
for i := 0 to 4 do
begin
Wait(100 + Random(400));
if (FindDTM(Bee[Num - 1], x, y, 400, MSY1, MSX2, 85)) then
begin
Done[2] := True;
Exit;
end;
end;
until (FindDTM(Bee[Num - 1], x, y, 400, MSY1, MSX2, 85));
end;
4: begin
repeat
MovePiece(4);
for i := 0 to 4 do
begin
Wait(100 + Random(400));
if (FindDTM(Bee[Num - 1], x, y, 350, MSY1, MSX2, MSY2)) then Break;
end;
p := p + 1;
until (p > 16 + Random(3) + Random(4)); // I call it "quality over perfection" as opposed to "quality of quantity"
repeat
MovePiece(2);
for i := 0 to 4 do
begin
Wait(100 + Random(400));
if (FindDTM(Bee[Num - 1], x, y, 400, MSY1, MSX2, MSY2))
or (not (FindDTM(Bee[Num - 1], x, y, MSX1, MSY1, MSX2, MSY2))) then
begin
Done[3] := True;
Exit;
end;
end;
until (FindDTM(Bee[Num - 1], x, y, 400, 200, MSX2, 250));
end;
end;
end;


procedure MoveToSpot(Num: Integer); // Moves pieces from the corners to their spots
var
i: Integer;
begin
if (not (LoggedIn)) then Exit;
case Num of
1: Mouse(56, 52, 8, 8, true);
2: Mouse(66, 216, 8, 8, true);
3: Mouse(436, 67, 8, 8, true);
4: Mouse(425, 216, 8, 8, true);
end;
case Num of
1: repeat
MovePiece(4);
for i := 0 to 5 do
begin
Wait(100 + Random(400));
if (FindDTM(Bee[Num - 1], x, y, 210, 25, 310, 75)) then
begin
Done[0] := True;
Exit;
end;
end;
until (FindDTM(Bee[Num - 1], x, y, 210, 25, 310, 75));
2: begin
repeat
MovePiece(4);
for i := 0 to 4 do
begin
Wait(100 + Random(400));
if (FindDTM(Bee[Num - 1], x, y, 210, 195, 310, 240)) then Break;
end;
until (FindDTM(Bee[Num - 1], x, y, 210, 195, 310, 240));
repeat
MovePiece(1);
for i := 0 to 5 do
begin
Wait(100 + Random(400));
if (FindDTM(Bee[Num - 1], x, y, 210, 80, 310, 125)) then
begin
Done[1] := True;
Exit;
end;
end;
until (FindDTM(Bee[Num - 1], x, y, 210, 80, 310, 125));
end;
3: begin
repeat
MovePiece(2);
for i := 0 to 4 do
begin
Wait(100 + Random(400));
if (FindDTM(Bee[Num - 1], x, y, 400, 140, MSX2, 175)) then Break;
end;
until (FindDTM(Bee[Num - 1], x, y, 400, 140, MSX2, 175));
repeat
MovePiece(3);
for i := 0 to 5 do
begin
Wait(100 + Random(400));
if (FindDTM(Bee[Num - 1], x, y, 210, 140, 310, 175)) then
begin
Done[2] := True;
Exit;
end;
end;
until (FindDTM(Bee[Num - 1], x, y, 210, 140, 310, 175));
end;
4: begin
repeat
MovePiece(3);
for i := 0 to 5 do
begin
Wait(100 + Random(400));
if (FindDTM(Bee[Num - 1], x, y, 210, 185, 310, 245)) then Break;
end;
until (FindDTM(Bee[Num - 1], x, y, 210, 185, 310, 245));
repeat
MovePiece(1);
for i := 0 to 5 do
begin
Wait(100 + Random(400));
if (FindDTM(Bee[Num - 1], x, y, 210, 185, 310, 230)) then
begin
Done[3] := True;
Exit;
end;
end;
until (FindDTM(Bee[Num - 1], x, y, 210, 185, 310, 245));
end;
end;
end;

function FindFirstPiece: TPoint; // Finds a piece that has not been moved yet
var
Cur: Integer;
begin
repeat
if (not (LoggedIn)) then Exit;
if (FindColorSkipBoxArrayTolerance(x, y, 10329514, MSX1, MSY1, MSX2, MSY2, 30, BoxArray)) then
begin
// WriteLN('x: ' + IntToStr(x) + ' y: ' + IntToStr(y));
Cur := GetColor(x, y);
Wait(10);
if (GetColor(x, y) = Cur) then
begin
SetArrayLength(BoxArray, GetArrayLength(BoxArray) + 1);
BoxArray[GetArrayLength(BoxArray) - 1].x1 := x - 1;
BoxArray[GetArrayLength(BoxArray) - 1].x2 := x + 1;
BoxArray[GetArrayLength(BoxArray) - 1].y1 := y - 1;
BoxArray[GetArrayLength(BoxArray) - 1].y2 := y + 1;
end else Break;
end else
begin
Result.y := -1;
Exit;
end;
until (false);
Mouse(x, y, 2, 2, false);
Wait(250 + Random(450));
if (ChooseOption('Ok')) then
begin
Result.x := x;
Result.y := y;
Exit;
end else
begin
SetArrayLength(BoxArray, GetArrayLength(BoxArray) + 1);
BoxArray[GetArrayLength(BoxArray) - 1].x1 := x - 1;
BoxArray[GetArrayLength(BoxArray) - 1].x2 := x + 1;
BoxArray[GetArrayLength(BoxArray) - 1].y1 := y - 1;
BoxArray[GetArrayLength(BoxArray) - 1].y2 := y + 1;
Result.x := -1;
end;
end;

function MoveFirstPiece: Integer; // Moves piece to the bottem so it can be identified
var
Coord: TPoint;
i: Integer;
begin
repeat
Coord := FindFirstPiece;
if (Coord.x > 0) and (Coord.y > 0) then Break;
if (Coord.y = 0) then MMouse(641, 298, 40, 40);
Wait(100 + Random(1900));
if (not (LoggedIn)) then Exit;
until (false);
if (Coord.x < 200) then
begin
MovePiece(4);
Wait(100 + Random(400));
if (Coord.x < 175) then
begin
MovePiece(4);
Wait(100 + Random(400));
if (Coord.x < 150) then
begin
MovePiece(4);
Wait(100 + Random(400));
if (Coord.x < 125) then
begin
MovePiece(4);
Wait(100 + Random(400));
if (Coord.x < 100) then
begin
MovePiece(4);
Wait(100 + Random(400));
if (Coord.x < 80) then
begin
MovePiece(4);
Wait(100 + Random(400));
end;
end;
end;
end;
end;
end;
repeat
MovePiece(2);
for i := 0 to 3 do
if (FindDTM(Bee[i], x, y, 60, MSCY + 27, MSX2 - 150, MSY2)) then
begin
case i of
0: begin
SetArrayLength(BoxArray, GetArrayLength(BoxArray) + 1);
BoxArray[GetArrayLength(BoxArray) - 1].x1 := 25;
BoxArray[GetArrayLength(BoxArray) - 1].x2 := 110;
BoxArray[GetArrayLength(BoxArray) - 1].y1 := 30;
BoxArray[GetArrayLength(BoxArray) - 1].y2 := 100;
end;
1: begin
SetArrayLength(BoxArray, GetArrayLength(BoxArray) + 1);
BoxArray[GetArrayLength(BoxArray) - 1].x1 := 25;
BoxArray[GetArrayLength(BoxArray) - 1].x2 := 105;
BoxArray[GetArrayLength(BoxArray) - 1].y1 := 170;
BoxArray[GetArrayLength(BoxArray) - 1].y2 := 225;
end;
2: begin
SetArrayLength(BoxArray, GetArrayLength(BoxArray) + 1);
BoxArray[GetArrayLength(BoxArray) - 1].x1 := 385;
BoxArray[GetArrayLength(BoxArray) - 1].x2 := MMX2;
BoxArray[GetArrayLength(BoxArray) - 1].y1 := 30;
BoxArray[GetArrayLength(BoxArray) - 1].y2 := 115;
end;
3: begin
SetArrayLength(BoxArray, GetArrayLength(BoxArray) + 1);
BoxArray[GetArrayLength(BoxArray) - 1].x1 := 395;
BoxArray[GetArrayLength(BoxArray) - 1].x2 := MMX2;
BoxArray[GetArrayLength(BoxArray) - 1].y1 := 200;
BoxArray[GetArrayLength(BoxArray) - 1].y2 := MMY2;
end;
end;
Result := i + 1;
WriteLN(IntToStr(i));
Exit;
end;
Wait(100 + Random(400));
until (not (LoggedIn));
end;

function SolveBeeKeeper: Boolean; // Main loop
var
i: Integer;
begin
DeclareDTMs;
TalkTo;
repeat
i := MoveFirstPiece;
MoveToCorner(i);
if (Done[0] = True) and (Done[1] = True) and (Done[2] = True) and (Done[3] = True) then Break;
until (not (LoggedIn));
for i := 0 to 3 do
Done[i] := False;
i := 1;
repeat
MoveToSpot(i);
i := i + 1;
if (Done[0] = True) and (Done[1] = True) and (Done[2] = True) and (Done[3] = True) then Break;
until (not (LoggedIn));
Mouse(257, 279, 4, 4, true); // Clicks build
for i := 0 to 50 do
begin
if (not (InBlack)) then
begin
Result := True;
Break;
end;
Wait(100);
if (i = 50) then
begin
Mouse(498, 20, 4, 4, true);
Wait(1000 + Random(1000));
if (Sec) then
begin
Result := False;
Logout;
Exit;
end;
Sec := True;
SolveBeeKeeper;
end;
end;
end;

begin
SetupSRL;
ActivateClient;
Wait(1000 + Random(1000));
SolveBeeKeeper;
end.

shaunthasheep

2007-10-15 09:56:02

I can't test it, but the function IntToBox(x1, y1, x2, y2) may help you :)

Town

2007-10-15 10:22:53

If anything I would have used function 'cBoxArray1(p1, p2: TPointArray): TBoxArray;' which I can find in SRL 3.6 but not in 4.0. Since there are so many points the larger box that my function makes can make a difference in how long it takes later on.

SKy Scripter

2007-10-15 13:28:33

do you have a pic of the random?

Town

2007-10-15 14:45:46


Off the Runescape page. If I get the random then I can let you use the account if you want to see it.

Basically, he teleports you there. You talk to him, interface pops up. Four pieces pop up that rotate like the mysterious box at different speeds. You click the pieces and use the arrows to move them to their spots, an example of the finished product is in the picture. Then, you click the middle build button.

Randoms page —> http://www.runescape.com/kbase/viewarticle.ws?article_id=1907

– In a nut shell -


SKy Scripter

2007-10-16 09:29:27

oh ok i had this random before, good job :). thats if it works good :p

Town

2007-10-16 14:21:49

I've got the random on one of my characters now. If anyone is interested then PM me for the username and password.

SKy Scripter

2007-10-16 15:18:19

hehehe im interested. ;)

Town

2007-10-16 16:14:05

I just remade a DTM because it wasn't working for some reason (only one of them, I may have forgetten to add tolerance to some of the points the first time, it's fine now) and changed a line of TalkTo so that if you're wearing dark colors it doesn't affect finding the guy. You'll have to download it again.

PMing you now. . .

Town

2007-10-20 17:52:38

Not quite the reaction I was looking for. . . I'm going to go post it in the members snippets forum.