Results 1 to 17 of 17

Thread: GetFarthestSymbol(Symbol : String) : TPointArray;

  1. #1
    Join Date
    Oct 2007
    Posts
    742
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default GetFarthestSymbol(Symbol : String) : TPointArray;

    SCAR Code:
    program New_Script;
    {.Include SRL/SRL.Scar}

    var
    MySymbol : TPointArray;

    function GetFarthestSymbol(Symbol : String) : TPointArray;
    var
      MaxDistance, I, D, N: Integer;
      TheSymbols : TPointArray;
    begin
    FindSymbols(TheSymbols, Symbol);
    MaxDistance := -1;
    for I := 0 to High(TheSymbols) do
    begin
      D := Distance(TheSymbols[I].X, TheSymbols[I].Y, MMCX, MMCY)
      if (D > MaxDistance) then
      begin
        MaxDistance :=  D;
        N := I;
      end;
    end;
    Result := TheSymbols;
    WriteLn('Furthest point in TheSymbols is TheSymbols['+IntToStr(N)+']');
    end;

    begin
    SetUpSRL;
    MySymbol := GetFarthestSymbol('fish')
    Mouse(MySymbol.X, MySymbol.Y, 2, 2, True);
    end.
    What this function should do is find all of the same inputted symbol specified by the user and sort them all out by distance from the middle to find the farthest away one.

    I always get errors with it or it does not work! Can someone please copy/paste this function into their scar and test it/fix it up? I have been having troubles with this for almost a week now lol...

    THANK YOU.
    Woot woot.

  2. #2
    Join Date
    Jul 2008
    Location
    England
    Posts
    763
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Try this:

    SCAR Code:
    program New_Script;
    {.Include SRL/SRL.Scar}

    var
      MySymbol : TPoint;

    function GetFarthestSymbol(Symbol : String) : TPoint;
    var
      MaxDistance, I, D, N: Integer;
      TheSymbols : TPointArray;
    begin
      FindSymbols(TheSymbols, Symbol);
      MaxDistance := -1;
      for I := 0 to High(TheSymbols) do
      begin
        D := Distance(TheSymbols[I].X, TheSymbols[I].Y, MMCX, MMCY);
        if (D > MaxDistance) then
        begin
          Result := TheSymbols[I];
          MaxDistance :=  D;
          N := I;
        end;
      end;
      WriteLn('Furthest point in TheSymbols is TheSymbols['+IntToStr(N)+']');
    end;

    begin
      SetUpSRL;
      MySymbol := GetFarthestSymbol('fish');
      Mouse(MySymbol.X, MySymbol.Y, 2, 2, True);
    end.
    Last edited by Quickmarch; 12-10-2009 at 02:51 PM.
    lol

  3. #3
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    Why not throw in a spiral algorithm? So it will spiral inwards looking for the symbol? Just an idea
    Ce ne sont que des gueux


  4. #4
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Why don't you just do FindSymbols, followed by a SortTPAFrom(Point(MMCX, MMCY));

  5. #5
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by ZephyrsFury View Post
    Why don't you just do FindSymbols, followed by a SortTPAFrom(Point(MMCX, MMCY));
    *sigh* thats what I've been saying.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  6. #6
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    *sigh* thats what I've been saying.
    It is not just what you said, it is what everyone was saying. And your (and mine) post is really useless.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  7. #7
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    *sigh* thats what I've been saying.
    Quote Originally Posted by Wizzup? View Post
    It is not just what you said, it is what everyone was saying. And your (and mine) post is really useless.
    Huh? Am I missing something?

  8. #8
    Join Date
    Feb 2009
    Location
    Hungary (GMT + 1)
    Posts
    1,774
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by ZephyrsFury View Post
    Huh? Am I missing something?
    This: http://www.villavu.com/forum/showthread.php?t=53293 ?

  9. #9
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    This solution is actually faster than SortTPAFrom, no swapping etc.

  10. #10
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    If this is about speed, why'd you use the distance function?

  11. #11
    Join Date
    Mar 2007
    Posts
    3,116
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by nielsie95 View Post
    If this is about speed, why'd you use the distance function?
    Cause distance is faster...

  12. #12
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    The easiest solution is for you to just actually know what you are doing.

    Naum has a very nice tut on the Wizzy plugin that I highly suggest you look through.
    http://www.villavu.com/forum/showthread.php?t=49067

    Just trying to copy/paste other people's function bit's isn't going to help you learn anything.

  13. #13
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by marpis View Post
    This solution is actually faster than SortTPAFrom, no swapping etc.
    Well I'm confused as to why his function would return a TPA as opposed to a TP. I assumed he wanted them sorted.

  14. #14
    Join Date
    Jan 2008
    Location
    NC, USA.
    Posts
    4,429
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Quote Originally Posted by ZephyrsFury View Post
    Well I'm confused as to why his function would return a TPA as opposed to a TP. I assumed he wanted them sorted.
    Yea. emmm. You're correct.

    Ultra, you have it return a TPA. I think you mean TP. You should be getting errors with the last few lines, as well. You're trying to make a TPA a TP

    TPA != TP

    Edit: QuickMarch did it right
    Last edited by noidea; 12-11-2009 at 06:14 AM.
    Quote Originally Posted by irc
    [00:55:29] < Guest3097> I lol at how BenLand100 has become noidea
    [01:07:40] <@BenLand100> i'm not noidea i'm
    [01:07:44] -!- BenLand100 is now known as BenLand42-
    [01:07:46] <@BenLand42-> shit
    [01:07:49] -!- BenLand42- is now known as BenLand420
    [01:07:50] <@BenLand420> YEA

  15. #15
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Quote Originally Posted by MylesMadness View Post
    Cause distance is faster...
    You sure?

    SCAR Code:
    x := p[i].x - MMCX;
    y := p[i].y - MMCY;
    Dist := x*x + y*y;

  16. #16
    Join Date
    Mar 2007
    Posts
    3,116
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by nielsie95 View Post
    You sure?

    SCAR Code:
    x := p[i].x - MMCX;
    y := p[i].y - MMCY;
    Dist := x*x + y*y;
    If he was tying to find the farthest point like he was, yes I am

  17. #17
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    SCAR Code:
    program New;

    const
      MMCX = 574;
      MMCY = 118;

      function QueryPerformanceFrequency(out Frequency: Int64): LongBool; external 'QueryPerformanceFrequency@kernel32.dll stdcall';
      function QueryPerformanceCounter(out Counter: Int64): LongBool; external 'QueryPerformanceCounter@kernel32.dll stdcall';

    procedure MarkTime(var Time: Int64);
    var
      Freq: Int64;
    begin
      if QueryPerformanceFrequency(Freq) then
        QueryPerformanceCounter(Time)
      else
        Time := GetTickCount;
    end;

    function TimeFromMark(Mark: Int64): Double;
    var
      Freq, Now: Int64;
    begin
      if QueryPerformanceFrequency(Freq) then
      begin
        QueryPerformanceCounter(Now);
        Result := ((Now - Mark) / Freq) * 1000;
      end
      else
        Result := (GetTickCount - Mark);
    end;


    var
      ii, i, h, MaxDist, Dist, Index, x, y: Integer;
      p: TPointArray;
      t: Int64;
      d: Double;
    begin
      SetLength(p, 10000);
      h := High(p);
      for i := 0 to h do
        p[i] := Point(RandomRange(-20000, 20000), RandomRange(-20000, 20000));

      MarkTime(t);
      for ii := 1 to 50 do
      begin
        MaxDist := 0;

        for i := 0 to h do
        begin
          Dist := Distance(p[i].x, p[i].y, MMCX, MMCY);
          if (Dist > MaxDist) then
          begin
            Index := i;
            MaxDist := Dist;
          end;
        end;
      end;
      d := TimeFromMark(t);
      WriteLn(Format('Distance || Result: %d -- 50 times: %fms  --  1 time: %fms', [Index, d, d / 50.0]));

      MarkTime(t);
      for ii := 1 to 50 do
      begin
        MaxDist := 0;

        for i := 0 to h do
        begin
          x := p[i].x - MMCX;
          if (x < 0) then
            x := -x;
          y := p[i].y - MMCY;
          if (y < 0) then
            y := -y;
          Dist := x + y;
          if (Dist > MaxDist) then
          begin
            Index := i;
            MaxDist := Dist;
          end;
        end;
      end;
      d := TimeFromMark(t);
      WriteLn(Format('Abs(x) + Abs(y) || Result: %d -- 50 times: %fms  --  1 time: %fms', [Index, d, d / 50.0]));

      MarkTime(t);
      for ii := 1 to 50 do
      begin
        MaxDist := 0;

        for i := 0 to h do
        begin
          x := p[i].x - MMCX;
          y := p[i].y - MMCY;
          Dist := x*x + y*y;
          if (Dist > MaxDist) then
          begin
            Index := i;
            MaxDist := Dist;
          end;
        end;
      end;
      d := TimeFromMark(t);
      WriteLn(Format('Sqr(x) + Sqr(y) || Result: %d -- 50 times: %fms  --  1 time: %fms', [Index, d, d / 50.0]));
    end.

    It's not much, but Distance seems slower.

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
  •