Sir R. M8gic1an
2010-07-11 12:23:40
ok so i've read about the common problem of hovering trees that aren't "cuttable".
First thing that came to mind, was to "mark the box as bad and therefore not check it."
That idea is very simple.
- You are looking for yews
- You find an Oak
- You mark the Oak TBox as a NotBox
- Next time you run the algo it won't check the NotBox
- Once the object is found, the NotBox Array is cleared.
A slight downside to this: Text checking is 100% necessary.
Then again, I thought: Any 'Smart' algorithm needs to somehow check the results, to be able to learn.
If we implement the text checking it means we'll cut down a layer, (in which I don't see harm), but we'll be able to use smart algorithms. And that, my friends, is a huge advantage.
And to push in this direction, I wrote some code.
embedded in the rest:
The only thing missing is the actual text finding. Didn't get around to the that.
And just in case this post didn't ring any bells yet.. this direction means we can embed things such as SmartColors and MatchTPA and so on into MSI.
~RM
First thing that came to mind, was to "mark the box as bad and therefore not check it."
That idea is very simple.
- You are looking for yews
- You find an Oak
- You mark the Oak TBox as a NotBox
- Next time you run the algo it won't check the NotBox
- Once the object is found, the NotBox Array is cleared.
A slight downside to this: Text checking is 100% necessary.
Then again, I thought: Any 'Smart' algorithm needs to somehow check the results, to be able to learn.
If we implement the text checking it means we'll cut down a layer, (in which I don't see harm), but we'll be able to use smart algorithms. And that, my friends, is a huge advantage.
And to push in this direction, I wrote some code.
Boxes, NotBoxes: TBoxArray;
{Bad Boxes}
if not BadPoint then
if Length(NotBoxes) > 0 then
begin
TMP := High(NotBoxes);
for II := 0 to TMP do
if PointInBox(TPA[i], NotBoxes[II])) then
begin
MSI_Debug('MSI_FindObjectsTPA', 'Point in bad Box', DEBUG_SMALL_DETAILS);
BadPoint := True;
break;
end;
end;
{ Text Checking }
if not BadPoint then
if CheckText then
begin
end;
{ Valid point! }
If (Not BadPoint) Then
Begin
SetLength(Objs, Length(Objs) + 1);
Objs[High(Objs)] := TPA[I];
{ Avoid it Next time}
End Else Begin
TMP := High(NotBoxes);
SetLength(NotBoxes, TMP + 1);
CopyBox( Boxes[I], NotBoxes[TMP]);
End;
embedded in the rest:
Procedure CopyBox(Origin, var BoxTo: TBox);
begin
BoxTo := IntToBox(Origin.X1, Origin.Y1, Origin.X2, Origin.Y2);
end;
{******************************************************************************}
{ Function MSI_FindObjectsTPA( ... ): Boolean; }
{ By: marpis }
{ Date: 25 June 2010 }
{ Description: Finds objects in mainscreen, saves co-ords in TPA }
{******************************************************************************}
Function MSI_FindObjectsTPA(Var Objs: TPointArray; ObjInfo: TMSObject; SearchBox: TBox; CheckText: Boolean): Boolean;
Var
TPA, TempTPA: TPointArray;
ATPA: T2DPointArray;
I, II, CTS, TMP, H: Integer;
SelfBox: TBox;
Boxes, NotBoxes: TBoxArray;
Animating2: TBooleanArray;
BadPoint: Boolean;
Begin
If (Not LoggedIn) Then Exit;
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(ObjInfo.Hue, ObjInfo.Sat);
SelfBox := IntToBox(228, 150, 275, 200);
H := High(ObjInfo.Colors);
SetLength(ATPA, H + 1);
For I := 0 To H Do
FindColorsSpiralTolerance(MSCX, MSCY, ATPA[I], ObjInfo.Colors[I], SearchBox.X1, SearchBox.Y1, SearchBox.X2, SearchBox.Y2, ObjInfo.Tol);
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.2, 0.2);
{ Check if some of the colors was not on MS. }
If ObjInfo.FindAllColors Then
For I := 0 To H Do
If (Length(ATPA) < 1) Then
Begin
MSI_Debug('MSI_FindObjectsTPA', 'All colors weren''t found!', DEBUG_SMALL_DETAILS);
Objs := [];
Exit;
End;
{ Check if we have enough pixels on MS. }
TPA := MergeATPA(ATPA);
//DrawDots(TPA, 1000);
If (Length(TPA) < ObjInfo.Accuracy) Then
Begin
MSI_Debug('MSI_FindObjectsTPA', 'No colors found!', DEBUG_SMALL_DETAILS);
Objs := [];
Exit;
End;
ATPA := TPAtoATPAEx(TPA, ObjInfo.W, ObjInfo.H);
SortATPAFrom(ATPA, Point(MSCX, MSCY));
H := High(ATPA);
SetLength(TPA, H + 1);
For I := 0 To H Do
TPA[I] := MiddleTPA(ATPA[I]);
H := High(TPA);
SetLength(Boxes, H + 1);
For I := 0 To H Do
Begin
Boxes[I].X1 := TPA[I].X - (ObjInfo.W / 2);
Boxes[I].Y1 := TPA[I].Y - (ObjInfo.H / 2);
Boxes[I].X2 := TPA[I].X + (ObjInfo.W / 2);
Boxes[I].Y2 := TPA[I].Y + (ObjInfo.H / 2);
End;
If ObjInfo.Anim Then
Animating2 := AnimatingMulti(Boxes, 100, 1);
For I := 0 To High(TPA) Do
Begin
BadPoint := False;
//DrawBox(Boxes[I], 200);
{Bad Boxes}
if not BadPoint then
if Length(NotBoxes) > 0 then
begin
TMP := High(NotBoxes);
for II := 0 to TMP do
if PointInBox(TPA[i], NotBoxes[II])) then
begin
MSI_Debug('MSI_FindObjectsTPA', 'Point in bad Box', DEBUG_SMALL_DETAILS);
BadPoint := True;
break;
end;
end;
{ Animation }
If (Not BadPoint) Then
If ObjInfo.Anim Then
If (Not Animating2[I]) Then
Begin
MSI_Debug('MSI_FindObjectsTPA', 'Not animating!', DEBUG_SMALL_DETAILS);
BadPoint := True;
End;
{ Exclude own character }
If (Not BadPoint) Then
If ObjInfo.ExcludeSelf Then
If PointInBox(TPA[I], SelfBox) Then
Begin
MSI_Debug('MSI_FindObjectsTPA', 'Own character!', DEBUG_SMALL_DETAILS);
BadPoint := True;
End;
{ Invalid point }
If (Not BadPoint) Then
If ((TPA[I].X + TPA[I].Y) < 1) Then
Begin
MSI_Debug('MSI_FindObjectsTPA', 'Invalid point!', DEBUG_SMALL_DETAILS);
BadPoint := True;
End;
{ Accuracy }
If (Not BadPoint) Then
If (Length(ATPA[I]) < ObjInfo.Accuracy) Then
Begin
MSI_Debug('MSI_FindObjectsTPA', 'Not enough points!', DEBUG_SMALL_DETAILS);
BadPoint := True;
End;
{ Bad colors }
If (Not BadPoint) Then
For II := 0 To High(ObjInfo.BadColors) Do
Begin
MSI_Debug('MSI_FindObjectsTPA', 'Looking for bad color: '+IntToStr(ObjInfo.BadColors[II]), DEBUG_SMALL_DETAILS);
If FindColorSpiralTolerance(TMP, TMP, ObjInfo.BadColors[II], TPA[I].X - (ObjInfo.W / 2), TPA[I].Y - (ObjInfo.H / 2), TPA[I].X + (ObjInfo.W / 2), TPA[I].Y + (ObjInfo.H / 2), ObjInfo.BadColorTolerance) Then
Begin
MSI_Debug('MSI_FindObjectsTPA', 'Bad color found!', DEBUG_SMALL_DETAILS);
BadPoint := True;
Break;
End;
End;
{ FindAllColors }
If (Not BadPoint) Then
If ObjInfo.FindAllColors Then
For II := 0 To H Do
Begin
TempTPA := MSI_ReturnPointsInBox(ATPA[II], IntToBox(TPA[I].X - (ObjInfo.W / 2), TPA[I].Y - (ObjInfo.H / 2), TPA[I].X + (ObjInfo.W / 2), TPA[I].Y + (ObjInfo.H / 2)));
If (Length(TempTPA) < 1) Then
Begin
MSI_Debug('MSI_FindObjectsTPA', 'All colors weren''t found!', DEBUG_SMALL_DETAILS);
BadPoint := True;
Break;
End;
End;
{ Text Checking }
if not BadPoint then
if CheckText then
begin
end;
{ Valid point! }
If (Not BadPoint) Then
Begin
SetLength(Objs, Length(Objs) + 1);
Objs[High(Objs)] := TPA[I];
{ Avoid it Next time}
End Else Begin
TMP := High(NotBoxes);
SetLength(NotBoxes, TMP + 1);
CopyBox( Boxes[I], NotBoxes[TMP]);
End;
End;
Result := (Length(Objs) > 0);
End;
The only thing missing is the actual text finding. Didn't get around to the that.
And just in case this post didn't ring any bells yet.. this direction means we can embed things such as SmartColors and MatchTPA and so on into MSI.
~RM