SRL Archive - Help and Support

Arrays of Arrays. TPA's to be precise


Ransom

2008-08-07 19:29:53

What started as the workings of a fisher, turned into a high octane coding session to mess around with TPA's and the like. Now i'm only concerned with being able to make this procedure work, even if it's usefulness isn't top notch.

Basically we have a procedure that makes a large TPA based on found colors. The Function i'm having trouble with is GroupPoints. Basically it's going to go through the array and decided which points are in a "group". My problem is data handling. What I want to do is have the function return a TPA with the center points of the "groups" which we found. It's fairly easy to see how i'm deciding what is a group in the code. Now what I want to do is go through the original large array, and write a certain number (based on user input, for how many groups they want), of new arrays. Once this is complete, use MiddleTPA to find the center of each group and write those values to the final Result TPA.

I just don't know how to get the data from the large array into the 5 smaller arrays, in a data handling sort of way. I figured i could make an array of TPA's but i've tried without success to execute it, mostly because of syntax and or lack of knowledge.

So i see help, either to make my thought work or to offer a second opinion on how i can achieve my goal.

If you need more info just let me know. I'm usually on IRC during the day and late at night.

Thanks

Ransom

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

var BubbleColor1, BubbleColor2 : Integer;

Procedure PlayerInputs;
begin
BubbleColor1 := 16776960; //this is the cyan color in paint. used it as a test.
BubbleColor2 := 16776960;
end;

Procedure ReportTPA(TPA : TPointArray); //debugger pretty much
var i : Integer;
begin
For i := 0 to High(TPA) do
begin
writeln('(' + IntToStr(TPA[i].x) + ', ' + IntToStr(TPA[i].y) + ')')
end;
Writeln('Total Length is ' + IntToStr(Length(TPA)));
end;

Function SortArray(TPA: TPointArray) : TPointArray;
var
i, j : integer; // in the real program, for swiftness, i will change this is a shell sort
temp : TPoint;
begin
For i := 0 to High(TPA) - 1 do
For j := i+1 to High(TPA) do
if TPA[i].x > TPA[j].x then
begin
temp := TPA[j];
TPA[j] := TPA[i];
TPA[i] := temp;
end;
Result := TPA;
end;

Function GroupPoints(TPA : TPointArray; Spots : Integer) : TPointArray;
var
i, i2, Counter : Integer;
initial : TPoint;
TempTPA : array [0..9, 0..200] of //PROBLEM HERE.
TPAOut : Array [0..10000] of TPoint;
begin
SortArray(TPA);
try
initial := TPA[0];
except
writeln('Could not set initial, most likely no data in the TPA.');
end;
Counter := 1;
Repeat
i2 := 0
For i := 0 to High(TPA) do
begin
if ((TPA[i].X - initial.x) < 20) and ((TPA[i].X - initial.y) < 20) then
begin
writeln('here');
TempTPA[Counter][i2] := TPA[i]; //PROBLEM HERE. this was my original attempt
Inc(i2);
Continue;
end else
begin
TPA[i].X := 14557;
Inc(Counter);
Break;
end;
end;
Until (Counter = Spots);

end;


Function FindFishLTR: Boolean;
var
FishTPA : TPointArray;
FishPoint : TPoint;
x, y, i: Integer;
begin
FindColorsTolerance(FishTPA, BubbleColor1, MSx1, MSy1, MSx2, Msy2, 1);
if Length(FishTPA) = 0 then FindColorsTolerance(FishTPA, BubbleColor2, MSx1, MSy1, MSx2, Msy2, 1);
ReportTPA(FishTPA); //debug purposes only
Writeln('================================================================');
FishTPA := GroupPoints(FishTPA, 4); //the problem child...
ReportTPA(FishTPA)
for i := 0 to High(FishTPA) do
begin
FishPoint := FishTPA[i];
MoveMouse(FishPoint.x, FishPoint.y);
wait(250);
End;
end;



begin
ClearDebug;
PlayerInputs;
FindFishLTR;
end.

HyperSecret

2008-08-07 20:10:38

TPAtoATPA I believe does what your trying to do, that splits the tpa into a an array of tpas determined by a certain size…or TPAtoATPAEx

so like TPAtoTPA(tpa, 25); will 'group' each tpa within 25 pixels of eachother and group them, and group another 25 pixel area together and so forth into an array or tpas…

Ransom

2008-08-07 20:47:07

Well gosh that makes it so much easier. I'll test it out and post the results. Thank you very much!