zmon
2012-05-29 05:35:46
when you watch bots mining in mining guild, you can predict where they will go mine with rather high degree of accuracy because the coal is searched through spiral … so they end up going after the nearest
it's not that bad when there is one bot - it almost looks human-like but when there are 5 or 7 shadowing same moves, it's a dead giveaway
now if you have a list ordered from most preferable to least preferable, it would be nice if you could go through it in semi random fashion while still giving 50% or so chance to the first pick going first
there are many ways of doing it but this one is simple - call GetAccessor which will return integer array of indexes already random sorted for you
in following example i'm generating accessor for array 1..7 - give it a spin and see what i mean - you will notice that 1 ends up in first position often but sometimes (lot less likely) you will see 7 in first position of the accessor array
and of course you then just iterate through your array as such:
here is the code
it's not that bad when there is one bot - it almost looks human-like but when there are 5 or 7 shadowing same moves, it's a dead giveaway
now if you have a list ordered from most preferable to least preferable, it would be nice if you could go through it in semi random fashion while still giving 50% or so chance to the first pick going first
there are many ways of doing it but this one is simple - call GetAccessor which will return integer array of indexes already random sorted for you
in following example i'm generating accessor for array 1..7 - give it a spin and see what i mean - you will notice that 1 ends up in first position often but sometimes (lot less likely) you will see 7 in first position of the accessor array
and of course you then just iterate through your array as such:
for Index := 0 to Length(accessor) - 1 do
begin
myArray[accessor[Index]];
end;
here is the code
program RandomizedWeightedAccessor;
function GetAccessor(Low, High : Integer) : TIntegerArray;
var TargetLength : Integer;
var Index : Integer;
begin
TargetLength := High - Low + 1;
SetLength(Result, TargetLength);
for Index := 0 to Length(Result) - 1 do
begin
Result[Index] := Low + Index;
end;
// randomize with weight by double sweep
for Index := Length(Result) - 1 downto 1 do
begin
if (RandomE > 0.5) then continue;
// swap
swap(Result[Index], Result[Index - 1]);
end;
for Index := 1 to Length(Result) - 1 do
begin
if (RandomE > 0.5) then continue;
// swap
swap(Result[Index], Result[Index - 1]);
end;
end;
var i : Integer;
var ac : TIntegerArray;
begin
ac := GetAccessor (1, 7);
for i := 0 to Length(ac) - 1 do
begin
WriteLN('pos ' + IntToStr(i) + ' value ' + IntToStr(ac[i]));
end;
end.