SRL Archive - Research & Development Lounge

Tbox Color Array Comparing


Stuart

2011-12-20 16:23:29

I'm trying to come up with a good way of finding noted forms of items in the inventory for my lazy merchant bot.

I developed these functions to do that, Just thought I would share. Any improvements would be awesome.

Use:

writeln(IntToStr(compareColorArrays(GetColorsFromTBox(InvBox(1)), GetColorsFromTBox(InvBox(2)))));

Snippet:

function GetColorsFromTBox(loc : TBox): Array of Integer;
var
x, y, currentCol, emptySlot, color : Integer;
found : boolean;
colors : Array[1..100] of Integer;
begin
for x := loc.X1 to loc.X2 do
begin
for y := loc.Y1 to loc.Y2 do
begin
found := false;
color := GetColor(x, y);
for currentCol := 1 to 100 do
begin
if colors[currentCol] = color then
begin
found := true;
Break;
end;
if colors[currentCol] = 0 then
begin
emptySlot := currentCol;
writeln('Filled up slot' + IntToStr(emptySlot) + ' with: ' + IntToStr(color));
Break;
end;
end;
if not(found) then colors[emptySlot] := color;
end;
end;
Result := colors;
end;

function compareColorArrays(origColors, searchColors : Array of Integer): Integer;
var
i, i2, colorsFound : Integer;
begin
for i := Low(origColors) to High(origColors) do
begin
for i2 := Low(searchColors) to High(searchColors) do
begin
if origColors[i] = searchColors[i2] then
begin
colorsFound := colorsFound + 1;
Break;
end;
end;
end;
Result := colorsFound;
end;

Swatarianess

2011-12-30 08:20:47

From: Stuart
I'm trying to come up with a good way of finding noted forms of items in the inventory for my lazy merchant bot.

I developed these functions to do that, Just thought I would share. Any improvements would be awesome.

Use:

writeln(IntToStr(compareColorArrays(GetColorsFromTBox(InvBox(1)), GetColorsFromTBox(InvBox(2)))));

Snippet:

function GetColorsFromTBox(loc : TBox): Array of Integer;
var
x, y, currentCol, emptySlot, color : Integer;
found : boolean;
colors : Array[1..100] of Integer;
begin
for x := loc.X1 to loc.X2 do
begin
for y := loc.Y1 to loc.Y2 do
begin
found := false;
color := GetColor(x, y);
for currentCol := 1 to 100 do
begin
if colors[currentCol] = color then
begin
found := true;
Break;
end;
if colors[currentCol] = 0 then
begin
emptySlot := currentCol;
writeln('Filled up slot' + IntToStr(emptySlot) + ' with: ' + IntToStr(color));
Break;
end;
end;
if not(found) then colors[emptySlot] := color;
end;
end;
Result := colors;
end;

function compareColorArrays(origColors, searchColors : Array of Integer): Integer;
var
i, i2, colorsFound : Integer;
begin
for i := Low(origColors) to High(origColors) do
begin
for i2 := Low(searchColors) to High(searchColors) do
begin
if origColors[i] = searchColors[i2] then
begin
colorsFound := colorsFound + 1;
Break;
end;
end;
end;
Result := colorsFound;
end;


Muhahaha hewo Stuart its Inf3cti0us ;) looks good i dont think theres difference of Noted and not noted items? looks good to me imo maybe some1 may help and how is it going with the Merchanting bot?

Stuart

2012-01-01 21:00:35

Mormonman posted a more effective method on merch forums, I'm looking into just using DTM's until I perfect my methods.

There are differences with noted and non noted items, I'm looking into alternative ideas though :)

n3ss3s

2012-01-04 00:08:38

Use GetColors rather than multiple GetColor calls