Results 1 to 13 of 13

Thread: Comparing Arrays

  1. #1
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default Comparing Arrays

    I'm having trouble storing a TPA, splitting it into a 2D TPA Array, then comparing a 3D TPA Array of the color count in each 2D TPA array. Keeping the most filled 3D TPA Array, then deleting the other values that are less reliable.

    This might not even make sense... so any help/advice/examples would be greatly appreciated.

  2. #2
    Join Date
    Mar 2006
    Location
    Behind you
    Posts
    3,193
    Mentioned
    61 Post(s)
    Quoted
    63 Post(s)

    Default

    Once you go into 3D arrays it gets really hard to explain. it's better if you break each step down literally to what you want it to do. Because you might find that all you need are a pair of 2D arrays which are easier to use. You might want to do some more research into the Wizzy plugin which is where all the TPA started from. Naum has a good tutorial for them. Also check the Docs. You might just wish to loop through the 2D array and remove the bad points and save the new points to a new 2D array. Then export that at the end of your sorting function or you can loop through again and only export the TPA that has the Most points left in it.

    I hope I made some sense with that. You might check out the Snippets section I think Dgby714 or me made something that sorted like that awhile back.

    "Sometimes User's don't need the Answer spelled out with Code. Sometimes all they need is guidance and explanation of the logic to get where they are going."

  3. #3
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    Hmm, I might try what you suggested first. It seems easier to me, at the moment, to do now. Then if I can manage that, I'll try making it into 3D arrays, but I think I really need the baby steps. Thanks for the help! (I've been somewhat scouring the docs/Naum's TPA tut; Plus I'll look up the potential snippets)

    Edit: Making an example for myself in Paint helps visualize what I need to accomplish too (idea from Naum's TPA tut)
    Edit2: adding this link so I can reference later / easier http://docs.villavu.com/simba/scriptref/tpa.html
    Last edited by Le Jingle; 08-15-2012 at 06:56 AM.

  4. #4
    Join Date
    Dec 2011
    Location
    New York, USA
    Posts
    1,242
    Mentioned
    12 Post(s)
    Quoted
    193 Post(s)

    Default

    Alright so assuming you can figure out how to get 3 ATPAs...

    Simba Code:
    var
      qwerty: Array of Array of Array of TPoint;
    begin

      //Get the 3 ATPAs
      qwerty :=  [ATPA1, ATPA2, ATPA3];
     
    end;

    What happens next depends on what you're trying to do, I still haven't figured that out yet.


    E: Actually from what I understand, you just want to be left with the largest ATPA(?). So just do something like this:

    Simba Code:
    var
      ATPA1, ATPA2, ATPA3, LATPA: Array of Array of TPoint;
    begin
      //get the values of the ATPAs...

      LATPA := ATPA1;
      if (Length(LATPA) > Length(ATPA2)) and (Length(LATPA) > Length(ATPA3)) then
        Exit;
      else
      if Length(ATPA2) > Length(ATPA3) then
        LATPA := ATPA2
      else
        LATPA := ATPA3;
    Last edited by Nebula; 08-15-2012 at 06:53 AM.

  5. #5
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    Found Brak's clearSameT2D's.. but I think I'd have to convert/get the colors back into the func before I try to clear them (when they're in tpa's no integers?)

    Here's what I have... Note this is my first time ever trying to make sense of this stuff.. and it's late. Soooo heck, here it is:

    Simba Code:
    var
      LeCols: TIntegerArray;
      LeTry_s, LeTol: Integer;
      LeUpTxts: TStringArray;

    procedure Declare_Params;
    begin
      LeCols := [{color1, color2, color3, etc...}];
      LeTry_s := 5;
      LeTol := 5;
      LeUpTxts := [{'','','',''}];
    end;

    procedure ClearSameIntT2D(var T2DArray: T2DIntegerArray);
    var
      I, II, III: Integer;
      ArrayOut: T2DIntegerArray;
      DeleteSet: TIntegerArray;

    begin
      For I := 0 to High(T2DArray) do
        ClearSameIntegers(T2DArray[I]);
      SetArrayLength(ArrayOut, Length(T2DArray));
      Writeln('Starting T2D Array After ClearSameIntegers := ' + tostr(T2DArray));
      for I := 0 to High(T2DArray) do
        for II := 0 to High(T2DArray[I]) do
          for III := 0 to High(T2DArray) do
            If I = III then
              continue
            else if InIntArray(T2DArray[III],T2DArray[I][II]) or InIntArray(DeleteSet, T2DArray[I][II])  then
            begin
              SetArrayLength(DeleteSet, Length(DeleteSet) + 1);
              DeleteSet[Length(DeleteSet) - 1] := T2DArray[I][II];
            end else
            begin
              SetArrayLength(ArrayOut[I], Length(ArrayOut[I]) + 1);
              ArrayOut[I][Length(ArrayOut[I]) - 1] := T2DArray[I][II];
            end;
      ClearSameIntegers(DeleteSet);
      writeln('Deleted Integers := ' + tostr(DeleteSet));
      For I := 0 to High(ArrayOut) do
        ClearSameIntegers(ArrayOut[I]);
      T2DArray := ArrayOut;
    end;

    function BestT3DTPAColors(Colors:TIntegerArray; TriesPerLoop, Tol: Integer; UpTxts: TStringArray): boolean;
    var
      i, ii, hCols, lCols: integer;
      MainScreenTPA, TempToDelete, PBox: TPointArray;
      temp: T2DPointArray;
      temp2: Array of Array of Array of TPoint;
    begin
      hCols := High(Colors) + 1;
      lCols := Low(Colors) + 1;
      PBox := TPAFromBox(IntToBox(240, 130, 275, 185));
      MSBox := IntToBox(msx1, msy1, msx2, msy2);

      for i := lCols to hCols do
      begin
        ClearTPAFromTPAWrap(MainScreenTPA, PBox, MainScreenTPA);
        if FindColorsTolerance(MainScreenTPA, colors[i], msx1, msy1, msx2, msy2, tol) then
        begin
          temp2[i] := temp;
          TempToDelete := ReturnPointsNotInTPA(MainScreenTPA, MSBox);
          ClearTPAFromTPAWrap(MainScreenTPA, TempToDelete, Temp[i]);
          temp2[i] := temp + temp;
        end;
      end;

      for ii := 0 to Length(temp2) do
      begin
        ClearSameIntT2D(temp2[ii]);
        if Length(temp2[ii]) < Length(temp2[ii]) then
          //use the T2D within the T3D as the 'best fit' T3DPointArray
          //Mouse to the center...
          //uptext, all that good stuff..
      end;

    end;

  6. #6
    Join Date
    Dec 2011
    Location
    New York, USA
    Posts
    1,242
    Mentioned
    12 Post(s)
    Quoted
    193 Post(s)

    Default

    I updated my post just like 30 seconds ago. There's definitely a shorter way than what you just posted. Explain in more depth what you want.

  7. #7
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    Here's a 'visualization' I made .. for myself .. lol
    It's late.
    ok. I'll probably be too embarrassed and just go to sleep, the drawings ridiculous lol


  8. #8
    Join Date
    Dec 2011
    Location
    New York, USA
    Posts
    1,242
    Mentioned
    12 Post(s)
    Quoted
    193 Post(s)

    Default

    Okay I think I understand what you're going for.


    Simba Code:
    var
      Colors: Array of LongInt;
      FinalTPA, TempTPA: Array of TPoint;
      ATPA: Array of Array of TPoint;

    Colors := [4535342, 453254, 4523523452, 42352345432];

    for i := 0 to high(Colors) do
    begin
      FindColorsTolerance(TempTPA, Colors[i],   rest_of_stuff   );
      FinalTPA := CombineTPA(TempTPA, FinalTPA);
    end;

    ATPA := TPAToATPAEx(FinalTPA, 10, 10);
    SortATPASize(ATPA, true);

    for i:= 0 to high(ATPA) do
    begin
      {
          MMouse, UpText, etc
      }

    end;

  9. #9
    Join Date
    Dec 2011
    Location
    The Netherlands
    Posts
    1,631
    Mentioned
    47 Post(s)
    Quoted
    254 Post(s)

    Default

    Nebula using that you will just get the highest result of a single colored box instead of multiple overlayed boxes I think.

    This is what I used to combine two colors
    Simba Code:
    function FindHobgoblin: Boolean;
    var
      i, j, t: Integer;
      ATPA: Array[0..1] of TPointArray;
      Colors, Tol, Area: Array of Integer;
      BoxSize: Array[0..1] of Integer;
      HueMod, SatMod: Array of Extended;
      TBox: Array[0..1] of TBox;
      ClearBoxes: TBox;
      ClearTPA: TPointArray;

    begin
      // Details of the gray & brown colors of Hobgoblins
      Colors := [9411230, 4020585]
      Tol := [28, 11]
      HueMod := [0.23, 0.17]
      SatMod := [0.20, 1.24]
      Area := [MSCX-220, MSCY-100, MSCX+200, MSCY-35]
      ClearTPA := TPAFromBox(IntToBox(240, 110, 285, 140));
      SMART_ClearCanvasArea(IntToBox(Area[0]-2, Area[1]-2, Area[2]+2, Area[3]+2));
      MarkTime(t);

      for i:=0 to high(Colors) do
        begin
          SetColorToleranceSpeed(2);
          SetColorSpeed2Modifiers(HueMod[i], SatMod[i]);
          if FindColorsSpiralTolerance(((MSX1+MSX2)/2), ((MSCY+MSY1)/2), ATPA[i], Colors[i], Area[0], Area[1], Area[2], Area[3], Tol[i]) then
            begin
              //WriteLn('Points: '+ToStr(ATPA[i])+'');
              ClearTPAFromTPA(ATPA[i], ClearTPA);
              WriteLn('Length: '+IntToStr(Length(ATPA[i]))+'');
              if (Length(ATPA[i])<100) then
                Exit;
              TBox[i] := GetTPABounds(ATPA[i]);
              BoxSize[i] := (TBox[i].x1 + TBox[i].y1 + TBox[i].x2 + TBox[i].y2);
              SMART_DrawBoxEx(False, IntToBox(TBox[i].x1, TBox[i].y1, TBox[i].x2, TBox[i].y2), clRed);
            end;
        end;
      for i:=0 to (high(Colors)-1) do
        begin
          for j:=0 to high(ATPA[i]) do
          if NearbyPointInArray(ATPA[i][j], 1, ATPA[i+1]) then
            begin
              if TimeFromMark(t) < 1500 then
                begin
                  MMouse(ATPA[i][j].x, ATPA[i][j].y, 0, 0);
                  if WaitUptextMulti(['tta', 'ack', 'obg', 'blin', 'Hobgoblin'], 100) then
                    begin
                      //WriteLn('Point: '+ToStr(ATPA[i][j])+'');
                      WriteLn('Clicked on a hobgoblin');
                      ClickMouse2(1);
                      Result:=True;
                      Exit;
                    end;
                end else
                begin
                  WriteLn('Too many attempts to find the hobgoblin, trying again soon');
                  Exit;
                end;
            end;
        end;
    end;
    Standards are a bit off there lol, but it might give you some idea's.

    Oh wait, according to that graphic he just wants to get the box with the biggest amount of color? Nebula's code will work for that as far as I can judge from the code alone.

    Script source code available here: Github

  10. #10
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    on request

    Quote Originally Posted by Brak
    Tell le jingle he needs to combine all three color tpas before going into a atpa
    Working on: Tithe Farmer

  11. #11
    Join Date
    Dec 2011
    Location
    New York, USA
    Posts
    1,242
    Mentioned
    12 Post(s)
    Quoted
    193 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    on request
    That's what I posted.

  12. #12
    Join Date
    Mar 2006
    Location
    Behind you
    Posts
    3,193
    Mentioned
    61 Post(s)
    Quoted
    63 Post(s)

    Default

    Guidance to the solution. Is sometimes better than code as it allows the person to figure it out and understand it better. Which will motivate them to learn more

    "Sometimes User's don't need the Answer spelled out with Code. Sometimes all they need is guidance and explanation of the logic to get where they are going."

  13. #13
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    Indeed I have learned quite a bit!

    I know this isn't the best of code, as well as I suspect it could be condensed in many ways (including a T3DPointArray?), but here's what I made that actually works with some success. I suppose it's a good start, for me at least. I might try to sort the points to one side of the bank booth, given the compass angle (is that a good idea?)..

    Simba Code:
    {$i srl/srl.simba}

    type T3DPointArray = record
      T3DPA: Array of T2DPointArray;
    end;

    var
    //  ResultArr: T3DPointArray;
      CollectResArr: T2DPointArray;
      MSArr, ClearFromMS: TPointArray;
      SearchCols: TIntegerArray;

    procedure Declare_Vars;
    begin
      SearchCols := [15132400,1184275,4137771,7576523,3362139,1930439];
    end;

    function BestSaturatedBox(Colors: TIntegerArray; Tol: Integer): boolean;
    var
      hColors, hCollected: Integer;
      i, ii, t: integer;
      TempResult, TempGather: TPointArray;
    begin
      result := false;
      if not loggedin then
        exit;
      ClearFromMS := TPAFromBox(IntToBox(240, 130, 275, 185));
      hColors := High(Colors);
      SetLength(CollectResArr, Length(Colors));
      hCollected := High(CollectResArr);
      MarkTime(t);

      for i := 0 to hColors do
      begin
        if FindColorsTolerance(MSArr, colors[i], MSX1, MSY1, MSX2, MSY2, tol) then  // Finds the 1st indexed Color
        begin
          ClearTPAFromTPAWrap(MSArr, ClearFromMS, MSArr);                           // Clears any of the 1st indexed color from our Player's Box
          TPAToATPAExWrap(MSArr, 50, 50, CollectResArr);                            //Make all occurences of the TPA to an ATPA, in which we want to save.
        end;
        for ii := 0 to hCollected do
        begin
          QuickATPASort(Colors, CollectResArr, 0, hCollected, false);
          writeln(colors); // +
          writeln(collectresarr); // +
          TempResult := CollectResArr[ii];
          SortTPAFrom(TempResult, Point(90,270{MSX1, MSY2}));
          writeln(tempresult); // +
          if (Length(TempResult) < 1) then
          begin
            writeln(tempgather);
            writeln('not enough matches');
            break;
          end
          else
          begin
            MMouse(TempResult[ii].x, TempResult[ii].y, 5, 5);
            ClickMouse2(Mouse_Right);
            WaitOption('nk Ba', 1500);
            Result := True;
            Exit;
          end;
        end;
      end;
      WriteLn('Time Elasped: ' + ToStr(TimeFromMark(t)) + '.');
    end;

    begin
      SetupSRL;
      ActivateClient;
      Declare_Vars;
      if BestSaturatedBox(SearchCols, 5) then
        writeln('yes')
      else
        writeln('no');
    end.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •