Janilabo

Untitled

Aug 15th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.68 KB | None | 0 0
  1. procedure TPAUnique(var TPA: TPointArray);
  2. var
  3.   h, h2, i, i2, i3, d: Integer;
  4. begin
  5.   h := High(TPA);
  6.   if (h < 1) then
  7.     Exit;
  8.   for i := (h - d) downto 1 do
  9.     for i2 := (i - 1) downto 0 do
  10.       if ((TPA[i].X = TPA[i2].X) and (TPA[i].Y = TPA[i2].Y)) then
  11.       begin
  12.         h2 := High(TPA);
  13.         for i3 := i to (h2 - 1) do
  14.           TPA[i3] := TPA[(i3 + 1)];
  15.         SetLength(TPA, h2);
  16.         Inc(d);
  17.         Break;
  18.       end;
  19. end;
  20.  
  21. function FindColorsMulti(colors: TIntegerArray; xs, ys, xe, ye: Integer): TPointArray;
  22. var
  23.   l, i: Integer;
  24.   ATPA: T2DPointArray;
  25. begin
  26.   ClearSameIntegers(colors);
  27.   l := Length(colors);
  28.   if (l < 1) then
  29.     Exit;
  30.   SetLength(ATPA, l);
  31.   for i := 0 to (l - 1) do
  32.     if ((colors[i] >= 0) and (colors[i] <= 16777215)) then
  33.       FindColors(ATPA[i], colors[i], xs, ys, xe, ye);
  34.   Result := MergeATPA(ATPA);
  35.   SetLength(ATPA, 0);
  36.   TPAUnique(Result);
  37. end;
  38.  
  39. function RSCE_UpText: string;
  40. var
  41.   TPA: TPointArray;
  42.   ATPA: array of TPointArray;
  43. begin
  44.   TPA := FindColorsMulti([65535, 4231423, 16776960, 65280, 16777215], 3, 2, 311, 18);
  45.   ATPA := SplitTPAEx(TPA, 1, 12);
  46.   SortATPAFromFirstPoint(ATPA, Point(0, 0));
  47.   SetLength(TPA, 0);
  48.   try
  49.     Result := GetTextATPA(ATPA, 3, 'RSCMainFont');
  50.   except
  51.   end;
  52.   SetLength(ATPA, 0);
  53. end;
  54.  
  55. function MinEx(Arr: TIntegerArray): Integer;
  56. var
  57.   H, I: LongInt;
  58. begin
  59.   H := High(Arr);
  60.   Result := Arr[0];
  61.   for I := 1 to H do
  62.     Result := Min(Result, Arr[I]);
  63. end;
  64.  
  65. function LevenshteinDistance(s: string; t: string): Integer;
  66. var
  67.   m, n, i, j: integer;
  68.   d: T2DIntegerArray;
  69. begin
  70.   m := Length(s);
  71.   n := Length(t);
  72.   SetLength(d, (m + 1));
  73.   for i := 0 to m do
  74.   begin
  75.     SetLength(d[i], (n + 1));
  76.     d[i][0] := i;
  77.   end;
  78.   for j := 0 to n do
  79.     d[0][j] := j;
  80.   for j := 1 to n do
  81.     for i := 1 to m do
  82.       if (s[i] = t[j]) then
  83.         d[i][j] := d[(i - 1)][(j - 1)]
  84.       else
  85.         d[i][j] := MinEx([(d[(i - 1)][j] + 1), (d[i][(j - 1)] + 1), (d[(i - 1)][(j - 1)] + 1)]);
  86.   Result := d[m][n];
  87. end;
  88.  
  89. function Percent(position, source: Extended): Extended;
  90. begin
  91.   if (position = 0) then
  92.     Result := 0
  93.   else
  94.     Result := (100 * (position / source));
  95. end;
  96.  
  97. function IsUpText(str: string; accuracy_percent: Extended): Boolean;
  98. var
  99.   L: Integer;
  100.   similarity: Extended;
  101.   uptxt: string;
  102. begin
  103.   uptxt := RSCE_UpText;
  104.   L := Length(str);
  105.   Result := (Percent((L - LevenshteinDistance(str, uptxt)), L) > accuracy_percent);
  106. end;
  107.  
  108. begin
  109.   LoadFont('RSCMainFont', False);
  110.   ClearDebug;
  111.   ActivateClient;
  112.   Wait(2000);
  113.   if IsUpText('Well: Walk here / 1 more option', 85.0) then
  114.     WriteLn('SUCCESS!');
  115.   FreeFont('RSCMainFont');
  116. end.
Advertisement
Add Comment
Please, Sign In to add comment