Page 1 of 2 12 LastLast
Results 1 to 25 of 47

Thread: The Big "Write a Portal Finder" competition!

  1. #1
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default The Big "Write a Portal Finder" competition!

    The Big "Write a Portal Finder" competition!

    Hiya!

    It's been a while since the last competition and it is time for a small one methinks. This competition is not official, meaning there is probably not an official cup, but maybe I can will bribe an admin to give you one. Can't promise anything though .

    The Challenge
    The challenge is easy yet hard: write a portal finder for in the essence mine! It's a fun object because it's pretty transparent, changes colors randomly when switching worlds, it is small and it has movement.

    The Rules
    • Collaboration allowed
    • 100% colour
    • No custom plugins! Pure simba code only
    • It's for use in RS3
    • Must work in both DirectX, OpenGL and maybe safe mode?
    • Using other's work is allowed (with permission), plagiarism is NOT.
    • Competition is open for anyone, from registered user to SRL Senior Developer Administrator


    The Marking criteria
    You will be marked both quantitatively and qualitatively. I had the following marks in mind:
    • Success rate
    • Accuracy (wacky mouse-movements)
    • Speed
    • Maintainability (can I understand your function and update it if necessary? Is it commented well?)
    • Cool techniques
    • Sexy debug output (a few plots on the (SMART) debug screen are fine, don't overdo it)



    The Testing
    A function which isn't working in a script is quite a useless function. Therefore, your function will be tested live during some trial runs in my essminer!
    Your function will be modified to keep track of the following:
    • Times function called
    • Time spent processing
    • Mouse movements made
    • Success/Failure

    After that, yours and all other functions will be added to the script. As all portal finders are in the script, they will all be used. Using a simple random(), it is determined which portal finder is to be tested. If the first one fails, a new random one is drawn until once succeeds. If all portal finders fail, a screenshot will be taken and the failure won't be counted against you, the script probably messed up.
    After sufficient trials (I'm aiming for at least 25 tries per function, so that'll mean a lot of rune ess for me) the results will be analysed and the winner announced!

    The Prize
    The top portal finders will find a nice place in my updated essence miner. The top 3 will be included because redundancy is good.
    Of course there will also be a bit of gp's. Thanks to generous donations of @The Mayor; and @Harrier;, the prize fund include the following:

    RS3 GP
    • 30M for the winner
    • 15M for the runner-up
    • 8M for the third place


    OSR GP
    • 3M for the winner
    • 2M for the runner-up
    • 1M for the third place


    As you can see, it is nothing special but fun nevertheless! hint, all donations for in the prize fund are welcome =D
    Of course, my eternal thanks, everlasting fame and a place in the most popular script of all time is also part of the deal.

    The Deadline
    The deadline will be October 7th, so I can start grading the functions. The winners will be announced within a month from then (got exams going around that period).

    The FAQ
    How can we submit stuff?
    You are free to post it here, if you want it secret, PM me. Please note that by participating, you are allowing me to use your function in a public script.

    What is the deadline?
    The deadline is after I got a couple of working submissions, lets just say it's October 7th

    Will the prize have to be shared if we collaborate?
    If you aren't something ridiculous like a 10-person team, I might be able to reward you all.

    What should the function look like?
    The function should require no parameters and only return a boolean true or false. The function will click the portal itself.
    You will not have to perform any walking or location detection, the portal will be visible on the mainscreen. This match is 100% about the object finding!

    Can I use that portal finder I wrote 5 years ago?
    You can use anything priorly written, as long as it works! No original work required.

    Are multiple entries allowed?
    Yes! But you can only win one prize to keep it fair.

    Is legacy mode allowed?
    The function will have to support the default SRL graphics settings. As SRL doesn't support legacy mode, your function should be able to function without it.
    I've been told it's only the interface which is different, so you shouldn't have any problems with this.

    Can I bribe you?
    I drink my coffee with milk & sugar or black depending on my mood, my favourite beer is Duvel. You can find me in the 040 and 0118 area, occasionally in 013, 020 and 030. Don't understand these numbers? Don't even bother then, they are Dutch

    No but still, how can I win?
    Besides by scoring high on the scoring criteria, I love transformations! If you use a Gabor, LaPlace, Fourier or maybe even wavelets, you will get a LOT of bonus points and I'll ignore all other rules.

    When will the competition start?
    Right now, you lazy fool!


    Any questions? Feel free to post/PM/email/IRC/text/call them

    Good luck!
    Last edited by Markus; 09-25-2014 at 01:42 PM.

  2. #2
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    Here are three portal finders by @J J; and @euphemism; They are currently broken but used to present state-of-the-art techniques on finding it! They are currently broken, but you might be able to fix them

    This first one is by J J, it uses a traditional approach to find the portal by using the colours. It used to be very reliable but it is not toooo original.
    Simba Code:
    function FindPortal3(var x, y : integer) : boolean; //By J J, thanks!
    var
      PortalColors: TPointArray;
      Splitted: T2DPointArray;
      P: TPoint;
      i, smallestX, smallestY, biggestX, biggestY, xSize, ySize: Integer;

    begin
      // Attempts to find the portal colors
      //ColorToleranceSpeed(2);
      //SetColorSpeed2Modifiers(4.71, 2.55);
      if FindColorsSpiralTolerance(MainScreen.CX, MainScreen.CY, PortalColors, 13489057, mainscreen.getbounds(), 20, colorSetting(2, 4.71, 2.55)) then
      begin
        (* Colors have been found, they will be drawn on SMART in the color red
           After that it will get splitted into an ATPA with a distance of 3 *)

    {$IFDEF SMARTDRAW} try
        SMART_DrawDotsEx(True, PortalColors, clRed);  except end;
    {$ENDIF}
        Splitted := SplitTPA(PortalColors, 3);
        SortATPASize(Splitted, True);

        (* ATPA has been sorted on size, large to small. The biggest one will get
           drawn on SMART in the color cyan. A box around will also be drawn. *)

    {$IFDEF SMARTDRAW} try
        SMART_DrawDotsEx(False, Splitted[0], clAqua);
        SMART_DrawBoxEx(False, False, GetTPABounds(Splitted[0]), clGreen);   except end;
    {$ENDIF}

        // Calculating the X and Y size of our best TPA
        smallestX := MainScreen.X2;
        smallestY := MainScreen.Y2;
        for i:=0 to high(Splitted[0]) do
        begin
          // Check if the X is bigger or smaller than our extreme values
          if Splitted[0][i].x < smallestX then
            smallestX := Splitted[0][i].x
          else
            if Splitted[0][i].x > biggestX then
              biggestX := Splitted[0][i].x;

          // Check if the Y is bigger or smaller than our extreme values
          if Splitted[0][i].y < smallestY then
            smallestY := Splitted[0][i].y
          else
            if Splitted[0][i].y > biggestY then
              biggestY := Splitted[0][i].y;
        end;

        (* Calculating the actual size. We take 40% of the size because the outline
           of a circle is two times the radius. To be sure we click on a clickable
           part we take 40% instead of 50%. *)


        //writeln('bigggestX : ' + IntToStr(biggestX) + ' en smallestX: ' + IntToStr(smallestX));
        //writeln('bigggestY : ' + IntToStr(biggestY) + ' en smallestY: ' + IntToStr(smallestY));
        xSize := ((biggestX - smallestX) * 4) div 10;
        ySize := ((biggestY - smallestY) * 4) div 10;

        (* The middle of the biggest TPA will get calculated and we will move the
           mouse to a spot around the middle. We draw this oval on SMART. *)

        P := MiddleTPA(Splitted[0]);
    {$IFDEF SMARTDRAW}  try
        SMART_DrawEllipse(False, P, xSize, ySize, False, clYellow); except end;
    {$ENDIF}
        MouseOval(P.x, P.y, xSize, ySize, 2);

        // Checking if the uptext is correct
        if isMouseOverText(['nter', 'ortal', 'Enter', 'Portal', 'tal', 'ter'], 500) then   //WaitUptextMulti -> isMouseOverText?
        begin
          (* The uptext is correct, the portal has been detected! We perform a
           left mouse click and wait until we have stopped moving. Result = true *)

          //ClickMouse2(1);
          //FFlag(0);
          //while IsMoving do
          //  Wait(RandomRange(100, 200));
          Result := True;
          x := P.x;   //Small modification to account for the rest of the script
          y := P.y;
          m_Debug('Portal found with FindPortal3!');
        end;

      end;
    end;

    The second one is by our fello euphemism. It uses a different approach: look for everything that is not a portal, then the portal will be left! It's pretty effective, but slow, and it'll also see other players as a portal. That's why it was second choice.
    Simba Code:
    // Half-broken
    function FindPortal2(var cx, cy: Integer; force : boolean): Boolean; //by euphemism, thanks!
    var
      Area, ColorSpeed, EdgeColor, EdgeTol, GroundColor, GroundTol, I, Match,
       WallColor, WallTol: Integer;
      TestPoint: TPoint;
      EdgeHue, EdgeSat, GroundHue, GroundSat, WallHue, WallSat: Extended;
      CharBox, AreaBox, SearchBox: TBox;
      CharTPA, ColorsTPA, NewTPA, EdgeTPA, SearchTPA: TPointArray;
      ResultsATPA, NewATPA: T2DPointArray;
    begin

      //ColorSpeed := GetColorToleranceSpeed;
      //ColorToleranceSpeed(2);
      //SetToleranceSpeed2Modifiers(0.37, 1.57);
      Match := 0;
      Result := False;

      CharBox := IntToBox(MainSCreen.CX - 14, MainScreen.CY - 21, MainSCreen.CX + 12, MainSCreen.CY + 16);
      CharTPA := TPAFromBox(CharBox);

      //SearchBox := IntToBox(MSX1, MSY1, MSX2, MSY2);
      //SearchBox := IntToBox(201, 123, 320, 231); //FASTER, BUT THIS ONLY WORKS IF YOU ARE ADJACENT TO THE PORTAL
      SearchBox := IntToBox(MainSCreen.CX - 80, MainSCreen.CY - 80, MainSCreen.CX + 80, MainSCreen.CY + 80);
      SearchTPA := TPAFromBox(SearchBox);

      GroundColor := 7047023; GroundHue := 0.72; GroundSat := 0.22; GroundTol := 43;
      WallColor   := 16180721; WallHue  := 3.42; WallSat   := 7.34; WallTol   := 4;
      EdgeColor   := 10391949; EdgeHue  := 0.16; EdgeSat   := 0.23; EdgeTol   := 28;

      //Find ground colours
      //SetToleranceSpeed2Modifiers(GroundHue, GroundSat);
      if not FindColorsTolerance(NewTPA, GroundColor, searchbox, GroundTol, colorSetting(2, GroundHue, GroundSat)) then
        Exit;

      //Find wall colours
      SetToleranceSpeed2Modifiers(WallHue, WallSat);
      FindColorsTolerance(ColorsTPA, WallColor, SearchBox.x1, SearchBox.y1,
       SearchBox.x2, SearchBox.y2, WallTol);

      //Finds wall colours
      ColorsTPA := CombineTPA(ColorsTPA, NewTPA);

      //Add edge colours, too
      SetToleranceSpeed2Modifiers(EdgeHue, EdgeSat);
      FindColorsTolerance(EdgeTPA, EdgeColor, SearchBox.x1, SearchBox.y1,
       SearchBox.x2, SearchBox.y2, EdgeTol);

      //SearchTPA is the entire box we are searching in,
      //We remove our own character and all other points from it
      AppendTPA(ColorsTPA, EdgeTPA);
      NewTPA := ClearTPAFromTPA(SearchTPA, ColorsTPA);
      ColorsTPA := ClearTPAFromTPA(NewTPA, CharTPA);

      ResultsATPA := SplitTPA(ColorsTPA, 1);
      SetLength(NewATPA, 0);

      //This thing is still a miracle to me (Markus)
      for I := 0 to High(ResultsATPA) do
      begin

        AreaBox := GetTPABounds(ResultsATPA[i]);
        Area := ((AreaBox.X2 - AreaBox.X1) * (AreaBox.Y2 - AreaBox.Y1));

        //Probably filters based on not being too small/large, portals arent big
        if (InRange(Area, 500, 1500) and (InRange(Length(ResultsATPA[i]), 250,
         1200))) then
        begin

          SetLength(NewATPA, Length(NewATPA) + 1);
          NewATPA[Match] := ResultsATPA[i];
          Inc(Match);
        end;
      end;

      //When no points left, no point to contine
      if Length(NewATPA) = 0 then
        Exit;

      SortATPAFromMidPoint(NewATPA, MainScreen.getcenterpoint);

      //Regular (A)TPA iteration
      for I := 0 to High(NewATPA) do
      begin

        TestPoint := MiddleTPA(NewATPA[i]);
          {$IfDef SMARTDRAW}                 try
          //Flashes the points, though noone watches it.
          Smart_DrawDotsEx(True, NewATPA[i], clFuchsia);
          m_DrawSmartLines;
           except end;
          {$EndIf}
        MMouse(TestPoint.x, TestPoint.y, 5, 5);
        writeln('P2: '+GetUpText);
        if WaitUpTextMulti(['Enter', 'Portal', 'nter', 'ortal', 'er P'], 500) then
        begin
          Result := True;
          m_debug('Portal found with FindPortal2!');
          cx := TestPoint.x;
          cy := TestPoint.y;
          Break;
        end else
        if force then
        begin
          ClickMouse2(false);
          if WaitOptionEx('eleport', 'all', clickLeft, 500) then
          begin
            cx := TestPoint.x;
            cy := TestPoint.y;
            result := true;
            break;
          end
        end;
      end;
    end;

    The third portal finder is also by euphemism. It uses some of Simba's bitmap manipulating tricks to isolate the portal from the background and then search that image. It worked around 2012 but not that effectively. That's why it was the 3rd portal finder in a row in the script. It could, however, function on a couple of edge cases where the others failed horribily.
    Simba Code:
    //No idea
    //by euphemism, try #2
    function FindPortal(var X, Y: Integer; force : boolean): Boolean;
    var
      x1, y1, x2, y2, W, H: Integer;
      CTS, ClientBitmap, I, Len: Integer;
      GrabBox: TBox;
      TPA: TPointArray;
      ATPA: T2DPointArray;
      ITarget, KMTarget: Integer;
    begin

      Result := False;
     // CTS := GetColorToleranceSpeed;
      //SetColorToleranceSpeed(2);

      //Grabs rectangle around player, something like 7x6 tiles
      ClientBitmap := BitmapFromClient(125, 65, 380, 265);
      SetBitmapName(ClientBitmap, 'ClientGrab');

      //Changes Simba's target to the bitmap we just made
      KMTarget := GetKeyMouseTarget;
      ITarget := GetImageTarget;
      SetTargetBitmap(ClientBitmap);

      //Applies bitmap filters to make it easier to single out portal
      {$IfDef LAPE} //defines could be removed, but this just works.
      InvertBitmap(ClientBitmap);
      PosterizeBitmap(ClientBitmap, 15);
      ContrastBitmap(ClientBitmap, 1);
      BrightnessBitmap(ClientBitmap, 15);
      {$Else}
      GetMufasaBitmap(ClientBitmap).Invert(GetMufasaBitmap(ClientBitmap));
      GetMufasaBitmap(ClientBitmap).Posterize(GetMufasaBitmap(ClientBitmap), 15);
      GetMufasaBitmap(ClientBitmap).Contrast(GetMufasaBitmap(ClientBitmap), 1);
      GetMufasaBitmap(ClientBitmap).Brightness(GetMufasaBitmap(ClientBitmap), 15);
      {$EndIf}

      GetClientDimensions(W, H);

      x1 := 0; y1 := 0; x2 := W - 1; y2 := H - 1;

      //Filters out most of the ground, painting it white on bitmap
      //SetColorSpeed2Modifiers(0.30, 0.58);

      FindColorsTolerance(TPA, 5135981, IntToBox(x1, y1, x2, y2), 29, colorSetting(2, 0.30, 0.58));
      Len := Length(TPA);
      for I := 0 to (Len - 1) do
        FastSetPixel(ClientBitmap, TPA[i].x, TPA[i].y, clWhite);

      //Filters out most of rocks and trees, painting them white on bitmap
      //SetColorSpeed2Modifiers(1.25, 0.21);
      FindColorsTolerance(TPA, 9344658, x1, y1, x2, y2, 20, colorSetting(2, 1.25, 0.21));
      Len := Length(TPA);
      for I := 0 to (Len - 1) do
        FastSetPixel(ClientBitmap, TPA[i].x, TPA[i].y, clWhite);

      //Turns bitmap to greyscale and ups contrast, making portal more or less black, and most everything left a lighter grey
      {$IfDef LAPE}
      GreyScaleBitmap(ClientBitmap);
      ContrastBitmap(ClientBitmap, 4);
      {$Else}
      GetMufasaBitmap(ClientBitmap).GreyScale(GetMufasaBitmap(ClientBitmap));
      GetMufasaBitmap(ClientBitmap).Contrast(GetMufasaBitmap(ClientBitmap), 4);
      {$EndIf}

      //Finds the black of the portal
      SetColorToleranceSpeed(0);
      if not FindColorsTolerance(TPA, 2236962, x1, y1, x2, y2, 34) then
        Exit;

      SplitTPAWrap(TPA, 5, ATPA);
      SortATPASize(ATPA, True);
      Len := Length(ATPA);

      //Loops through black groups to find one with correct dimensions
      for I := 0 to (Len - 1) do
      begin

        GrabBox := GetTPABounds(ATPA[i]);

        W := (GrabBox.x2 - GrabBox.x1);
        H := (GrabBox.y2 - GrabBox.y1);

        if (not (InRange(W, 25, 38) and InRange(H, 15, 38))) then
          Continue;

        TPA[0] := MiddleTPA(ATPA[i]);
        OffSetTPA(TPA, IntToPoint(125, 65));

        X := TPA[0].x;
        Y := TPA[0].y;

      //Debug image--------------------
      // note by Markus: replace by Smart Graphics
      if ((result)) then
      begin
      Len := Length(ATPA[i]);
      for W := 0 to (Len - 1) do
        FastSetPixel(ClientBitmap, ATPA[i][W].x, ATPA[i][W].y, clFuchsia);
    {$IfDef SMARTDRAW}
      SMART_DrawBitmap(true, ClientBitmap, IntToPoint(GrabBox.x1, GrabBox.Y1));
    {$EndIf}
    //  DisplayDebugImgWindow(0,0);
    //  DisplayDebugImgWindow(255,200);
    //  DrawBitmapDebugImg(ClientBitmap);
      end;

        MMouse(x, y, 5, 5);
        writeln('P1: '+GetUpText);
        if (not(WaitUpTextMulti(['nter', 'ortal', 'Ent', 'Port', 'er P'], 500))) then
        if force then
        begin
          ClickMouse2(false);
          if not WaitOptionEx('eleport', 'all', clickLeft, 500) then
            continue;
        end;
        Result := True;
        m_debug('Portal found with FindPortal!');
        Break;
      end;


      //-------------------------------

      //Sets Simba's target back to SMART
      FreeTarget(GetImageTarget);
      SetKeyMouseTarget(KMTarget);
      SetImageTarget(ITarget);

      SetColorToleranceSpeed(CTS);
      FreeBitmap(ClientBitmap);
    end;
    I made a new script, check it out!.

  3. #3
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    I think I have found a reason to come back and make a rs3 script


    Question: So does the script just have to find a way out of the essence mine essentially?

  4. #4
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    It only has to find the portal on the mainscreen! No walking or other difficult things required as the rest of the script is already finished x)

    Edit: you will already be standing close to the portal. It will be visible and only a few tiles from your character.
    I made a new script, check it out!.

  5. #5
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Markus View Post
    It only has to find the portal on the mainscreen! No walking or other difficult things required as the rest of the script is already finished x)

    Edit: you will already be standing close to the portal. It will be visible and only a few tiles from your character.
    Can I use legacy mode?

  6. #6
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    I guess I can give it a go...

  7. #7
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    As SRL is not compatible with legacy mode, you are not allowed to use legacy mode.

  8. #8
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

  9. #9
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    Quote Originally Posted by Robert View Post
    Can I use legacy mode?
    Legacy mode has only interface differences so if it can find it in legacy mode it can find it in RS3 mode.

  10. #10
    Join Date
    Dec 2011
    Posts
    2,147
    Mentioned
    221 Post(s)
    Quoted
    1068 Post(s)

  11. #11
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    Quote Originally Posted by Clarity View Post




    @bonsai
    @slacky

    I only added a few lines myself for the specific situation, 99% their work.
    Nice use of the movement detection!

    What happens when someone walks near you, though?

  12. #12
    Join Date
    Dec 2011
    Posts
    2,147
    Mentioned
    221 Post(s)
    Quoted
    1068 Post(s)

    Default

    Quote Originally Posted by NKN View Post
    Nice use of the movement detection!

    What happens when someone walks near you, though?
    A similar procedure for how I blocked out the motion detected around the player.

    One can expect that the portal will be of certain dimensions that will vary slightly due to camera angle/position, but not by a lot.
    One can also expect the general color range the portal will be. So if motion detection finds an awkwardly large box, or a box with weird/random colors in it, those other checks will disregard it and remove it from possible portal matches.

    Those checks would fail miserably without the limiting scope of the motion detection. Combining the detection and the color/size checks makes it flawless.

    In the rare case a player walks onto the portal while looking for it, the presence of mouseOverText would confirm its existence there.

  13. #13
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    Progress Report:
    -- Beginning portal detection
    ---- Symbol position at: {X = 683, Y = 109}
    ---- Player position at: {X = 687, Y = 106}
    ---- Distance between the two points is: 5
    -- Finished finding the portal in: 16ms


    I'll post it once I get back from dinner.


    Edit:


    It automatically walks to the portal if you're too far away from it.
    Otherwise, it'll go ahead and detect where you are.

    Gonna add comments then I'll post the full code.

    31 ms though, if near the portal. c:



    Simba Code:
    {
      SetSymbol is the lower portion of the minimap symbol.  Looks like a down arrow, the very bottom tip of it.
      This simply sets a ddtm.
    }

    function SetSymbol: Integer;
    var
      dtmMainPoint: TSDTMPointDef;
      dtmSubPoints: TSDTMPointDefArray;
      TempTDTM: TSDTM;
    begin
      SetArraylength(dtmSubPoints,5);
      dtmMainPoint.x := 2803;
      dtmMainPoint.y := 375;
      dtmMainPoint.AreaSize := 0;
      dtmMainPoint.AreaShape := 0;
      dtmMainPoint.Color := 12552820;
      dtmMainPoint.Tolerance := 40;

      dtmSubPoints[0].x := 2803;
      dtmSubPoints[0].y := 375;
      dtmSubPoints[0].AreaSize := 0;
      dtmSubPoints[0].AreaShape := 0;
      dtmSubPoints[0].Color := 12552820;
      dtmSubPoints[0].Tolerance := 40;

      dtmSubPoints[1].x := 2796;
      dtmSubPoints[1].y := 368;
      dtmSubPoints[1].AreaSize := 0;
      dtmSubPoints[1].AreaShape := 0;
      dtmSubPoints[1].Color := 14461071;
      dtmSubPoints[1].Tolerance := 40;

      dtmSubPoints[2].x := 2809;
      dtmSubPoints[2].y := 367;
      dtmSubPoints[2].AreaSize := 0;
      dtmSubPoints[2].AreaShape := 0;
      dtmSubPoints[2].Color := 14724755;
      dtmSubPoints[2].Tolerance := 40;

      dtmSubPoints[3].x := 2804;
      dtmSubPoints[3].y := 365;
      dtmSubPoints[3].AreaSize := 0;
      dtmSubPoints[3].AreaShape := 0;
      dtmSubPoints[3].Color := 1805019;
      dtmSubPoints[3].Tolerance := 40;

      dtmSubPoints[4].x := 2802;
      dtmSubPoints[4].y := 358;
      dtmSubPoints[4].AreaSize := 0;
      dtmSubPoints[4].AreaShape := 0;
      dtmSubPoints[4].Color := 15254443;
      dtmSubPoints[4].Tolerance := 40;

      TempTDTM.MainPoint := dtmMainPoint;
      TempTDTM.SubPoints := dtmSubPoints;
      Result := AddSDTM(TempTDTM);
    end;
    {
      It was a pain writing multiple SimilarColor statements in a if statement, so this checks multiple.
    }


    function SimilarColorMulti(color,tolerance:integer; colors:TIntegerArray):boolean;
    var
      i:integer;
    begin
      for i := 0 to high(colors) do
      begin
        if(similarColors(color,colors[i],tolerance)) then
          exit(1);
      end;
    end;


    {
      Returns the point it finds the portal at.
    }

    function enterPortal(var pnt:TPoint):boolean;
    var
      tpa,final:TpointArray;
      mmLocation, symbolPoint:TPoint;
      symbol,x,y,dist,i:integer;
      colors,clear:TIntegerArray;
      marker:TTimeMarker;
      box:TBox;
      angle:extended;
    begin
      try
        marker.start;
        print('Beginning portal detection',TDebug.HEADER);
        symbol := setSymbol; //Sets the DDTM;
        if(FindDTMRotated(symbol,x,y,Minimap.getBounds,-Pi,Pi,Pi/60,Angle)) then
        begin
          SymbolPoint := Point(x,y+5); //We want to detect under the point, as the portal is a few pixels below it.
          print('Symbol position at: '+ToStr(symbolPoint),TDebug.DEBUG);
          print('Player position at: ' + ToStr(minimap.getCenterPoint),TDebug.DEBUG);
          dist := Distance(symbolPoint,minimap.getCenterPoint);  //Calculate the distance between the portal and you.
          print('Distance between the two points is: ' + ToStr(dist), TDebug.DEBUG);
          if(dist > 25) then //If you're too far away, you'll move.
          begin
            Mouse(x,y,4,4,MOUSE_LEFT);
            minimap.waitFlag();
            minimap.waitPlayerMoving(250);
            if(FindDTMRotated(symbol,x,y,Minimap.getBounds,-Pi,Pi,Pi/60,Angle)) then  //Have to reset the position of the point to calculate a mainscreen point.
            begin
              print('Corrected player position',TDebug.DEBUG);
              symbolPoint := Point(x,y+5);
            end else
            begin
              print('Moved onto DTM. Using center point.',TDebug.Warning);  //If you cover the tip and the DTM won't work, this'll work instead.
              symbolPoint := Point(minimap.getCenterPoint.x,minimap.getCenterPoint.y+5);
            end;
          end;
          mmLocation := minimap.pointToMainscreen(symbolPoint); //Convert the point to a mainscreen point.
          box := IntToBox(mmLocation.x - 35, mmLocation.y - 35, mmLocation.x + 35, mmLocation.y+25); //Make a small box surrounding it.
          smartImage.drawBox(box,false,clPurple);
          tpa := box.createTPA; //Creates a TPA from every point in the box
          for i := 0 to high(tpa) do
            if(not(similarColorMulti(GetColor(tpa[i]),18,[10722453,9604741,12105129,8091505,14735566,12564912,13353915,16777215,12498100,16248301,7565161]))) then //In the array are the colors of the floor/walls around it.  Add more if it becomes unreliable.
              Insert(tpa[i],final);
          pnt := MiddleTPA(final); //Middle of the tpa is our return point.
          result := true;
          smartImage.debugTPA(final);
          smartImage.drawCross(pnt,5,clRed);
          print('Finished finding the portal in: '+ToStr(marker.getTime)+'ms',TDebug.Footer);
        end;
      finally
        FreeDTM(symbol);
      end;

    end;
    Last edited by NKN; 09-24-2014 at 12:37 AM.

  14. #14
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    My first thought was to use a BitmapMask. It used to work in Scar but Simba's masks are weird for me :S.. In fact, it still does work in Scar. Just not Simba. So.. I did something else for Simba..

    I got this working (SOMETIMES).. It doesn't work all time (because I don't have enough TPA's) but the idea is simple.. The portal changes colours right? But everything around it is still the same or roughly the same.

    Gather TPA's of everything (snow, thing in the middle, floor around the portal, wood walk-way, etc..) Everything except the portal. Combine them all into one TPA. Now you have a single TPA of everything except the portal (and except your character of course).

    Then invert the TPA or get the points that are NOT in it and then split by 40x40 to an ATPA. Go through that and voila.. Portal found.

    I only have 5 TPA's below but more might be needed (maybe less.. I don't know). It might seem computationally expensive but it isn't.. Not by a long shot. It's actually faster than it looks..

    My total TPA size was 176000 points. After inverting it, I ended up with just a TPA of the portal only.. I just split it and went through it and clicked it. Took a couple ms. I tried to write it without SRL-6 but I needed the debugTPA function to check what it was actually finding :l

    Simba Code:
    {$I SRL-6/SRL.Simba}

    procedure show(img: Integer);
    var
      Bmp: TMufasaBitmap;
    begin
      Bmp := GetMufasaBitmap(Img);
      DisplayDebugImgWindow(Bmp.getWidth, Bmp.getHeight);
      DrawBitmapDebugImg(Bmp.getIndex());
    end;


    Function FindPortal(MSBox: TBox): TBox;
    var
      TPA, TPA2, TPA3, TPA4: TPointArray;
      ATPA: T2DPointArray;
      CTS, I: Integer;
      P: TPoint;
    Begin
      CTS := GetToleranceSpeed;
      SetColorToleranceSpeed(2);
      SetToleranceSpeed2Modifiers(1.59, 0.22);

      FindColorsTolerance(TPA, 8228993, MSBox.X1, MSBox.Y1, MSBox.X2, MSBox.Y2, 19);

      SetToleranceSpeed2Modifiers(0.08, 0.24);
      FindColorsTolerance(TPA2, 8422037, MSBox.X1, MSBox.Y1, MSBox.X2, MSBox.Y2, 22);

      SetToleranceSpeed2Modifiers(3.34, 5.11);
      FindColorsTolerance(TPA3, 14349274, MSBox.X1, MSBox.Y1, MSBox.X2, MSBox.Y2, 10);

      SetToleranceSpeed2Modifiers(0.07, 0.61);
      FindColorsTolerance(TPA4, 12563629, MSBox.X1, MSBox.Y1, MSBox.X2, MSBox.Y2, 10);


      TPA := CombineTPA(CombineTPA(TPA, TPA2), CombineTPA(TPA3, TPA4));
      TPA := ReturnPointsNotInTPA(TPA, MSBox); //not sure the difference between this and InvertTPA(TPA);
      ATPA := TPAToATPAEx(TPA, 38, 38);

      SortATPAFromFirstPoint(ATPA, MiddleBox(MSBox));
      Result := IntToBox(-1, -1, -1, -1);

      For I := 0 To High(ATPA) Do
      Begin
        P := MiddleTPA(ATPA[I]);
        Mouse(P, MOUSE_MOVE);
        if (isMouseOverText(['rtal'], 50, true)) Then
        begin
          Result := GetTPABounds(ATPA[I]);
          break;
        end;
      End;

      DebugATPA(ATPA);

      SetColorToleranceSpeed(CTS);
      SetToleranceSpeed2Modifiers(0.2, 0.2);
    End;

    var
      MSBox: TBox;
    begin
      ActivateClient;
      MSBox := IntToBox(0, 0, 575, 330);
      FindPortal(MSBox);
    end.
    Last edited by Brandon; 09-24-2014 at 12:31 AM.
    I am Ggzz..
    Hackintosher

  15. #15
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    Quote Originally Posted by Brandon View Post
    TPA := ReturnPointsNotInTPA(TPA, MSBox); //not sure the difference between this and InvertTPA(TPA);
    An awful name, ReturnPointsNotInTPA is indeed what you want.. InvertTPA reverses the TPA order.

  16. #16
    Join Date
    Jun 2014
    Location
    Vancouver
    Posts
    150
    Mentioned
    1 Post(s)
    Quoted
    89 Post(s)

    Default

    I wish I had time to take a stab! University is a birch.....

    Goodluck to everyone!

  17. #17
    Join Date
    Oct 2013
    Location
    East Coast USA
    Posts
    770
    Mentioned
    61 Post(s)
    Quoted
    364 Post(s)

    Default

    Quote Originally Posted by Clarity View Post
    @bonsai
    @slacky

    I only added a few lines myself for the specific situation, 99% their work.
    You touched it, you own it. The only functions I published were basically getPixelshift returning tpa instead of count.

    Finish it up this is probably a contender for slow but highly accurate. That's the problem with motion, you need to wait for it to happen. It may be interesting to see what motion you see if you take faster snaps. I had to wait like 75ms to get a good batch of info but smaller waits did get data as it painted.

    Quote Originally Posted by NKN View Post
    Progress Report:
    -- Beginning portal detection
    ---- Symbol position at: {X = 683, Y = 109}
    ---- Player position at: {X = 687, Y = 106}
    ---- Distance between the two points is: 5
    -- Finished finding the portal in: 16ms
    I like this one. You've basically found it before you find it.

    Quote Originally Posted by Brandon View Post
    I got this working (SOMETIMES).. It doesn't work all time (because I don't have enough TPA's) but the idea is simple.. The portal changes colours right? But everything around it is still the same or roughly the same.

    Gather TPA's of everything (snow, thing in the middle, floor around the portal, wood walk-way, etc..) Everything except the portal. Combine them all into one TPA. Now you have a single TPA of everything except the portal (and except your character of course).

    Then invert the TPA or get the points that are NOT in it and then split by 40x40 to an ATPA. Go through that and voila.. Portal found.
    In theory this should be the same as clarity's motion based find. Once you've removed all the static things you should both be left with about the same data to work with.

    I'm curious why it's so fast. I had serious issues with my autocoloring if I asked simba to findcolor a background color like black in a black place. It would hang for over a minute sometimes. I had to write my own hack finder for the first time so it wouldn't bog out.

  18. #18
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    Wow, what an overwhelming response guys. Glad to see so many young and old faces participating in this challenge!
    I've clarified the rules a bit: custom plugins are not allowed, the function will have to work with the SRL default graphics settings and the deadline is now official.
    There's also a new challenge added. If you use use any transformations to go to another domain (Fourier, Gabor, Wavelets, LaPlace) you will get instant bonus points I doubt anyone using them though but just in case..
    I made a new script, check it out!.

  19. #19
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Quote Originally Posted by Markus View Post
    Wow, what an overwhelming response guys. Glad to see so many young and old faces participating in this challenge!
    I've clarified the rules a bit: custom plugins are not allowed, the function will have to work with the SRL default graphics settings and the deadline is now official.
    There's also a new challenge added. If you use use any transformations to go to another domain (Fourier, Gabor, Wavelets, LaPlace) you will get instant bonus points I doubt anyone using them though but just in case..
    lol, transformation to any other domain such as transforming it to EG frequency domain takes a lot of time in Lape, so you might give bonus for it, but you will then substract that bonus by looking at the time-consumption. So without plugins, that is useless.

    No custom plugins = no slacky = no fancy shit from me
    Last edited by slacky; 09-24-2014 at 07:27 AM.
    !No priv. messages please

  20. #20
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    Quote Originally Posted by bonsai View Post
    ...
    You took the words out of my mouth. Great feedback!
    Are you participating yourself too?
    I made a new script, check it out!.

  21. #21
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    Quote Originally Posted by slacky View Post
    lol, transformation to any other domain such as transforming it to EG frequency domain takes a lot of time Lape, so you might give bonus for it, but you will then substract that bonus by looking at the time-consumption. So without plugins, that is useless.

    No custom plugins = no slacky = no fancy shit from me
    You can use them for the challenge, but as I can't include it in the script, you will only be contending for the bonus prize (all RSGP's I have left, around 35M). I'd really love to see the transformations so I'll ignore the time-constraint if you also supply a plugin-less version.
    highlightmeAs I still got some kind of access to SRL development, your plugin might just randomly end up in SRL making it official ^_^
    I made a new script, check it out!.

  22. #22
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

    Default

    You should only have to walk to the portal as a failsafe. If the compass can be rotated so the portal is on screen then that should be the first option (as you can single click to exit).

  23. #23
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Quote Originally Posted by bonsai View Post
    I'm curious why it's so fast. I had serious issues with my autocoloring if I asked simba to findcolor a background color like black in a black place. It would hang for over a minute sometimes. I had to write my own hack finder for the first time so it wouldn't bog out.
    It sounds as if you have been splitting the background up as well with SplitTPA, or SplitTPAEx I may add, then it will use for ever: if you are splitting such a large TPA as "the background". This is a case where ClusterTPA shines.
    !No priv. messages please

  24. #24
    Join Date
    Oct 2013
    Location
    East Coast USA
    Posts
    770
    Mentioned
    61 Post(s)
    Quoted
    364 Post(s)

    Default

    Quote Originally Posted by Markus View Post
    You took the words out of my mouth. Great feedback!
    Are you participating yourself too?
    Just gotta see how much free time this week has to offer.

    I'll probably run it through the autocoloring process to see if I can scam up some truly unique colors. I was also wondering what that scene looked like in blue but I don't know of any efficient ways of doing that yet.

    Great thread, BTW. Looks like it's going to generate some good discussion and learning material.

    Quote Originally Posted by slacky View Post
    It sounds as if you have been splitting the background up as well with SplitTPA, or SplitTPAEx I may add, then it will use for ever: if you are splitting such a large TPA as "the background". This is a case where ClusterTPA shines.
    I'm going to re-test. I thought it was purely findcolorstolerance but I see the calling function is doing a x.split() afterwards. Perhaps I blamed the wrong culprit. I did take note of you mentioning to use clustertpa previously but didn't code review yet.

    Most of my results will be small but some could be huge. Is it worth the prices of a length check? If len<xx then split else cluster?

  25. #25
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    Quote Originally Posted by Markus View Post
    Wow, what an overwhelming response guys. Glad to see so many young and old faces participating in this challenge!
    I've clarified the rules a bit: custom plugins are not allowed, the function will have to work with the SRL default graphics settings and the deadline is now official.
    There's also a new challenge added. If you use use any transformations to go to another domain (Fourier, Gabor, Wavelets, LaPlace) you will get instant bonus points I doubt anyone using them though but just in case..
    if only I knew what those transforms were, I could give it a stab. :')

Page 1 of 2 12 LastLast

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
  •