http://www.staredit.net/wiki/api.php?action=feedcontributions&user=Whiplash&feedformat=atomStaredit Network Wiki - User contributions [en]2020-11-01T01:22:18ZUser contributionsMediaWiki 1.24.1http://www.staredit.net/wiki/index.php?title=Randomization&diff=614Randomization2019-05-22T15:26:27Z<p>Whiplash: adding link to randomization map with music</p>
<hr />
<div>Games often need to make use of random numbers. Use one of the methods described below if your map requires randomization.<br />
<br />
==Switch Methods==<br />
Switches have two states, CLEAR (0) and SET (1).<br />
<br />
Switch randomization is a built-in function of the Set Switch trigger action.<br />
<br />
If two different outcomes is not be enough for you, there are ways of generating higher random numbers using switches.<br />
<br />
===Multi-Switch===<br />
This method will allow you to create a random number within the range of zero to some power of 2.<br />
<br />
Here is a list of how many switches you should use in this method, based on the number of outcomes you need:<br />
1 Switch: 2 Outcomes<br />
2 Switches: 4 Outcomes<br />
3 Switches: 8 Outcomes<br />
4 Switches: 16 Outcomes<br />
5 Switches: 32 Outcomes<br />
6 Switches: 64 Outcomes<br />
7 Switches: 128 Outcomes<br />
8 Switches: 256 Outcomes<br />
9 Switches: 512 Outcomes<br />
10 Switches: 1024 Outcomes<br />
11 Switches: 2048 Outcomes <br />
12 Switches: 4096 Outcomes<br />
13 Switches: 8192 Outcomes<br />
14 Switches: 16384 Outcomes<br />
15 Switches: 32768 Outcomes<br />
16 Switches: 65536 Outcomes<br />
<br />
After you determine how many switches you will need, make a trigger to randomize that amount of switches.<br />
In this example, we need to select one of the 8 players to go first. There are 8 outcomes, so we will be using 3 switches.<br />
<br />
{{StarCraft Trigger<br />
|description=<br />
|players=<br />
*Your choice<br />
|conditions=<br />
*Always.<br />
|actions=<br />
*Randomize Switch 1.<br />
*Randomize Switch 2.<br />
*Randomize Switch 3.<br />
}}<br />
<br />
With three switches (bits) randomized, there are 8 possible outcomes:<br />
#000<br />
#001<br />
#010<br />
#011<br />
#100<br />
#101<br />
#110<br />
#111<br />
<br />
Or, in other words:<br />
#Switch1 is CLEAR, Switch2 is CLEAR, Switch3 is CLEAR.<br />
#Switch1 is SET, Switch2 is CLEAR, Switch3 is CLEAR.<br />
#Switch1 is CLEAR, Switch2 is SET, Switch3 is CLEAR.<br />
#Switch1 is SET, Switch2 is SET, Switch3 is CLEAR.<br />
#Switch1 is CLEAR, Switch2 is CLEAR, Switch3 is SET.<br />
#Switch1 is SET, Switch2 is CLEAR, Switch3 is SET.<br />
#Switch1 is CLEAR, Switch2 is SET, Switch3 is SET.<br />
#Switch1 is SET, Switch2 is SET, Switch3 is SET.<br />
<br />
Then create a trigger for each possible switch outcome.<br />
<br />
For example, one could be:<br />
<br />
{{StarCraft Trigger<br />
|description=<br />
|players=<br />
*Your choice<br />
|conditions=<br />
*Switch 1 is CLEAR<br />
*Switch 2 is SET<br />
*Switch 3 is SET<br />
|actions=<br />
*Whatever is planned for outcome #7.<br />
}}<br />
<br />
If you need a number of outcomes that is not a power of 2, use the next-highest power of 2, and just re-randomize for all the outcomes you aren't using. It will eventually land on a valid outcome.<br />
<br />
===One Switch===<br />
<br />
This method will allow you to create a random number within the range of zero to some power of 2.<br />
<br />
It is possible to use just one switch to make a random number. This method can be easier to use than the multi-switch method because it stores the outcome in a counter, instead of in a bunch of switches. You can use 'at least' and 'at most' with a [[death counter]].<br />
<br />
Start by randomizing the switch.<br />
<br />
{{StarCraft Trigger<br />
|description=<br />
|players=<br />
*Your choice<br />
|conditions=<br />
*Always.<br />
|actions=<br />
*Randomize Switch 1.<br />
}}<br />
<br />
If the switch is set, add 1 to your counter.<br />
<br />
{{StarCraft Trigger<br />
|description=<br />
|players=<br />
*Your choice<br />
|conditions=<br />
*Switch 1 is SET.<br />
|actions=<br />
*Modify death counts for Player: Add 1 for Unit.<br />
}}<br />
<br />
Randomize the switch again.<br />
<br />
{{StarCraft Trigger<br />
|description=<br />
|players=<br />
*Your choice<br />
|conditions=<br />
*Always.<br />
|actions=<br />
*Randomize Switch 1.<br />
}}<br />
<br />
If the switch is set this time, add 2 to your counter.<br />
<br />
{{StarCraft Trigger<br />
|description=<br />
|players=<br />
*Your choice<br />
|conditions=<br />
*Switch 1 is SET.<br />
|actions=<br />
*Modify death counts for Player: Add 2 for Unit.<br />
}}<br />
<br />
Randomize the switch ''again''.<br />
<br />
{{StarCraft Trigger<br />
|description=<br />
|players=<br />
*Your choice<br />
|conditions=<br />
*Always.<br />
|actions=<br />
*Randomize Switch 1.<br />
}}<br />
<br />
If the switch is set this time, add 4 to your counter.<br />
<br />
{{StarCraft Trigger<br />
|description=<br />
|players=<br />
*Your choice<br />
|conditions=<br />
*Switch 1 is SET.<br />
|actions=<br />
*Modify death counts for Player: Add 4 for Unit.<br />
}}<br />
<br />
Now the death counter for 'Unit' will have a random number in the range of 0-7. Use the Deaths condition to detect the number.<br />
<br />
If you want to make a random number in a higher range, keep randomizing the switch and adding the next highest power of 2 to the counter. See the list above for how many outcomes you get for the amount of times you randomize the switch.<br />
<br />
==Other Methods==<br />
There are some easier, but less accurate, methods of getting random numbers.<br />
View these methods as making 'ever-changing' numbers, rather than actual random numbers.<br />
<br />
===Cycling Counter===<br />
The numbers you get from this method will not be random, but if you use some kind of user input, it will be an unpredictable number. (Example: A human player has to take a unit to a beacon to activate the trigger)<br />
<br />
Create a trigger that always adds 1 to a counter.<br />
<br />
{{StarCraft Trigger<br />
|description=<br />
|players=<br />
*Your choice<br />
|conditions=<br />
*Switch 1 is SET.<br />
|actions=<br />
*Preserve trigger.<br />
*Modify death counts for Player: Add 1 for Unit.<br />
}}<br />
<br />
Also make a trigger that resets the counter to 0 when it goes past a certain range. Our range is 0-7, so 8 is out of bounds.<br />
<br />
{{StarCraft Trigger<br />
|description=<br />
|players=<br />
*Your choice<br />
|conditions=<br />
*Player has suffered at least 8 deaths of unit.<br />
|actions=<br />
*Preserve trigger.<br />
*Modify death counts for Player: Set to 0 for Unit.<br />
}}<br />
<br />
Use the Deaths condition to detect the number. Make a trigger to detect each possible outcome. The number you get will depend completely on when the trigger is activated. Use [[hyper triggers]] for this method.<br />
<br />
===Roaming Unit===<br />
Units using the junkyard dog AI script move around in an unpredictable manner.<br />
<br />
To use this to get a number, first make an area for the unit to move around in, and put locations that cover all parts of it.<br />
<br />
[[File:Roamingunit.png]]<br />
<br />
Use the Bring condition to detect which location the unit is touching. Make different outcomes based on the location.<br />
<br />
Critters are not recommended for this because their movements are not random (they move up and left over 90% more often than they move down or right). Also, units using the junkyard dog AI do not move randomly when they are near the edge of the map (they have an extremely high chance of moving away from the edge).<br />
<br />
It is possible for the unit to remain in the same location for a long time.<br />
<br />
The quality of this method is questionable. Its usefulness is limited.<br />
<br />
===Example Map===<br />
Here is an example map that shows randomization being used between three different options to play music, you can change the triggers and death counter to adjust timing and what you want the randomized triggers to execute. [https://drive.google.com/open?id=1oETdaFOHM1RkJ-ImMH-BAc4wBqOAN0ze Map Link]<br />
<br />
[[Category:Tutorials]]</div>Whiplash