(Page created) |
m |
||
| Line 1: | Line 1: | ||
<center><img src="https://www.shadowera.com/landing/img/blog-separator-2.png" ></center><br> | <center><img src="https://www.shadowera.com/landing/img/blog-separator-2.png" ></center><br> | ||
== Code Summary and Detailed Code == | == Code Summary and Detailed Code == | ||
| − | + | ||
{| class="wikitable" code-table" | {| class="wikitable" code-table" | ||
|- | |- | ||
| Line 22: | Line 22: | ||
#`Gameplay.ExecuteGameplay()`<br>Calls `UnityEngine.Random.Range(0, 4)` to set a random environment. | #`Gameplay.ExecuteGameplay()`<br>Calls `UnityEngine.Random.Range(0, 4)` to set a random environment. | ||
#`GameState.ActivateGameState()`<br>Calls `GameModel.SetCurSide(Random.Range(0, 2))` to randomly determine which player goes first. | #`GameState.ActivateGameState()`<br>Calls `GameModel.SetCurSide(Random.Range(0, 2))` to randomly determine which player goes first. | ||
| + | |- | ||
| + | ! colspan="2" | <center>DETAILED CODE</center> | ||
|- | |- | ||
| colspan="2" | This code is a collection of all the functions involved in the shuffle mechanic, though it doesn't exist as a single block in any one file. | | colspan="2" | This code is a collection of all the functions involved in the shuffle mechanic, though it doesn't exist as a single block in any one file. | ||
| Line 54: | Line 56: | ||
</syntaxhighlight></small> | </syntaxhighlight></small> | ||
|} | |} | ||
| − | </ | + | <center><img src="https://www.shadowera.com/landing/img/blog-separator-2.png" ></center><br> |
== Randomization explanation == | == Randomization explanation == | ||
<br> | <br> | ||
Shadow Era does not implement its own card shuffling technique; instead, it relies on the built-in randomization techniques provided by Unity, specifically through the `UnityEngine.Random` class. You can read [https://docs.unity3d.com/Manual/class-Random.html more information in the Unity Website] about this class. This is the [https://docs.unity3d.com/Manual/UnityManual.html Unity User Manual 2022.3]<br> | Shadow Era does not implement its own card shuffling technique; instead, it relies on the built-in randomization techniques provided by Unity, specifically through the `UnityEngine.Random` class. You can read [https://docs.unity3d.com/Manual/class-Random.html more information in the Unity Website] about this class. This is the [https://docs.unity3d.com/Manual/UnityManual.html Unity User Manual 2022.3]<br> | ||
<br> | <br> | ||
| − | #'''Random Number Generation Algorithm'''<br>Reliable Mechanism: Unity uses a pseudo-random number generation (PRNG) algorithm based on the [https://en.wikipedia.org/wiki/Mersenne_Twister Mersenne Twister]. This type of algorithm is recognized for its ability to produce a sequence of numbers that mimics randomness, with a long period and good distribution. | + | #'''Random Number Generation Algorithm'''<br>Reliable Mechanism: Unity uses a pseudo-random number generation (PRNG) algorithm based on the [https://en.wikipedia.org/wiki/Mersenne_Twister Mersenne Twister]. This type of algorithm is recognized for its ability to produce a sequence of numbers that mimics randomness, with a long period and good distribution.<br><br> |
| − | #'''State Control'''<br>State Management: With `Random.State`, Unity allows developers to save and restore the state of the random number generator. This ensures that card shuffling can be reproduced if necessary, which is useful for debugging and testing. | + | #'''State Control'''<br>State Management: With `Random.State`, Unity allows developers to [https://docs.unity3d.com/ScriptReference/Random-state.html save and restore] the state of the random number generator. This ensures that card shuffling can be reproduced if necessary, which is useful for debugging and testing.<br><br> |
| − | #'''Ease of Use'''<br>Simple Interface: The use of methods like `Random.Range` allows developers to quickly obtain random values within specific ranges, thereby facilitating the implementation of game logic. | + | #'''Ease of Use'''<br>Simple Interface: The use of methods like `Random.Range` allows developers to [https://docs.unity3d.com/ScriptReference/Random.html quickly obtain random values within specific ranges], thereby facilitating the implementation of game logic.<br><br> |
#'''Applications in Games'''<br>Used in Numerous Games: Many games developed in Unity ([https://en.wikipedia.org/wiki/Hollow_Knight Hollow Knight] & [https://en.wikipedia.org/wiki/Among_Us Among Us]) use this method for crucial mechanics such as card drawing, enemy placement, and other random elements. This would demonstrate its robustness and effectiveness in real game scenarios. | #'''Applications in Games'''<br>Used in Numerous Games: Many games developed in Unity ([https://en.wikipedia.org/wiki/Hollow_Knight Hollow Knight] & [https://en.wikipedia.org/wiki/Among_Us Among Us]) use this method for crucial mechanics such as card drawing, enemy placement, and other random elements. This would demonstrate its robustness and effectiveness in real game scenarios. | ||

| |
|
|---|---|
|
|
| | |
| |
| | |
| This code is a collection of all the functions involved in the shuffle mechanic, though it doesn't exist as a single block in any one file. | |
//1. GameModel.GetRandomSynced(int minInclusive, int maxExclusive) public static int GetRandomSynced(int minInclusive, int maxExclusive) { Random.State state = Random.state; Random.InitState(num); int result = Random.Range(minInclusive, maxExclusive); Random.state = state; return result; } //2. UnityEngine.Random.Range(int min, int max) int randomValue = UnityEngine.Random.Range(min, max); //3. GameManager.SomeMethod() public void SomeMethod() { return text + "rand=" + UnityEngine.Random.Range(0, 99999) + "\\n"; } //4. Gameplay.ExecuteGameplay() public void ExecuteGameplay() { int curEnvironment = UnityEngine.Random.Range(0, 4); } //5. GameState.ActivateGameState() public void ActivateGameState() { GameModel.SetCurSide(Random.Range(0, 2)); } | |

Shadow Era does not implement its own card shuffling technique; instead, it relies on the built-in randomization techniques provided by Unity, specifically through the `UnityEngine.Random` class. You can read more information in the Unity Website about this class. This is the Unity User Manual 2022.3