Simba Code:
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- ? Box Routines --//
//-----------------------------------------------------------------//
// * function FindBox: Boolean; // * by WT-Fakawi
// * function GambleBox: Boolean; // * by WT-Fakawi
// * function GetBoxSide: Integer; // * by pups
// * function GetQuestion(var num: Integer; var shape: string): Integer; // * by pups
// * function OpenBox: Boolean; // * by pups
// * function SolveBox: Boolean; // * by pups
{$I SRL-OSR/SRL/misc/Debug.Simba}
{$I SRL-OSR/SRL/misc/SmartGraphics.Simba}
var
NumberBounds: TBox;
const
DebugBox=false;
{*******************************************************************************
function GambleNewBox: Boolean;
by: WT-Fakawi
Description: A random box clicker. Will try to solve the box ONCE, by a random click
@ any of the three answers. THIS IS NOT A BOXSOLVER, JUST A BOXCLICKER!
*******************************************************************************}
function GambleBox: Boolean;
var
xb, yb, Choise: Integer;
begin
//if FindBitmapToleranceIn(Box, xb, yb, MIX1, MIY1, MIX2, MIY2, 40) then
begin
Mouse(xb, yb, 0, 0, True);
Wait(2000);
Choise:= Random(3);
TakeScreen('Gambling box Choise - '+IntToStr(Choise));
case Choise of
0: Mouse(145, 295, 4, 4, True);
1: Mouse(270, 295, 4, 4, True);
2: Mouse(381, 295, 4, 4, True);
end;
IdleTime(4000, 2000, 1.0);
// if FindBitmapToleranceIn(Box, xb, yb, MIX1, MIY1, MIX2, MIY2, 40) then
begin
WriteLn('Box Missed');
// NOnewboxes := NOnewboxes + 1;
Result := False;
repeat
Logout;
until (not (LoggedIn));
Exit;
end
//else
begin
WriteLn('Box solved');
// newboxes := newboxes + 1;
Result := True;
end;
end;
end;
{*******************************************************************************
function OpenBox: Boolean;
by: pups fixed by Cheesehunk.
Description: Opens the box.
*******************************************************************************}
function OpenBox : Boolean;
var
x, y, i,BoxDTM : Integer;
begin
Result := False;
GameTab(Tab_Inv);
Wait(100 + Random(50));
BoxDTM:=DTMFromString('mwQAAAHic42RgYHBiYmAwQ8J+SNgZiN2A+BlQ3QMGCP0GiO8C8SMo/wMU97W0AElGvNiIgTDAbwIEwwEAyPkMaQ==');
if FindDTM(BoxDTM, x, y, MIX1, MIY1, MIX2, MIY2) then
begin
Mouse(x, y, 4, 4, True);
for i := 0 to 9 do
begin
if (GetColor(487, 39) = 13567) and (GetColor(350, 295) = 2304814) then
begin
Result := True;
Exit;
end;
Wait(500);
end;
end;
freedtm(boxdtm);
end;
Function GetNumber: Integer;
Var
CTS,X,Y,ZeroDTM,OneDTM,TwoDTM,ThreeDTM,FourDTM,FiveDTM,SixDTM,SevenDTM,EightDTM,NineDTM: Integer;
MidBox: TPoint;
TPA,TPA1,TPA2,TPAW: TPointArray;
ATPA: T2DPointArray;
BrownBox: TBox;
afound: Extended;
Begin
Result:=-1
CTS:= GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.05, 0.31);
MidBox:=MiddleBox(IntToBox(NumberBounds.X1+5, NumberBounds.Y1+5, NumberBounds.X2-5, NumberBounds.Y2-5));
FindColorsSpiralTolerance(MidBox.X, MidBox.Y, TPA, 6187391, NumberBounds.X1, NumberBounds.Y1, NumberBounds.X2, NumberBounds.Y2, 16);
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.2, 0.2);
ATPA:=FloodFillTPA(TPA);
If Length(ATPA)=0 Then
Begin
Writeln('No brown found');
Exit;
End;
{Good} ZeroDTM := DTMFromString('mEQIAAHicvc1BCoMwEAXQiRZR1FLUjdfwKJ7Aa3gfsaWViOjxDPSH/K1mpYHHTH4mSS0iT+VkEEMED/Y2e0HKXIGwz6GAkux8ALu4mRASqOCHSMOXJu5n1pHePLfZQprzK2xk9x/eGViNMaf6rvXyvdHgn6upGxyuP2gVUcs=');
{Good} OneDTM := DTMFromString('mggAAAHicY2NgYGBigABmIGaBshmBmA+IuaFYCirOAcT1mXEMf//8AWMQG4aNgHLYMBMODAEARdcMkQ==');
{Good} TwoDTM := DTMFromString('mOwIAAHicvc3dCoJAEIbhUSNEtL9T78JL8Qq8hbQgo8Sf6K6Xepe+TjoI6sCFh4+Z3dnJzSwKzEIsECPDBomsZIdU/Lul+mtsJdOMv/P/GhzxsNeOiRzQfRhxU/a44ogaDQ7YK084o5V3fdH8XZxzf2ur8icF++YSzOjLeQJzJ1Aa');
{Good} ThreeDTM := DTMFromString('mJgIAAHicvc1RCoJAEMbxNUWCSkJ86hgexRN0Dc/SgykmahKeL9zwL35Pgj704MKPmZ2dmb0ZY67O7CyBnODDg4uD4lEiuahvev+xb4CFUT3El2uFGg1eKJHjiUwK1SvFQvk006HFW3tKzT7wQa+6tfYv6T3ZtOyP+WsPzk7WzwgAalmq');
{Good} FourDTM := DTMFromString('mJgIAAHicvc7vCkFBEIfh2dtwGW6IK5A7UChaVv6FuEHppCTi1J7Ou/nRKfniw9l6mp1pZnYbZnbHRTHHA0/do+pn5bnym2YyHHFSz1XzRYW5VwyYYIQ+vGrLijnW2OOALTaqLTDFGAP0MNSeGVbYpT/HaKHb/uI7rU98S3nq/0eTt+rgavL7lIw5ZyI=');
{Good} FiveDTM := DTMFromString('mOwIAAHicvc1dCoJAFIbhMxBhJAWSUdYqWof3LaOVGBphYj8LzQZ8B7/rCAIHHs7P8M3szGzmzBZIsMYGmRv2Uxg+lLcNfeAwQazsSlLssVW/xBwROqI3XHFBqT7sWjzxwh21NJrD/UNzrVyjekahWurtCqdj/jPv/V8O/DcWN6IvpwdBgFTL');
SixDTM := DTMFromString('mJgIAAHicvczBCoJAEMbx2YiwotRLBx+rJ/AZPFltKGJZHXrhWOi/8F21Tg78mN3hmynMbOPMtkix03uFtXr0IWd0hwWWmu+RS6b9RLmgnTg/4Ma3Q487BrTwuOKMWryyMffECw/NGlyUq3Qj5t7qIYS/nMrjT1P7c5WbyXh9AZtZTSk=');
{Good} SevenDTM := DTMFromString('m/AEAAHictc3dCYAgFAVg26I5mqgRWqQJCooIkoiIaLL+qNDoXDg+1ksofBw5XjVUSq1wwg0WLjjY7zAzXe86sXFO9gvPDd8yVEJBNbTQwwQjVOwlG9DUkcwOkEHO1OzlfprEn6y1v0T4w6fAs7f1AM9jZhg=');
{Good} EightDTM := DTMFromString('megIAAHicxc1NCoMwEAXgSQSFCtWFaw/Rc3TvMTxCS9H6S1s8bRHS+gbeIhuldGPgI8nMyyQXkS98QIyIpZiOdICZuQDniLWUEt5D9nSGZvXNm7tlX2UwoNZ6etJzByM1UFHt7Zp7wIs5ffMknXOHG1zgChPzzrmflMX5L2vzTvh7D2Yn22sBgURdPw==');
NineDTM := DTMFromString('mUAIAAHick2FgYGBmhGAmIGYFYkEg5oKyGYD4LwME/wZiFqg6NqgaHiDmA2IBKM0N1Q+iORgh6v8B9f0A4l8MEDMrgXQdENdAcRkQF0NxCRBXQMWrgLgJCTeg6auC6i0C4gIkDOJXQ/W0gdz+5w8KzgvzIgqj6yMWGwHtpCdmpDPGBwCan1l1');
If DebugBox Then
Begin
DebugATPABounds(ATPA);
Writeln('Length of Brown Shape: '+ToStr(Length(ATPA[0])));
End;
BrownBox:=GetTPABounds(ATPA[0]);
FindColorsSpiralTolerance(MSCX, MSCY, TPA1, 16579837, BrownBox.X1, BrownBox.Y1, BrownBox.X2, BrownBox.Y2, 5);
FindColorsSpiralTolerance(MSCX, MSCY, TPA2, 12764106, BrownBox.X1, BrownBox.Y1, BrownBox.X2, BrownBox.Y2, 5);
TPAW:=CombineTPA(TPA1,TPA2);
If DebugBox Then
Writeln('Length of White TPA in Brown: '+ToStr(Length(TPAW)));
If Result=-1 Then
If findDTMrotated(EightDTM, x, y, BrownBox.X1-3, BrownBox.Y1-3, BrownBox.X2+3, BrownBox.Y2+3,-Pi,Pi,Pi/30,aFound) And InRange(Length(ATPA[0]),130,400) And InRange(Length(TPAW),200,450) Then
Result:=8;
If Result=-1 Then
If findDTMrotated(NineDTM, x, y, BrownBox.X1-3, BrownBox.Y1-3, BrownBox.X2+3, BrownBox.Y2+3,-Pi,Pi,Pi/30,aFound) And InRange(Length(ATPA[0]),160,440) And InRange(Length(TPAW),300,600) Then
Result:=9;
If Result=-1 Then
If findDTMrotated(SixDTM, x, y, BrownBox.X1-3, BrownBox.Y1-3, BrownBox.X2+3, BrownBox.Y2+3,-Pi,Pi,Pi/30,aFound) And InRange(Length(ATPA[0]),160,440) And InRange(Length(TPAW),300,600) Then
Result:=6;
If Result=-1 Then
If findDTMrotated(FourDTM, x, y, BrownBox.X1-3, BrownBox.Y1-3, BrownBox.X2+3, BrownBox.Y2+3,-Pi,Pi,Pi/30,aFound) And InRange(Length(ATPA[0]),130,300) And InRange(Length(TPAW),200,450) Then
Result:=4;
If Result=-1 Then
If findDTMrotated(FiveDTM, x, y, BrownBox.X1-3, BrownBox.Y1-3, BrownBox.X2+3, BrownBox.Y2+3,-Pi,Pi,Pi/30,aFound) And InRange(Length(ATPA[0]),230,300) And InRange(Length(TPAW),340,900) Then
Result:=5;
If Result=-1 Then
If findDTMrotated(TwoDTM, x, y, BrownBox.X1-3, BrownBox.Y1-3, BrownBox.X2+3, BrownBox.Y2+3,-Pi,Pi,Pi/30,aFound) Then
Result:=2;
If Result=-1 Then
If findDTMrotated(ZeroDTM, x, y, BrownBox.X1-3, BrownBox.Y1-3, BrownBox.X2+3, BrownBox.Y2+3,-Pi,Pi,Pi/30,aFound) And InRange(Length(ATPA[0]),140,215) And InRange(Length(TPAW),160,300) Then
Result:=0;
If Result=-1 Then
If findDTMrotated(ThreeDTM, x, y, BrownBox.X1-3, BrownBox.Y1-3, BrownBox.X2+3, BrownBox.Y2+3,-Pi,Pi,Pi/30,aFound) And InRange(Length(ATPA[0]),140,220) And InRange(Length(TPAW),300,550) Then
Result:=3;
If Result=-1 Then
If findDTMrotated(SevenDTM, x, y, BrownBox.X1-4, BrownBox.Y1-4, BrownBox.X2+4, BrownBox.Y2+4,-Pi,Pi,Pi/30,aFound) And InRange(Length(ATPA[0]),140,220) And InRange(Length(TPAW),200,550) Then
Result:=7;
If Result=-1 Then
If findDTMrotated(OneDTM, x, y, BrownBox.X1-3, BrownBox.Y1-3, BrownBox.X2+3, BrownBox.Y2+3,-Pi,Pi,Pi/30,aFound) Or (InRange(Length(ATPA[0]),85,130) And InRange(Length(TPAW),0,100)) Then
Result:=1;
SetLength(ATPA,0);
SetLength(TPA,0);
SetLength(TPA1,0);
SetLength(TPA2,0);
SetLength(TPAW,0);
FreeDTM(ZeroDTM);
FreeDTM(OneDTM);
FreeDTM(TwoDTM);
FreeDTM(ThreeDTM);
FreeDTM(FourDTM);
FreeDTM(FiveDTM);
FreeDTM(SixDTM);
FreeDTM(SevenDTM);
FreeDTM(EightDTM);
FreeDTM(NineDTM);
Writeln('We think the number is: '+ToStr(Result));
End;
Function GetShape: String;
Var
CTS: Integer;
TPA,TPA1,TPA2, TPAB: TPointArray;
ATPA,ATPAB: T2DPointArray;
WhiteBox: TBox;
Begin
Result:='';
FindColorsSpiralTolerance(MSCX, MSCY, TPA1, 16579837, 172, 45, 352, 225, 5);
FindColorsSpiralTolerance(MSCX, MSCY, TPA2, 12764106, 172, 45, 352, 225, 5);
TPA:=CombineTPA(TPA1,TPA2);
ATPA:=FloodFillTPA(TPA);
SortATPASize(ATPA,True);
If DebugBox Then
Writeln('Length of Full White ATPA: '+ToStr(Length(ATPA)));
If Length(ATPA)=0 Then
Begin
Writeln('No white found');
Exit;
End;
If DebugBox Then
DebugATPABounds(ATPA);
CTS:= GetColorToleranceSpeed;
ColorToleranceSpeed(2);
WhiteBox:=GetTPABounds(ATPA[0]);
NumberBounds:=WhiteBox;
SetColorSpeed2Modifiers(0.05, 0.31);
FindColorsSpiralTolerance(MSCX, MSCY, TPAB, 6187391, WhiteBox.X1, WhiteBox.Y1, WhiteBox.X2, WhiteBox.Y2, 16);
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.2, 0.2);
SplitTPAWrap(TPAB,10,ATPAB);
SortATPASize(ATPAB,True);
If DebugBox Then
Begin
Writeln('Length of Shape: '+ToStr(Length(ATPA[0])));
Writeln('Length of OutterBox: '+ToStr(Length(ATPAB[0])));
End;
If InRange(Length(ATPA[0]),4280,4900) And InRange(Length(ATPA),9,20) And InRange(Length(ATPAB[0]),2700,5200) Then
Result:='Triangle';
If Result = '' Then
If InRange(Length(ATPA[0]),4801,6000) And InRange(Length(ATPA),8,15) And InRange(Length(ATPAB[0]),100,4600) Then
Result:='Square';
If Result = '' Then
If InRange(Length(ATPA[0]),3600,4580) And InRange(Length(ATPA),15,30) And InRange(Length(ATPAB[0]),7300,8700) Then
Result:='Star';
If Result = '' Then
If InRange(Length(ATPA[0]),6001,7900) And InRange(Length(ATPA),16,23) And InRange(Length(ATPAB[0]),200,2300) Then
Result:='Circle';
If Result = '' Then
Result:= 'Pentagon';
Writeln('We think the shape is: '+ToStr(Result));
SetLength(ATPA,0);
SetLength(TPA,0);
SetLength(TPA1,0);
SetLength(TPA2,0);
SetLength(ATPAB,0);
SetLength(TPAB,0);
End;
{*******************************************************************************
function GetBoxSide: Integer;
by: pups
Description: Gets Box side and returns Bitmap
*******************************************************************************}
Procedure GetBoxSide;
var
X,Y: Integer;
begin
repeat
wait(100);
if FindColorTolerance(x, y, 16579837, 182, 45, 182, 225, 5) then continue;
if FindColorTolerance(x, y, 16579837, 342, 45, 342, 225, 5) then continue;
if FindColorTolerance(x, y, 16579837, 172, 55, 352, 55, 5) then continue;
if FindColorTolerance(x, y, 16579837, 172, 215, 352, 215, 5) then continue;
if FindColorTolerance(x, y, 12764106, 182, 45, 182, 225, 5) then continue;
if FindColorTolerance(x, y, 12764106, 342, 45, 342, 225, 5) then continue;
if FindColorTolerance(x, y, 12764106, 172, 55, 352, 55, 5) then continue;
if FindColorTolerance(x, y, 12764106, 172, 215, 352, 215, 5) then continue;
Break;
until False;
Freeze;
end;
{*******************************************************************************
function GetQuestion(var num: Integer; var shape: String): Integer;
by: pups
Description: Returns number and type.
*******************************************************************************}
function GetQuestion(var num: Integer; var shape: string): Integer;
var
x, y, i: Integer;
text: string;
begin
num := 10;
shape := '';
for i := 0 to 14 do
begin
case i of
0: text := '0'; //Zero
1: text := '1'; //One
2: text := '2'; //Two
3: text := '3'; //Three
4: text := '4'; //Four
5: text := '5'; //Five
6: text := '6'; //Six
7: text := '7'; //Seven
8: text := '8'; //Eight
9: text := '9'; //Nine
10: text := 'Circle'; //Circle
11: text := 'Triangle'; //Triangle
12: text := 'Square'; //Square
13: text := 'Star'; //Star
14: text := 'Pentagon'; //Pentagon
end;
if (FindText(x, y, Text, upchars07, 110, 250, 415, 275)) then
begin
Result := i;
if (i < 10) then
num := i;
if (i >= 10) then
shape := text;
Exit;
end;
end;
end;
{*******************************************************************************
function SolveBox: Boolean;
by: pups
Description: Solves the Box!
*******************************************************************************}
function SolveBox: Boolean;
var
st2: Integer;
shapeQ, shape, ans: string;
numQ, num: Integer;
x, y: Integer;
begin
while OpenBox do
begin
WriteLn('Found a box, solving...');
Wait(1000);
GetQuestion(numQ, shapeQ);
if (shapeQ = '') and (numQ = 10) then
exit;
WriteLn('Question is:');
if shapeQ = '' then
WriteLn('Which shape has number ' + IntToStr(numQ))
else
WriteLn('What number is the ' + shapeQ);
st2 := GetSystemTime;
repeat
GetBoxSide;
Shape:=GetShape;
Num:=GetNumber;
UnFreeze;
If DebugBox Then
Wait(2000) Else
if (num = numQ) or (shape = shapeQ) then
begin
if num = numQ then
ans := shape
else
ans := IntToStr(num);
WriteLn('Answer is ' + ans);
if FindText(x, y, ans, upchars07, 116, 286, 183, 311) then
Mouse(120, 290, 30, 10, True);
if FindText(x, y, ans, upchars07, 235, 286, 302, 311) then
Mouse(240, 290, 30, 10, True);
if FindText(x, y, ans, upchars07, 350, 286, 417, 311) then
Mouse(355, 290, 30, 10, True);
WriteLn('******** SOLVED BOX RANDOM ********');
Result := True;
Break;
end;
until GetSystemTime > st2 + 12000;
Wait(1500 + Random(1000));
end;
end;