Log in

View Full Version : Need help with script (Newbie)



Saltyspoons
06-06-2012, 08:45 AM
EDIT: Wrong section, sorry! Move if you must


Ok, so I am beginning to work on a script for the game some are familiar with (Puzzle Pirates) and I am having trouble thinking of what to write for a part in my script.

First off

Here is a "good board":
http://img822.imageshack.us/img822/456/examplekf.png

I have defined a "good board" as a board with the red region to be empty of the crates that are randomly generated on the board. (Showed in blue)

What I want to do is find out how I can make my bot do my procedure until there is a good board displayed.


procedure CheckBoard;
var x, y: integer;
begin
PlainCrate := DTMFromString('mQwAAAHicY2ZgYBBlZGDQA2J1IH4KxP+B+B MQL2pKYghys2RY2BDLgAwYkTAQAAAitwci');
RockCrate := DTMFromString('mLgAAAHicY2JgYNgNxVxMDAwSQKwiL8qwZF oHAwwwQjEDAwBtVwO7');
RedCrate := DTMFromString('mLgAAAHicY2JgYHgNxPeAmJuRgUGaEcKezQ hkQAEjFDMwAABxAQNx');



if FindDTM(PlainCrate, x, y, 19, 441, 443, 487) = true then
begin
Abandon; // a previously defined procedure that exits the board
FindCannon; // procedure that opens new puzzle board
end;

if FindDTM(RedCrate, x, y, 19, 441, 443, 487) = true then
begin
Abandon;
FindCannon;
end;

if FindDTM(RockCrate, x, y, 19, 441, 443, 487) = true then
begin
Abandon;
FindCannon;
end;


FreeDTM(PlainCrate);
FreeDTM(RockCrate);
FreeDTM(RedCrate);
end;


The DTM's in my script are the 3 randomly generated crates, one being the crate full of rocks, one being the box with berries, etc.

So, my bot will open a board, and check the board if it has any crates in the red region. If there are any crates in the region, it will abandon the puzzle board and re open it. It stops after the second try. Sometimes it takes about 4-5 tries to get a good board, so i need to find out how to make my procedure continue abandoning multiple times until it has a good board.

If you understood this load of crap i just wrote, any help is appreciated. thanks

zluo
06-06-2012, 09:17 AM
procedure CheckBoard;
var x, y: integer;
begin
PlainCrate := DTMFromString('mQwAAAHicY2ZgYBBlZGDQA2J1IH4KxP+B+B MQL2pKYghys2RY2BDLgAwYkTAQAAAitwci');
RockCrate := DTMFromString('mLgAAAHicY2JgYNgNxVxMDAwSQKwiL8qwZF oHAwwwQjEDAwBtVwO7');
RedCrate := DTMFromString('mLgAAAHicY2JgYHgNxPeAmJuRgUGaEcKezQ hkQAEjFDMwAABxAQNx');

if (goodboard)then
begin
exit; //this will exit out of the procedure onto the next procedure on the mainloop. feel free to change to whatever
end;
repeat
if FindDTM(PlainCrate, x, y, 19, 441, 443, 487) then
begin
Abandon; // a previously defined procedure that exits the board
FindCannon; // procedure that opens new puzzle board
end;

if FindDTM(RedCrate, x, y, 19, 441, 443, 487) then
begin
Abandon;
FindCannon;
end;

if FindDTM(RockCrate, x, y, 19, 441, 443, 487) then
begin
Abandon;
FindCannon;
end;

until (goodboard)


FreeDTM(PlainCrate);
FreeDTM(RockCrate);
FreeDTM(RedCrate);
end;

this maybe? not to sure though

edit:actually i think my example wont work. ill wait till tomorrow

Saltyspoons
06-06-2012, 09:24 AM
this maybe? not to sure though

edit:actually i think my example wont work. ill wait till tomorrow

This is good help.

I don't know how to define what a "good board" is to simba. Would I declare a Boolean variable named goodboard, and make it "if there aren't any DTM's in the region, then goodboard = true"? I wouldn't know how to write that either. I think I am confusing myself, so I will stop writing but thanks and let me know if you think of something tomorrow.

Rich
06-06-2012, 09:44 AM
function GoodBoard : Boolean;
begin
Result:= not FindColor(X, Y, CrateColour, X1, Y1, X2, Y2);
end;That would do the same job?

zluo
06-06-2012, 09:45 AM
actually come to think of it, it can be very simple. you dont actually need those box dtms, just make a dtm of the entire good board(make sure you put dtm marks where the boxes are usually are so it can be spotted) and if (goodboard) = false then abandon.
if(goodboard)=true then carry on

Saltyspoons
06-06-2012, 10:21 AM
Based on all your guys' input, my problem is 100% solved!

Here is the final code (Credit to zluo and Rich):

procedure CheckBoard;
var x, y, GoodBoard: Integer;
begin
GoodBoard := DTMFromString('maQEAAHicE2RgYFjMyMDQDMRJQOwExIpAzA vE34Fyj4H4HBDvAOJFQNwDxGVAnAzEvkBsDsRKQHwdqP4GFN8E 4ltAfBuKb0BpZPE7UPoeEN+Fii+s8mFYWOLDsLjSl2FhuQ/DsroQhnklHgzLqgMYFlb6AcV8IWyg3JIyN4bFFb5gsaW1wQwrG yMYmhLtGKgBGKmAMQAAezcuew==');
If FindDTM(GoodBoard, x, y, 19, 441, 443, 487) = false then
repeat
begin
Abandon;
FindCannon;
end;
until FindDTM(GoodBoard, x, y, 19, 441, 443, 487) = true;
end;


Edit: Spelling

Rich
06-06-2012, 10:40 AM
Based on all your guys' input, my problem is 100% solved!

Here is the final code (Credit to zluo and Rich):

procedure CheckBoard;
var x, y, GoodBoard: Integer;
begin
GoodBoard := DTMFromString('maQEAAHicE2RgYFjMyMDQDMRJQOwExIpAzA vE34Fyj4H4HBDvAOJFQNwDxGVAnAzEvkBsDsRKQHwdqP4GFN8E 4ltAfBuKb0BpZPE7UPoeEN+Fii+s8mFYWOLDsLjSl2FhuQ/DsroQhnklHgzLqgMYFlb6AcV8IWyg3JIyN4bFFb5gsaW1wQwrG yMYmhLtGKgBGKmAMQAAezcuew==');
If FindDTM(GoodBoard, x, y, 19, 441, 443, 487) = false then
repeat
begin
Abandon;
FindCannon;
end;
until FindDTM(GoodBoard, x, y, 19, 441, 443, 487) = true;
end;


Edit: Spellingprocedure CheckBoard;
var
X, Y, GoodBoard : Integer;

begin
GoodBoard:= DTMFromString('maQEAAHicE2RgYFjMyMDQDMRJQOwExIpAzA vE34Fyj4H4HBD' +
'vAOJFQNwDxGVAnAzEvkBsDsRKQHwdqP4GFN8E4ltAfBuKb0Bp ZPE7UPoeEN+Fi' +
'is8mFYWOLDsLjSl2FhuQ/DsroQhnklHgzLqgMYFlb6AcV8IWyg3JIyN4bFFb5g' +
'saW1wQwrGyMYmhLtGKgBGKmAMQAAezcuew==');
if not FindDTM(GoodBoard, X, Y, 19, 441, 443, 487) then
repeat
Abandon;
FindCannon;
until FindDTM(GoodBoard, X, Y, 19, 441, 443, 487);
end; Couldn't help myself :p

Saltyspoons
06-06-2012, 10:43 AM
Couldn't help myself :p

hahahaha. I had just done the standards on my client, but not on my post. I forgot how much Simba hates ugly code. But actually, I never thought about using '+' signs for those long DTM's. Don't feel bad because you really taught me something here!!

Rich
06-06-2012, 10:51 AM
Haha no problem, glad I could help out then.
One thing I just remembered is that you might need to put + signs at the start of the lines as well, like this + 'vAOJFQNwDxGVAnAzEvkBsDsRKQHwdqP4GFN8E4ltAfBuKb0Bp ZPE7UPoeEN+Fi' +
+ 'is8mFYWOLDsLjSl2FhuQ/DsroQhnklHgzLqgMYFlb6AcV8IWyg3JIyN4bFFb5g' +
+ 'saW1wQwrGyMYmhLtGKgBGKmAMQAAezcuew==');I can't be too sure though, but if one way gives you an error, try to other way :)