PDA

View Full Version : Randomly moving around



Limzo
11-18-2006, 04:31 AM
Please can somebody make me a script where a combo randomly moves around the screen but does not go over unwalkable areas?

I would like to use this in my quest when I get round to it. *gets round to it*

Thanks, Limzo.

Revfan9
11-18-2006, 07:40 PM
WAIT WAITFRAME
COMPAREV CANMOVE,1
GOTOTRUE REVERSE
COMPAREV d0,0
GOTOTRUE TURNU
SUBV d0,1
COMPAREV d1,0
GOTOTRUE TURNR
SUBV d1,1
GOTO WAIT
REVERSE
COMPAREV xd,0
GOTOFALSE YMOV
MULTV xd,-1
YMOV COMPAREV yd,0
GOTOFALSE WAIT
MULTV xd,1
GOTO WAIT
TURNU SETV xd,0
SETV yd,1
SETR d0,d2
GOTO WAIT
TURNR SETV yd,0
SETV xd,1
SETR d1,d3
GOTO WAIT

Should work... Lemme know if it doesn't.

Limzo
11-21-2006, 04:16 PM
Sorry to be a noob, but I don't know how to use Scripts at all. I can only use FFCombo scripting, and not very well.
EDIT: Stupid me, this is FFCombo scripting. Forget that Pm revfan.
EDIT2: Okay, it doesn't work. It comes up with the message,
"Unable to parse instruction 2 from script random.txt
The error was: Parameter 1 invalid.
The command was (COMPAREV) (CANMOVE, 1)"

*tries to fix from past experiences*

bluedeath
11-22-2006, 04:57 PM
go to z-script and when you type the code, seems there is lot of caps in the code so make sure you capital them and when you do so compile it go to freeformcombos and select and edit a combo choose your tile and go to select script. i hope this helps

Revfan9
11-22-2006, 11:48 PM
CANMOVE doesn't work as a variable in Zasm... damn... Does anyone know the Zasm equivilant of CANMOVE?

Limzo
11-23-2006, 06:19 AM
Nonono, I went on Tools > Import FF script.

Let me guess, it's not that kind of script.

Saffith
11-23-2006, 07:08 AM
No, you had it right. It's ASM, so it's imported rather than compiled.


CANMOVE doesn't work as a variable in Zasm... damn... Does anyone know the Zasm equivilant of CANMOVE?I'm not sure precisely what you're trying to do with it; you're trying to test the solidity of a combo, I take it?
To do that, load the position of the combo you want to test into D0 and use COMBOSD. That'll give you a 4-bit number representing the solidity of the combo; you can check the solidity of each quarter separately using AND. 1 for the top-left, 2 for the bottom-left, 3 for the top-right, and 4 for the bottom-right. 1 is solid, 0 is walkable.

Limzo
11-23-2006, 07:34 AM
Sorry, I lost track after FFCombos and scripting became more advanced.

Please can you explain? I have no idea what those "D" boxes do.

Limzo
11-24-2006, 11:08 AM
Please guys, I need this for random battles.

DarkDragon
11-24-2006, 12:15 PM
Patience my friend, the AGN boards are slow these days and you sometimes need to give people a few days to respond to posts.

What kind of "random" movement to you want?
1. A random walk in two dimensions?
2. Two simultaneous random walks in one dimension?
3. Constant velocity in the cardinal directions, with the direction chosen randomly when an unwalkable tile is hit?
4. Constant velocity in any direction, with the direction chosen randomly when an unwalkable tile is hit?
5. As in 3 or 4, but with a fixed probability of spontaneously changing direction every few frames?
6. As in 5, but with the direction change biased towards the current player position (darknut movement)?
7. Something else entirely?

The power is yours.

Limzo
11-24-2006, 06:43 PM
Just, moving in any direction randomly at all. Like, it chooses a random number of frames (out of a set of intergers from 1 to 20 or something) and a random direction from North, North-North West, North West, West North West, West, North South West et cetera, and then changes direction when it hits the edge of a combo of ANY solidity.

Revfan9
11-24-2006, 06:48 PM
That's what my script did, except I need the Zasm equivilent of CANMOVE. Aside from that, it should work fine (it changes a random direction every so often, and starts going the other way when it hits a solid object).

Limzo
11-25-2006, 04:20 AM
Also, BTW, I need it to not go off the screen.

DarkDragon
11-27-2006, 11:31 AM
OK, here are a bunch of skeleton movement scripts I cooked up on the way here on the metro; note that these are UNTESTED and incomplete, but these algorithms are hopefully enough to get you started. A couple of points:
1. For each of these you need to write and include a function canMove(), which can be more or less complicated depending on the fidelity of walkability detection you want to use. For no detection, make the function always return true.
2. In these scripts, if trying to move in a random direction fails, a new random direction is chosen, until movement succeeds. Note that this is approximative and not particularly clever; I couldn't think of a simple way to generate permutations without more advanced data structures or excessive pain. As a consequence, when choosing a new direction, I've put in code to prevent the script from hanging if the FFC is completely stuck; set NUMTRIES as desired. Higher values require more CPU time, but increase the probability of a legal direction being chosen, if one exists. Lower values take less time but increase the probability of the FFC doing nothing for several frames when it hits an unwalkable boundary.

Since this computer has a tendency to crash unexpectedly, I'll be entering these one at a time; please patientez.

1. A random walk in 2 dimensions. Very erratic movement. speed is the number of pixels the FFC is to move each frame.


ffc script rwalk2d {
void run(int speed) {
int x=this->X;
int y=this->Y;
int safety=NUMTRIES;
while(true) {
if(safety == 0) {
safety = NUMTRIES;
WaitFrame();
}
int deg=Rand(360);
int newx=x+speed*Sin(deg);
int newy=y+speed*Cos(deg);
if(canMove(newx,newy)) {
x=newx;
this->X=x;
y=newy;
this->Y=y;
safety=NUMTRIES;
WaitFrame();
}
else safety--;
}
}
}


2. Two simultaneous random walks in 1 dimension. Very erratic movement. Speed is the number of pixels per frame the FFC moves in each direction.



ffc script rwalk2x1d {
void run(int speed) {
int x=this->X;
int y=this->Y;
int safety=NUMTRIES;
while(true) {
if(safety == 0) {
safety = NUMTRIES;
WaitFrame();
}
int dx=2*Rand(2)-1;
int dy=2*Rand(2)-1;
int newx=x+speed*dx;
int newy=y+speed*dy;
if(canMove(newx,newy)) {
x=newx;
this->X=x;
y=newy;
this->Y=y;
safety=NUMTRIES;
WaitFrame();
}
else safety--;
}
}
}


3. The FFC continues in a straight line along a cardinal direction until it hits a wall, at which time it chooses a new direction. Speed is the number of pixels to move per frame.



ffc script wall2wallrect {
void run(int speed) {
int x=this->X;
int y=this->Y;
int safety=NUMTRIES;
int dir=Rand(4);
while(true) {
if(safety == 0) {
safety = NUMTRIES;
WaitFrame();
}
int newx=x;
int newy=y;
if(dir==0) newx+=speed;
if(dir==1) newx-=speed;
if(dir==2) newy+=speed;
if(dir==3) newy-=speed;
if(canMove(newx,newy)) {
x=newx;
this->X=x;
y=newy;
this->Y=y;
safety=NUMTRIES;
WaitFrame();
}
else {
dir=Rand(4);
safety--;
}
}
}
}


4. The FFC starts moving in a cardinal direction, and every few frames, there is a chance the FFC will choose a new random direction. Speed is the number of pixels the FFC moves per frame, interval is the number of frames that pass before the FFC has a chance to change direction, and prob is the percent chance, from 0 to 100, of the FFC changing direction at that time.



ffc script randrect {
void run(int speed, int interval, int prob) {
int x=this->X;
int y=this->Y;
int safety=NUMTRIES;
int dir=Rand(4);
int counter=0;
while(true) {
if(safety == 0) {
safety = NUMTRIES;
WaitFrame();
}
int newx=x;
int newy=y;
if(counter==0) {
int p = Rand(100);
if(p<prob) dir=Rand(4);
}
if(dir==0) newx+=speed;
if(dir==1) newx-=speed;
if(dir==2) newy+=speed;
if(dir==3) newy-=speed;
if(canMove(newx,newy)) {
x=newx;
this->X=x;
y=newy;
this->Y=y;
safety=NUMTRIES;
counter=(counter+1)%interval;
WaitFrame();
}
else {
dir=Rand(4);
safety--;
}
}
}
}


5. The FFC bounces around the screen; when it hits the wall, it chooses a new random angle. Speed is the number of pixels the FFC moves per frame.



ffc script wall2wall2d {
void run(int speed) {
int x=this->X;
int y=this->Y;
int safety=NUMTRIES;
int ang=Rand(360);
while(true) {
if(safety == 0) {
safety = NUMTRIES;
WaitFrame();
}
int newx=x+speed*Sin(ang);
int newy=y+speed*Cos(ang);
if(canMove(newx,newy)) {
x=newx;
this->X=x;
y=newy;
this->Y=y;
safety=NUMTRIES;
WaitFrame();
}
else {
ang=Rand(360);
safety--;
}
}
}
}


6. As script 4, but the FFC is not restricted to the cardinal directions.



ffc script rand2d {
void run(int speed, int interval, int prob) {
int x=this->X;
int y=this->Y;
int safety=NUMTRIES;
int ang=Rand(360);
int counter=0;
while(true) {
if(safety == 0) {
safety = NUMTRIES;
WaitFrame();
}
if(counter==0) {
int p = Rand(100);
if(p<prob) dir=Rand(360);
}
int newx=x+speed*Sin(ang);
int newy=y+speed*Cos(ang);
if(canMove(newx,newy)) {
x=newx;
this->X=x;
y=newy;
this->Y=y;
safety=NUMTRIES;
counter=(counter+1)%interval;
WaitFrame();
}
else {
ang=Rand(360);
safety--;
}
}
}
}


7. The FFC constantly accelerates towards link, until it hits a solid obstacle. This FFC should be fairly easy to dodge from far away. Initv is the initial velocity of the FFC, acc is the magnitude of the FFC's acceleration each frame.


ffc script seekacc {
void run(int initv, int acc) {
int dx = Link->X-this->X;
int dy = Link->Y-this->Y;
int scale = initv/Sqrt(dx*dx+dy*dy);
this->Vx = dx*scale;
this->Vy = dy*scale;
while(true) {
if(!canMove(this->X, this->Y)) {
this->Vx=0;
this->Vy=0;
this->Ax=0;
this->Ay=0;
Quit();
}
dx = Link->X-this->X;
dy = Link->Y-this->Y;
scale = acc/Sqrt(dx*dx+dy*dy);
this->Ax = dx*scale;
this->Ay = dy*scale;
WaitFrame();
}
}
}


8. This FFC homes in on Link while keeping constant velocity; this script is HIGHLY UNTESTED as the geometrical derivation was somewhat complicated. Initv is again the initial velocity, in pixels per frame, and maxacc is the FFC's maximum turning acceleration. The higher this acceleration, the better the homing.



ffc script seekconst {
void run(int initv, int maxacc) {
int dx = Link->X-this->X;
int dy = Link->Y-this->Y;
int scale = initv/Sqrt(dx*dx+dy*dy);
this->Vx = dx*scale;
this->Vy = dy*scale;
while(true) {
if(!canMove(this->X, this->Y)) {
this->Vx=0;
this->Vy=0;
this->Ax=0;
this->Ay=0;
Quit();
}
dx = Link->X-this->X;
dy = Link->Y-this->Y;
int distsqr = dx*dx+dy*dy;
int speed = Sqrt(this->Vx*this->Vx+this->Vy*this->Vy);
int acc = 2*speed*(this->Vx*dy-this->Vy*dx)/distsqr;
if(Abs(acc) > maxacc) {
if(acc>0) acc=maxacc;
else acc = -maxacc;
}
this->Ax = -this->Vy*acc/speed;
this->Ay = this->Vx*acc/speed;
WaitFrame();
}
}
}


Feel free to post enhancements or bug fixes to these scripts, or movement scripts of your own.

Limzo
11-27-2006, 01:22 PM
I tried number 1 and it said it could not parse instruction one.

DarkDragon
11-28-2006, 10:58 AM
Are you sure you're compiling it correctly? Save it to a text file and then import it from the main ZScript dialog.

Also, it won't work without a canMove implementation. I'll write one for you but I'll need some time to sit down and work out how to do so correctly; maybe someone else will be able to help you sooner.

Limzo
02-04-2007, 07:01 AM
People, I don't know if this is gravedigging or not, but please can someone help?