What I'm trying to do is creating rows of AIs. There are 10 rows and each row has 10 AIs. Out of the 100 AIs created 20 of them are Zombies, and the rest are Warriors. I've done this part, but the zombies are usually all closed together in one spot. How would I make it so the 20 zombies are scattered in the 10 rows of AI?
Like so:
o x x x x o x x x o
x x x o x x x x x x
x x x x x x x o x x
x o x x x x x x x o
x x x x o x x o x x
x o x x x x x x x o
x o x x x x x x x x
x x x x x o x x o x
x x o x x x x x x x
o x x x o x x o x o
o - Zombie
x - Warrior
Also when they are scattered I don't want them to be at the same spot all the time. I think the best way to do this is randomizing between (0-3) zombies to add to each row. I kind of achieved what I wanted when I let all the warriors be created, and then changed specific ones to zombies. But I found it too slow. So basically I'm looking for a way to scattering the zombies from into 10 rows, and it should be random, and it shouldn't have any type of delay or long delay time.
ID:162409
Jan 12 2008, 5:29 am
|
|
In response to Kaiochao2536
|
|
I already know how to use those procs. Like I said, I already know how to generate the 20 zombies randomly, but the thing is they are usually close together and not spread out in the 10 rows. I figure that using prob() can make it more spread out, but I wouldn't end up with 20 zombies.
The only thing that I can come up with is when the monsters are created, they are assigned a value for a variable. Then I would use rand() to check if the value of that variable is between certain numbers. But I'm sure it's not efficient at all. If you can provide a small working and efficient way to do this that I can build upon, that would really help. |
In response to Bobmcapple
|
|
How about you make a variable? For every monster, add 1. When a monster is created, nullify it. If it is 10(ten monsters in a row), make a warrior.
Of course, you'll be making warriors between 1 and 10. |
The problem is you really don't want randomness; a true random distribution would have some clustering. The easiest method is probably to go with something weighted that adjusts each time you put a new zombie in. The algorithm would be something like this:
var/list/weights = new --X if(!(j%10)) // end of a row --Y X+=10</dm> There might be faster ways to do this or something like it, but it probably doesn't matter because this should run through fairly quickly. Lummox JR |
In response to Lummox JR
|
|
I really don't want any type of delay so I decided to take a different approach even if the randomness has some clustering. What I decided to do is the first 20 mobs created will be the zombies the rest will be warriors. After they're all created, a proc will be run that swaps zombie positions with warriors. The proc looks something like this:
proc/Scatter() These monsters aren't being used to fight other mobs, so I don't think it's crucial that they should have their own specific type path. The proc works, but how would I: 1. Make it more efficient. 2. Make it less clustering but still with no type of delay 3. Since the first 20 mobs created are zombies, when the proc is called the first 2 rows will be warriors. The first two rows will always be one type. I want to avoid that and I think I can do this by selecting random mobs in the list to be switched, but I think there is a delay associated with this idea. I tried using prob() in the for() loop but that doesn't seem to work. If you have any ideas that fixes this issue and wouldn't involve a or much of a delay, that would really help. |
In response to Bobmcapple
|
|
Bump
|
In response to Bobmcapple
|
|
Just follow Lummox's advice.
|
In response to Garthor
|
|
But there's delay?
|
In response to Bobmcapple
|
|
There's delay in everything. Sometimes really small, sometimes long.
If you see any sleeps or spawns, take them out. If not, your code is so large it's taking a while to process.. |
pick()
rand()
prob()
Those are my most used ones. Look them up in the DM Reference, and figure it out.