SRL Archive - Test corner

ChopATree(WhichTree: string): boolean;


skilld u

2008-03-25 20:42:33

function ChopATree(WhichTree: string): boolean;
var
TreeColors : array [0..3] of integer;
TreeTPA: TPointArray;
I: Integer;
begin
case lowercase(WhichTree) of
'yew': begin
TreeColors[0] := 2571321;
TreeColors[1] := 3691098;
TreeColors[2] := 2132598;
TreeColors[3] := 2262386;
for i := 0 to 3 do
FindColorsSpiralTolerance(X, Y, TreeTPA, TreeColors[i], MSX1, MSY1, MSX2, MSY2, 50);
for I := 0 to 0 do
begin
MMouse(TreeTPA[i].x, TreeTPA[i].y, 3, 3);
Wait(100);
if IsUpText('hop') then
begin
GetMousePos(x, y);
case Random(1) of
0: Mouse(x, y, 5, 5, true);
1: begin
Mouse(x, y, 5, 5, false);
Wait(100 + random(100));
ChooseOption('hop');
end;
end;
Result := True;
end;
end
end;

'oak': begin
TreeColors[0] := 2571321;
TreeColors[1] := 3691098;
TreeColors[2] := 2132598;
TreeColors[3] := 2262386;
for i := 0 to 3 do
FindColorsSpiralTolerance(X, Y, TreeTPA, TreeColors[i], MSX1, MSY1, MSX2, MSY2, 50);
for I := 0 to 0 do
begin
MMouse(TreeTPA[i].x, TreeTPA[i].y, 3, 3);
Wait(100);
if IsUpText('hop') then
begin
GetMousePos(x, y);
case Random(1) of
0: Mouse(x, y, 5, 5, true);
1: begin
Mouse(x, y, 5, 5, false);
Wait(100 + random(100));
ChooseOption('hop');
end;
end;
Result := True;
end;
end
end;

'normal': begin
TreeColors[0] := 2571321;
TreeColors[1] := 3691098;
TreeColors[2] := 2132598;
TreeColors[3] := 2262386;
for i := 0 to 3 do
FindColorsSpiralTolerance(X, Y, TreeTPA, TreeColors[i], MSX1, MSY1, MSX2, MSY2, 50);
for I := 0 to 0 do
begin
MMouse(TreeTPA[i].x, TreeTPA[i].y, 3, 3);
Wait(100);
if IsUpText('hop') then
begin
GetMousePos(x, y);
case Random(1) of
0: Mouse(x, y, 5, 5, true);
1: begin
Mouse(x, y, 5, 5, false);
Wait(100 + random(100));
ChooseOption('hop');
end;
end;
Result := True;
end;
end
end;

'willow': begin //colors done
TreeColors[0] := 2571321;
TreeColors[1] := 3691098;
TreeColors[2] := 2132598;
TreeColors[3] := 2262386;
for i := 0 to 3 do
FindColorsSpiralTolerance(X, Y, TreeTPA, TreeColors[i], MSX1, MSY1, MSX2, MSY2, 50);
for I := 0 to 0 do
begin
MMouse(TreeTPA[i].x, TreeTPA[i].y, 3, 3);
Wait(100);
if IsUpText('hop') then
begin
GetMousePos(x, y);
case Random(1) of
0: Mouse(x, y, 5, 5, true);
1: begin
Mouse(x, y, 5, 5, false);
Wait(100 + random(100));
ChooseOption('hop');
end;
end;
Result := True;
end;
end
end;
end;
end;

ex.
ChopATree('yew');

only the willow colors are right.

Cazax

2008-03-25 20:50:49

Why dont you use TPAtoATPA, SplitTPA,MiddleTPAEx, etc…?

skilld u

2008-03-25 20:51:22

dont know how. want to explain?

P1nky

2008-03-25 21:48:29

good job its nice

skilld u

2008-03-25 21:57:06

thanks

Bobarkinator

2008-03-25 23:06:12

function ChopATree(WhichTree: string): boolean;
var
TreeColors : array [0..3] of integer;
TreeTPA: TPointArray;
I: Integer;
begin
case lowercase(WhichTree) of
'yew':
TreeColors[0] := 2571321;
TreeColors[1] := 3691098;
TreeColors[2] := 2132598;
TreeColors[3] := 2262386;
'oak':
TreeColors[0] := 2571321;
TreeColors[1] := 3691098;
TreeColors[2] := 2132598;
TreeColors[3] := 2262386;
'normal':
TreeColors[0] := 2571321;
TreeColors[1] := 3691098;
TreeColors[2] := 2132598;
TreeColors[3] := 2262386;
'willow':
TreeColors[0] := 2571321;
TreeColors[1] := 3691098;
TreeColors[2] := 2132598;
TreeColors[3] := 2262386;
end;
for i := 0 to 3 do
FindColorsSpiralTolerance(X, Y, TreeTPA, TreeColors[i], MSX1, MSY1, MSX2, MSY2, 50);
for I := 0 to 0 do
begin
MMouse(TreeTPA[i].x, TreeTPA[i].y, 3, 3);
Wait(100);
if IsUpText('hop') then
begin
GetMousePos(x, y);
case Random(1) of
0: Mouse(x, y, 5, 5, true);
1: begin
Mouse(x, y, 5, 5, false);
Wait(100 + random(100));
ChooseOption('hop');
end;
end;
Result := True;
end;
end;
end;

Shortened. Also, you need to use CombineTPA when you search for multiple colors, what you are doing now is just finding each color but overwriting the array before so it's only really going off the last color.

skilld u

2008-03-25 23:12:14

thanks, but could you show me how to use combine tpa?

Negaal

2008-03-26 07:16:11

From: Cazax
TPAtoATPA, SplitTPA


He uses FindColorsSpiralTolerance. yeah making tpa to groups would be better:) but still, nice job.

Also combinetpa is like this

it puts old1 and old2 together to newtpa

Newtpa:=CombineTPA(old1,old2);

skilld u

2008-03-26 07:29:26

still kinda confusing :confused: can you post it in a script so its easier for me to understand?

n3ss3s

2008-03-26 09:58:58

So nobody is even going to bother trying reading mine, negaal, or Ray's tut on TPAs?

ShowerThoughts

2008-03-26 10:38:47

Link me N3ss3s because i can't find the search button :p

P1nky

2008-03-26 13:10:44

goodness take your avatar OUT! btw theres tuts for that

Sir R. M8gic1an

2008-03-26 15:58:54


for i := 0 to 3 do
FindColorsSpiralTolerance(X, Y, TreeTPA, TreeColors[i], MSX1, MSY1, MSX2, MSY2, 50);
for I := 0 to 0 do // may i point 0 to 0 out?
begin
MMouse(TreeTPA[i].x, TreeTPA[i].y, 3, 3);
Wait(100);
if IsUpText('hop') then
begin
GetMousePos(x, y);
case Random(1) of
0: Mouse(x, y, 5, 5, true);
1: begin
Mouse(x, y, 5, 5, false);
Wait(100 + random(100));
ChooseOption('hop');
end;
end;
Result := True;
end;

it'll only check one point of each color. 0 to 0 will run the loop once only.
but otherwise it is a good idea. you might like to look into FindTPAMulti in Object.scar

~RM

EvilChicken!

2008-03-26 23:20:45

From: Rasta Magician
You might like to look into FindTPAMulti in Object.scar

~RM



*shifty eyes looks from side to side*
..
There is no FindTPAMulti there.. Post the funtion you got please?
You meant
function FindObjTPA(var x, y: integer; color, tol, cts, ObjWidth, ObjHeight, minCount :Integer; UpText: tstringarray): Boolean;
?

If not, be kind and post the function.

Nava2

2008-08-20 10:31:25

EDIT: SORRY FOR GRAVEDIG DIDNT REALISE! Guess I fixed it anyways though…

function ChopATree(WhichTree: string) : boolean;

var
TreeColors : array [0..3] of integer;
TreeTPA, TreeTPAComb : TPointArray;
TreeATPA : T2DPointArray;
P : TPoint;
S : String;
I, H, CTS, x, y : Integer;

begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
case lowercase(WhichTree) of
'yew': TreeColors := [2571321, 3691098, 2132598, 2262386];
'oak': TreeColors := [2571321, 3691098, 2132598, 2262386];
'normal': TreeColors := [2571321, 3691098, 2132598, 2262386];
'willow': TreeColors := [2571321, 3691098, 2132598, 2262386];
else
begin
Writeln('Invalid tree type ' + Which + '. Exiting.');
Exit;
end;
end;
Delete(S, 1, 1);
for I := 0 to 3 do
if FindColorsSpiralTolerance(X, Y, TreeTPA, TreeColors[i], MSX1, MSY1, MSX2, MSY2, 15) then
TreeTPAComb := CombineTPA(TreeTPA, TreeTPAComb);
TreeATPA := SplitTPAEx(TreeTPAComb, 20, 20);
H := High(TreeATPA);
for I := 0 to H do
begin
P := MiddleTPA(TreeATPA[I]);
MMouse(P.x, P.y, 5, 5);
Wait(100);
if IsUpText(LowerCase(S)) then
begin
GetMousePos(x, y);
case Random(2) of
0: Mouse(x, y, 5, 5, true);
1: begin
Mouse(x, y, 5, 5, false);
Wait(100 + random(100));
ChooseOption('hop');
end;
end;
Result := True;
Break;
end;
end;
ColorToleranceSpeed(CTS);
end;

Untested, should work though. Shortened then made longer by fixing it. Strange eh?

HyperSecret

2008-08-20 13:41:51

did you try compiling your new one?

FindColorsSpiralTolerance is a procedure, not a boolean function, so it won't work in an if…then statement…

also String S never gets set to anything, so how does it know what uptext it looks for?

Nava2

2008-08-20 14:37:11

From: HyperSecret
did you try compiling your new one?

FindColorsSpiralTolerance is a procedure, not a boolean function, so it won't work in an if…then statement…

also String S never gets set to anything, so how does it know what uptext it looks for?


Fixed.

function ChopATree(WhichTree: string) : boolean;

var
TreeColors : array [0..3] of integer;
TreeTPA, TreeTPAComb : TPointArray;
TreeATPA : T2DPointArray;
P : TPoint;
S : String;
I, H, CTS, x, y : Integer;

begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
case lowercase(WhichTree) of
'yew': TreeColors := [2571321, 3691098, 2132598, 2262386];
'oak': TreeColors := [2571321, 3691098, 2132598, 2262386];
'normal': TreeColors := [2571321, 3691098, 2132598, 2262386];
'willow': TreeColors := [2571321, 3691098, 2132598, 2262386];
else
begin
Writeln('Invalid tree type ' + Which + '. Exiting.');
Exit;
end;
end;
S := WhichTree;
Delete(S, 1, 1);
for I := 0 to 3 do
if FindColorsSpiralTolerance(X, Y, TreeTPA, TreeColors[i], MSX1, MSY1, MSX2, MSY2, 15) then
TreeTPAComb := CombineTPA(TreeTPA, TreeTPAComb);
TreeATPA := SplitTPAEx(TreeTPAComb, 20, 20);
H := High(TreeATPA);
for I := 0 to H do
begin
P := MiddleTPA(TreeATPA[I]);
MMouse(P.x, P.y, 5, 5);
Wait(100);
if IsUpText(LowerCase(S)) then
begin
GetMousePos(x, y);
case Random(2) of
0: Mouse(x, y, 5, 5, true);
1: begin
Mouse(x, y, 5, 5, false);
Wait(100 + random(100));
ChooseOption('hop');
end;
end;
Result := True;
Break;
end;
end;
ColorToleranceSpeed(CTS);
end;

Nah I didn't, I will fix it one sec. Also, FindColors is actually a function. Scar glitch. Test it if you don't believe me.

markuska815

2008-08-20 14:42:48

Here's the function I use that is very similiar. It works amazing w/ maples.
The tree color and uptext are already set in another part of code cause this is from my script but im too lazy to add it into the function right now. But it also checks the uptext color to make sure its not an ent.

function LocateTree:Boolean;

var
i, TreeNum : Integer;
ColorTPA, TreeMidPoints : TPointArray;
ColorTPAs : array [0..2] of TPointArray;
TreeTPAs : T2DPointArray;

begin
Status('Finding Colors');
//Find All Tree Colors
FindColorsSpiralTolerance(MSCX, MSCY,ColorTPAs[0], Tree[CurrentTree].Color[0],
MSX1, MSY1, MSX2, MSY2, 7);
FindColorsSpiralTolerance(MSCX, MSCY,ColorTPAs[1], Tree[CurrentTree].Color[1],
MSX1, MSY1, MSX2, MSY2, 7);
FindColorsSpiralTolerance(MSCX, MSCY,ColorTPAs[2], Tree[CurrentTree].Color[2],
MSX1, MSY1, MSX2, MSY2, 7);
//Combine the tree color TPAs
ColorTPA := CombineTPA(ColorTPAs[0],CombineTPA(ColorTPAs[1],ColorTPAs[2]));
SortTPAFrom(ColorTPA, InttoPoint(MSCX, MSCY));
//Split the TPAs by distance
TreeTPAs := SplitTPA(ColorTPA, 15);
TreeNum := High(TreeTPAs) + 1;
SetArrayLength(TreeMidPoints, TreeNum);
//Get the midpoints
for i := 0 to TreeNum - 1 do
TreeMidPoints[i] := MiddleTPA(TreeTPAs[i]);
//Sort by distance
SortTPAFrom(TreeMidPoints, InttoPoint(MSCX, MSCY));
if (High(TreeMidPoints) < 0) then
begin
result := false;
Exit;
end else
begin
TreePt := TreeMidPoints[0];
MMouse(TreePt.x,TreePt.y,2,2);
if (IsUpText(Tree[CurrentTree].TreeText)) then
begin
if (FindColorTolerance(x, y, 55769, 85, 15, 115, 15, 15)) then //Auto-Checks if the closest tree is an ent
if (High(TreeMidPoints) > 0) then //If it is it goes to the second closest tree
begin //if there is more than one tree of course
TreePt := TreeMidPoints[1];
end else
begin
Result := false;
Exit;
end;
end else
begin
for i := 1 to TreeNum - 1 do
begin
MMouse(TreeMidPoints[i].x, TreeMidPoints[i].y, 3, 3);
if (IsUpText(Tree[CurrentTree].TreeText)) then
begin
if (FindColorTolerance(x, y, 55769, 85, 15, 115, 15, 15)) then
begin
//Inc(i);
Continue;
end;
TreePt := TreeMidPoints[i];
Break;
end;
if (i = TreeNum - 1) then
begin
Result := false;
Exit;
end;
end;
end;
Result := true;
end;
end;

P1nky

2008-08-30 12:13:41

nava do you mind if i use this for my powerchopper?
ill forsure credit you :P

and @markus post the other part :)

markuska815

2008-08-30 22:23:16

There's no other part… i just meant that the Tree[0].Color[0] and the TreeText are specific to my script so its not going to work by itself but it's pretty easy to modify