Results 1 to 4 of 4

Thread: Comparing Arrays

  1. #1
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default Comparing Arrays

    SCAR Code:
    program New;
    var myarray,myarray2:array[0..1]of integer;

    begin
      myarray[0]:=4;
      myarray2[0]:=4;
      myarray[1]:=5;
      myarray2[1]:=5;

     if (myarray=myarray2) then writeln('yes');

    end.

    Is there a way to do this without comparing each integer?

  2. #2
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Nvm this is pretty fast

    SCAR Code:
    function CompareIntArrays(FirstIntArray,SecondIntArray:array of integer):boolean;
    var Counter:integer;
    begin
      if not(getarraylength(FirstIntArray)=getarraylength(SecondIntArray)) then
        result:=false;


      if (getarraylength(FirstIntArray)=getarraylength(SecondIntArray)) then
      begin
        result:=true;
        repeat
          if not(FirstIntArray[Counter]=SecondIntArray[Counter]) then
            result:=false;
          Counter:=Counter+1;
        until ((Counter=getarraylength(FirstIntArray)) or (result=false));
      end;
    end;

  3. #3
    Join Date
    Feb 2006
    Location
    L.A, USA
    Posts
    1,632
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    yee, i'm bored boreas!

    SCAR Code:
    type
      tworesults =  record
        all : Boolean;
        numb : Integer;
    end;

    function HeresMyThreeSecondOne(rofl, rofl2 : array of Integer) : tworesults;
    var
      i, lel: Integer;
    begin
      if(not(getarraylength(rofl)) <> (getarraylength(rofl2)))then
        Result.all := false;
      lel:= getarraylength(rofl) - 1
      for i:= 0 to lel do
        if(samevalue(rofl[i], rofl2[i]))then
          Result.numb:= Result.numb + 1;
      if (Result.numb = lel) then
        Result.all:= true;
    end;

    Results number of matches matched if all, then Result.all verifies true.

    Wrote it in a minute or two. sorry for mistakes. 8)

    EDIT: put a comma instead of a period, woops. i'm a nub.

    p.s you should make a runescape script. i'd hacks/learn from it ALOT!! D :]]

  4. #4
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Thanks, I may use that for something else, but right now I need it to be completely the same. Here's the teeny piece of a runescape script/include I'm using it for.
    SCAR Code:
    program New;
    {.include SRL/SRL.scar}
    var MyList:TPointArray;
    var tmpList,tmpList2:array of integer;


    var t:integer;
    {*******************************************************************************
    function Create40PercentTPA:TPointArray;
    By: Boreas
    Note: Purely an internal function, used in setup.
    Description: Returns a TPointArray containing the relative (to x1,y1 of a BSlot)
    for 385 points (out of 31*31, hence 40%). Only needs to be done once, to create
    the list of points to check for 65536. Only takes like 15ms, and I didn't
    feel like typing them all out.
    *******************************************************************************}

    function Create40PercentTPA:TPointArray;
    var Counter,hx,hy:integer;
      var TPointsToCheck:array [0..384] of TPoint;
    begin
      repeat
        hy:=15;
        hx:=hx+1;
        repeat
          hy:=hy+1;
          if (((hx mod 4)=0) or ((hy mod 4)=0)) then
          begin
            TPointsToCheck[Counter].x:=hx;
            TPointsToCheck[Counter].y:=hy;
            Counter:=Counter+1;
          end;
        until hy=31;
      until hx=31;
      result:=TPointsToCheck;
    end;

    {*******************************************************************************
    function CreateItemBlackList(WhichBankSlot:integer;WhichList:TPointArray):array of integer;
    By: Boreas
    Description: Looks at the points in the list for an item, and returns an array
    contatining the indexes of the points that are black.
    Usage: WhichBankSlot-just what it sounds like. WhichList-the TPointArray
    containing positions relative to the x1,y1 of a bankslot which you want to check
    *******************************************************************************}


    function CreateItemBlackList(WhichBankSlot:integer;WhichList:TPointArray):array of integer;
    var Counter,Counter2,Tmpx1,Tmpy1,ListLength:integer;
    var TmpArray:array of integer;
    begin
        Tmpx1:=79+((((WhichBankSlot+7)mod 8))*47);
        Tmpy1:=62+((((WhichBankSlot-1)/8))*38);
      ListLength:=getarraylength(WhichList)-1;
      setarraylength(tmparray,1);
      for Counter:= 0 to ListLength do
      begin

        if GetColor(Tmpx1+WhichList[Counter].x,Tmpy1+WhichList[Counter].y)=65536 then
        begin
          TmpArray[Counter2]:=Counter;
          Counter2:=Counter2+1;
          setarraylength(TmpArray,Counter2+1);

        end;
      end;
      result:=TmpArray;
    end;
    {*******************************************************************************
    function CheckItemBlackList(WhichBankSlot:integer;WhichBlackList:array of integer;WhichList:TPointArray):boolean;
    By: Boreas
    Description: Returns true if an items blacklist matches the one in the parameters
    *******************************************************************************}

    function CheckItemBlackList(WhichBankSlot:integer;WhichBlackList:array of integer;WhichList:TPointArray):boolean;
    var Counter,Tmpx1,Tmpy1,ListLength:integer;
    var TheBoolean:boolean;
    begin
      Tmpx1:=79+((((WhichBankSlot+7)mod 8))*47);
      Tmpy1:=62+((((WhichBankSlot-1)/8))*38);
      ListLength:=getarraylength(WhichBlackList)-1;
      TheBoolean:=true;
      repeat
        if not(getcolor(Tmpx1+Whichlist[WhichBlacklist[Counter]].x,
           Tmpy1+Whichlist[WhichBlacklist[Counter]].y)=65536) then
           TheBoolean:=false;
        Counter:=Counter+1;
      until ((not(TheBoolean)) or  (Counter=(ListLength+1)));
      result:=TheBoolean;
    end;

    {*******************************************************************************
    function CompareIntArrays(FirstIntArray,SecondIntArray:array of integer):boolean;
    By: Boreas
    Description: Returns true both arrays are the same
    ******************************************************************************}

    function CompareIntArrays(FirstIntArray,SecondIntArray:array of integer):boolean;
    var Counter:integer;
    begin
      if not(getarraylength(FirstIntArray)=getarraylength(SecondIntArray)) then
        result:=false;


      if (getarraylength(FirstIntArray)=getarraylength(SecondIntArray)) then
      begin
        result:=true;
        repeat
          if not(FirstIntArray[Counter]=SecondIntArray[Counter]) then
            result:=false;
          Counter:=Counter+1;
        until ((Counter=getarraylength(FirstIntArray)) or (result=false));
      end;
    end;
    function intArrayToStr(intArray: array of Integer): string;
    var
      i, arrayLength: Integer;
    begin
      arrayLength := GetArrayLength(intArray);
      repeat
        Result := Result + IntToStr(intArray[i]);
        if (not (i = (arrayLength - 1))) then
          Result := Result + ' ';
        i := i + 1;
      until (i = arrayLength)
    end;

    function strToIntArray(intArray: string): array of Integer;
    var
      i, spacePos: Integer;
    begin
      repeat
        SetArrayLength(Result, i + 1);
        spacePos := Pos(' ', intArray);
        if (not (spacePos = 0)) then
        begin
          Result[i] := StrToInt(Copy(intArray, 1, spacePos - 1));
        end
        else
        begin
          Result[i] := StrToInt(Copy(intArray, 1, Length(intArray)));
          break;
        end;
        Delete(intArray, 1, spacePos);
        i := i + 1;
      until (False)
    end;

    begin
    setupsrl;
    t:=getsystemtime;
    MyList:=Create40PercentTPA;
    tmplist:=CreateItemBlackList(45,MyList);
    tmplist2:=CreateItemBlackList(46,MyList);
    //writeln(inttostr(getarraylength(tmplist2)));
    writeln(intarraytostr(tmplist2));
    if CompareIntArrays(tmplist,tmplist2) then writeln('yes')

    //if (tmplist=tmplist2) then writeln('yes');
    //writeln(inttostr(getsystemtime-t)+'ms');
    {
    if CheckItemBlackList(46,tmplist,mylist) then
    writeln('yes');
    writeln(inttostr(getsystemtime-t));
    }
    end.

    Run it on this



    It's like creating a DTM of the black outline, except it's faster because it looks at specific pixels with getcolor instead of searching everywhere with findcolor, and it's easier because it makes the 'sorta DTM' for you without even opening the DTM editor. I'll explain more in a tut later.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Question on getting pictures and comparing them.
    By Sandstorm in forum OSR Help
    Replies: 8
    Last Post: 12-12-2008, 08:29 PM
  2. Arrays, stuck on arrays
    By Camaro' in forum OSR Help
    Replies: 1
    Last Post: 03-08-2008, 02:02 AM
  3. Help with Arrays
    By kooldude in forum OSR Help
    Replies: 16
    Last Post: 06-15-2007, 05:36 AM

Posting Permissions

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