SRL Archive - Test corner

Radial Walking Array


boberman

2009-01-27 11:27:09

Well, I always feel that many walking functions are, frankly, pretty ugly looking. So I wrote this function which I believe should be pretty useful for someone.

function RWArray(colors : array of function : integer; startAngles, endAngles, dists, tols : array of integer) : boolean;
var
tpa : TPointArray;
i, j, Xmod, Ymod : integer;
begin
Result := False;
if not (LoggedIn) then
exit;

// ensure that the data is sane. These arrays should all be the same size.
if (high(startAngles) <> high(dists)) then
exit;

MakeCompass('n');
for i := 0 to High(dists) do
begin
Xmod := Random(4) - 2;
Ymod := Random(4) - 2;
// The code below was copied from RadialWalk by Nielsie95
if RadialWalkEx(tpa, MMCX, MMCY, colors[i](), tols[i], startAngles[i], endAngles[i], dists[i]) then
begin
for j to High(tpa) do
if MFNF(tpa[j].x, tpa[j].y, Xmod, Ymod) then
begin
FFlag(10);
Result := True;
Break;
end;
end else
break; // Radial Walk failed somewhere
end;
end;

How it should be called.
procedure WalkSomewhere;
startAngles, endAngles, distances, tolerances : array[0..5] of integer;
funcs : array[0..5] of function : integer;
begin
startAngles := [20, 30, 40, 50, 90, 38];
endAngles := [32, 40, 45, 55, 92, 40];
dists := [30, 50, 40, 60, 30, 25];
tolerances := [3, 5, 10, 8, 9, 6];
funcs := [@FindVarrockRoadColor, @FindRockColor, @FindStoneColor, @FindSandColor, SomeCustomColorFinder, SuperColorFinder];
if (RWArray(funcs, startAngles, endAngles, dists, tolerances)) then
begin
writeln('Win!');
end else
writeln('phail :(');
end;

*edit* I guess I should add some credit as well :)
*edit2* added a check for if a radial walk instance fails. Should help keep the walking sane.

Shuttleu

2009-01-27 11:30:45

why cant you use just a normal array of colors?
why does it have to use a array of function of integer?

~shut

EDIT: i mean so its like this

function RWArray(colors : array of integer; startAngles, endAngles, dists, tols : array of integer) : boolean;
var
tpa : TPointArray;
i, Xmod, Ymod : integer;
begin
Result := False;
if not (LoggedIn) then
exit;

// ensure that the data is sane. These arrays should all be the same size.
if (high(startAngles) <> high(dists)) then
exit;

MakeCompass('n');
for i := 0 to High(dists) do
begin
Xmod := Random(4) - 2;
Ymod := Random(4) - 2;
if RadialWalkEx(tpa, MMCX, MMCY, colors[i], tols[i], startAngles[i], endAngles[i], dists[i]) then
if MFNF(tpa[i].x, tpa[i].y, Xmod, Ymod) then
begin
FFlag(10);
Result := True;
Break;
end;
end;
end;

boberman

2009-01-27 11:36:15

From: Shuttleu
why cant you use just a normal array of colors?
why does it have to use a array of function of integer?

~shut

EDIT: i mean so its like this

function RWArray(colors : array of integer; startAngles, endAngles, dists, tols : array of integer) : boolean;
var
tpa : TPointArray;
i, Xmod, Ymod : integer;
begin
Result := False;
if not (LoggedIn) then
exit;

// ensure that the data is sane. These arrays should all be the same size.
if (high(startAngles) <> high(dists)) then
exit;

MakeCompass('n');
for i := 0 to High(dists) do
begin
Xmod := Random(4) - 2;
Ymod := Random(4) - 2;
if RadialWalkEx(tpa, MMCX, MMCY, colors[i], tols[i], startAngles[i], endAngles[i], dists[i]) then
if MFNF(tpa[i].x, tpa[i].y, Xmod, Ymod) then
begin
FFlag(10);
Result := True;
Break;
end;
end;
end;


Quite simply because if you are doing a long walk, colors could easily change on you. Since there is no way to update the array once it is started, a function call would take care of any changes for you.

Shuttleu

2009-01-27 12:08:00

ok so how would it take care of the changes?

~shut

boberman

2009-01-27 12:15:41

From: Shuttleu
ok so how would it take care of the changes?

~shut


The functions are passed in and called when the radial walking is used. Not before it is used.

Sir R. M8gic1an

2009-01-27 13:41:07

i love the idea, and definitely think that it should be further improved;

there's just one thing i'm not sure about;


for i := 0 to High(dists) do
begin
Xmod := Random(4) - 2;
Ymod := Random(4) - 2;
if RadialWalkEx(tpa, MMCX, MMCY, colors[i], tols[i], startAngles[i], endAngles[i], dists[i]) then
//for h:= 0 to High(tpa) do
if MFNF(tpa[i].x, tpa[i].y, Xmod, Ymod) then
begin
FFlag(10);
Result := True;
Break;
end;
end;

because the way you currently have it once it walks once it'll stop all the other walks (is that what you intended?), because the code is very similar to RadialWalk(in that part), but the way you currently have it might run into an Out Of Range error because you are using the i from "dists" instead of using the i according to High(tpa).

~RM

boberman

2009-01-27 14:09:09

From: Rasta Magician
i love the idea, and definitely think that it should be further improved;

there's just one thing i'm not sure about;


for i := 0 to High(dists) do
begin
Xmod := Random(4) - 2;
Ymod := Random(4) - 2;
if RadialWalkEx(tpa, MMCX, MMCY, colors[i], tols[i], startAngles[i], endAngles[i], dists[i]) then
//for h:= 0 to High(tpa) do
if MFNF(tpa[i].x, tpa[i].y, Xmod, Ymod) then
begin
FFlag(10);
Result := True;
Break;
end;
end;

because the way you currently have it once it walks once it'll stop all the other walks (is that what you intended?), because the code is very similar to RadialWalk(in that part), but the way you currently have it might run into an Out Of Range error because you are using the i from "dists" instead of using the i according to High(tpa).

~RM

Oh, Yikes, you're right that is far from what I intended. :). I figured there might be a bug present. Ok, added the couple of bug fixes. It should run pretty much perfectly now.

What do you guys think about adding a callback function to be called every time the script walks? That way, you can put in anti-ban, ect into the walking procedure if you like.

n3ss3s

2009-01-31 10:26:10

Doing a for loop from an int array is handier for debug and everything…

Wizzup?

2009-01-31 11:20:14

As far as I know calling 'FindXXColor' everytime is pretty much a waste of CPU, no?

boberman

2009-01-31 11:30:25

From: Wizzup?
As far as I know calling 'FindXXColor' everytime is pretty much a waste of CPU, no?


meh, not really, it shouldn't take too much extra time to perform, and guarantees correct colors. With a long walk, this could be very important.

Wizzup?

2009-01-31 15:47:49

From: boberman
meh, not really, it shouldn't take too much extra time to perform, and guarantees correct colors. With a long walk, this could be very important.


RadialRoadWalk also guarantees correct colors. :)
Perhaps do this:

(at start) oldcolor c;
(in loop)
if not findcolor(c) then
oldcolor := c
radial stuff
(endloop)

Nava2

2009-02-04 17:18:27

Good idea, but for future reference,

funcs : array[0..5] of function : integer;
begin
startAngles := [20, 30, 40, 50, 90, 38];
endAngles := [32, 40, 45, 55, 92, 40];
dists := [30, 50, 40, 60, 30, 25];
tolerances := [3, 5, 10, 8, 9, 6];
funcs := [@FindVarrockRoadColor, @FindRockColor, @FindStoneColor, @FindSandColor, SomeCustomColorFinder, SuperColorFinder];
if (RWArray(funcs, startAngles, endAngles, dists, tolerances)) then
begin
writeln('Win!');
end else
writeln('phail :(');
end;

Won't work, as you can't declare an array like: B : array [0..44] of Integer; then declare it in the script as:
B := [24, 52, 62, 34];
It will cause either runtime errors or compiling. It doesn't like that it has a preset length, then you are resetting the length with the [].

Anyways, I like the idea! :)

Its basically a pathwalker.

marpis

2009-03-20 21:33:35

Good idea, saving rows in long walks, but prevents use of failsafes like

If not RadialWalk(..) then
DDTMWalk;