Staredit Network

Staredit Network -> UMS Assistance -> Generating a conditional Random Number
Report, edit, etc...Posted by Leath on 2006-07-13 at 18:25:17
Greetings everyone,

I am seeking enlightment on the ways of randomness. Might have been a common problem to many of you fellow map makers before, and I hope brain storming over ideas will be in everyone's benefit.


My map:
I am making a map which looks like the Arena. Micro based combats, with different Match Ups (MUs), but where my version is going to differ is that every time the game is played the MUs should change.

What I need:
I want a way to generate a set of random numbers under the following conditions
1- They must all have the same probability of occurring
2- They should be excludable, by which I mean that once a number has occurred it wont occur again.
3- It should be easy to manipulate. ie: add another number upon map editing.


My current problem:
The only way to found to deal with this, was to create several units for a computer opponent, then add the Junk Yard Dog Ai Script to them. The units would move to a different location, and each unit would represent a different MU.
But there is a problem!! Its an 8 player's map and there is no way to include a computer opponent. Player 12's trigger are disregarded, and P1-8 cannot send an AI script order to other players. AI script are all reflexive.


My current solution:
I kept the player 12 as the holder of the units, and added building stacked on top of the units. The effect is that the units will randomly roam around just like Junk Yard Dog script.
But its plain ugly....


I am trying to find an alternative way for this problem.
Something I could do with switches, maybe timer... Or if there is a way to add a 9th player to the game.


Thanks in advance for any tip. smile.gif
Ill keep brainstorming for solutions in the mean time.

Yours,
Leath
Report, edit, etc...Posted by Noober on 2006-07-13 at 19:03:29
Just randomize switches. It's a lot simpler than doing all that AI script stuff...
Report, edit, etc...Posted by Leath on 2006-07-13 at 19:27:45
QUOTE(Noober @ Jul 13 2006, 04:03 PM)
Just randomize switches. It's a lot simpler than doing all that AI script stuff...
[right][snapback]523285[/snapback][/right]



Please dont give me those replies without explaining how...
Cuz I dont know how I could make this work with switches and meet all my conditions.


For example, I could associate, say, a mineral value to the switch, and add triggers:
Condition: always
Action: randomnize s1
randomnize s2
randomnize s3

Condition: s1 is on
Action: add +1 mineral to P1

Condition: s2 is on
Action: add +2 minerals to P1

Condition: s3 is on
Action: add +4 minerals to P1

This would generate a range of
0 to 7 minerals with same probabilities....


But then it doesnt meet my needs...
I want to be able to modify the range easily by one unit.
What if I want a range of 0-10? Which ever other value I add in the 4th switch willl bias the others, and I will never attain the range of 0-10 with equal probabilities.

And how would I be able to make the events exclusive? What prevents the number 5 from coming twice in a row??

I really need a lottery draw...
Imagine a box filled with balls each of which has a different number.
The balls are picked at random, with the exact same probability.
So if there are 10 balls, the probability of picking any given ball is 1/10.
Each ball is associated with a different prize which is exclusive, so you cannot take the same ball twice.
And everytime there is a new lottery I want to be able to select the number of balls with no constrains... I could put 5,6,7,8,11,25,10000, or any other amount of balls that I wanted inside the box.

How can I do that with switches???
Report, edit, etc...Posted by Kenoli on 2006-07-13 at 19:28:52
QUOTE(MMA Forum Guidelines)
1. Please, ALWAYS check the Tutorials Database before posting.
Randomization
Report, edit, etc...Posted by Leath on 2006-07-13 at 19:38:11
QUOTE(Kenoli @ Jul 13 2006, 04:28 PM)
Randomization
[right][snapback]523304[/snapback][/right]


Omg... I did read that, and it doesnt help me with what I want.

And I did search the forum too.
And I did search the web.
And I did search other map making forums.


This tutorials just covers how to make events with switches which are exponentials, and is gonna generate more than 1 event at a time as it increases...

Plus the critter idea is alright, but it not random!! Its biased towards the locations' positioning. Id have to create a perfect circle around the critter starting area and God knows how long before the critter decides to walk over one of them... and as the location moves away and there is few left, it could take several minutes before the critter steps on the last ones. I personally dislike that...
Report, edit, etc...Posted by Kenoli on 2006-07-13 at 19:59:48
Personally, I'd use the 4th method down, "Randomization using death counters".

It's very simple, and you can adjust the amount of outcomes easily.
It's also easy to exclude certain outcomes after they happen. Do something like this:
Trigger
Description:
Outcome #5
Conditions:
¤ 'Player' has suffered exactly 5 deaths of 'DeathCounter'.
¤ 'Switch 5' is Cleared.
Actions:
¤ Set 'Switch 5'.
¤ (Do actions for outcome #5)
Report, edit, etc...Posted by Leath on 2006-07-13 at 20:16:57
QUOTE(Kenoli @ Jul 13 2006, 04:59 PM)
Personally, I'd use the 4th method down, "Randomization using death counters".

It's very simple, and you can adjust the amount of outcomes easily.
It's also easy to exclude certain outcomes after they happen. Do something like this:


Trigger
Description:
Outcome #5
Conditions:
¤ 'Player' has suffered exactly 5 deaths of 'DeathCounter'.
¤ 'Switch 5' is Cleared.
Actions:
¤ Set 'Switch 5'.
¤ (Do actions for outcome #5)

[right][snapback]523321[/snapback][/right]




Thanks smile.gif
But sorry lol its not what I need (I feel like a grumpy old lady trying to buy clothes... nothing ever suits me well enough tongue.gif)

It would work after the second event. Death counters require user input or are time based. tongue.gif
Since the first event will always take place in the same time the margin of randomness would be lower if it was time based... for all subsequent ones DeathCounter would do just fine happy.gif
Report, edit, etc...Posted by devilesk on 2006-07-13 at 20:26:31
1 switch randomization is probably the best trigger based way to do this. It's similiar to what you posted in your example and I'll explain a few ways to do what you want.

1 switch randomization will generate a range of numbers based on powers of 2.

You can modify the range of numbers you want to use that will generate an event by just making every randomly generated number that's above the range you want restart the randomization process. If you later want to change the range then just modify the trigger that sets the limit for which random number results will rerandomize.

For example if you use 1 switch randomization to generate a range of 0 - 127 but you only want to use numbers from 0 - 100 just have a trigger with the condition and modifier of if the number is at least 101 Then rerandomize.

Using 1 switch randomization or any randomization system you can keep numbers from generating an event more than once after they have been picked. You can do this in a variety of ways, such as a switch or death counter being set or added to, creating units, bringing units after it has come up. Yet however you do it, it may start to get impractical.
QUOTE
Thanks smile.gif
But sorry lol its not what I need (I feel like a grumpy old lady trying to buy clothes... nothing ever suits me well enough tongue.gif)

It would work after the second event. Death counters require user input or are time based. tongue.gif
Since the first event will always take place in the same time the margin of randomness would be lower if it was time based... for all subsequent ones DeathCounter would do just fine happy.gif


What do you mean by death counters require user input or are time based? You can manipulate death counters using set deaths action. And kenoli's trigger would not work after the second event.

All of these randomization processes take place in one trigger cycle, unless you are rerandomizing, but even still, copying and pasting the whole process would be able to rerandomize in one trigger cycle.
--
In depth description of useless concept below.

A more complex but death counter saving method would be to store multiple values as "switches" in only one death counter. This idea was thought up by Shmidley and me and him discussed how it would be done. This would be based on powers of 2. I'm not sure how many different values you would be able to store in one death counter, but it would depend on the exact maximum a death counter can hold. For this example I'll use 8 "switches" stored in a death counter.

If you picture a switch in binary it can either be 0 or 1, set or clear. If you string 8 switches together they will look like this: 00000000 with each place value being either a 0 or a 1. For example if the switches looked like this in binary 10000000 then it could be read as 128 in decimal or switch 8 is set and the rest are cleared. 10000001 would be read as 129 in decimal or as switch 8 and switch 1 are set and the rest are cleared.

The decimal representation can be used in a death counter by adding the correct power of 2 if the corresponding switch is set. So if you want to set switch 1 you would add 1, switch 2 would add 2, switch 3 would add 4 ... switch 8 would add 128 and so on.

Now you have to be able to "read" which "switches" in the death counter are set or cleared by using triggers. To do this you would simply break down the death counter by subtracting powers of 2 starting with the highest power of 2 you are using to the lowest power. If a certain power of 2 can be subtracted from the death counter, then that means that corresponding switch is set.

Using 129 as an example, the process by which it would be read will look like this:

Can 128 be subtracted from it?
Yes, so that means "switch" 8 is set and then subtract 128

Can 64 be subtracted what's left? No, so move on

Can 32 be subtracted what's left? No, so keep going down
.
.
.
And then you it will get down to 1

Can 1 be subtracted what's left?
Yes (because the death counter's value is 1), so that means "switch 1" is set and then subtract 1

No matter what the value in the death counter is, after going through this process it will be set back down to 0. However, if you want to still keep track of the switches after going through them once, you will need to "restore" the value of the death counter to what it was before. To do this you would add an action to add the power of 2 you are subtracting into a "storage" death counter. And once you are done with the process you would have another process that would take the value of the storage counter and place it into the value of the death counter.

These processes are based on what we here call "binary countoffs" because you are subtracting powers of 2. You can see a good example of this being used in Tuxedo-Templar's calculator map. And the counter arithmetic tutorial http/www.staredit.net/index.php?tutorial=34
Report, edit, etc...Posted by Kenoli on 2006-07-14 at 00:09:27
QUOTE(Leath)
But sorry lol its not what I need
How is it not what you need? It fits your requirements.

QUOTE(HereToHelp)
All of these randomization processes take place in one trigger cycle, unless you are rerandomizing, but even still, copying and pasting the whole process would be able to rerandomize in one trigger cycle.
With the counter method you cycle through each possibility sequentially, it's not actually random at all. What determines the outcome is when the trigger activates. Without some kind of external input you'd get the same set of outcomes every time you played.
The easiest way to do it it to make a human player do something to activate it. Another way would be to add to the counter randomly.
Report, edit, etc...Posted by devilesk on 2006-07-14 at 02:54:36
QUOTE
With the counter method you cycle through each possibility sequentially, it's not actually random at all. What determines the outcome is when the trigger activates. Without some kind of external input you'd get the same set of outcomes every time you played.
The easiest way to do it it to make a human player do something to activate it. Another way would be to add to the counter randomly.


That's true, I left out that I was referring to the methods involving randomizing switches. And when I was talking about death counters I was referring to the death counter value generated from 1 switch randomization.
Next Page (1)