Code Summary and Detailed Code
FILE REFERENCES IN THE GAME |
TERMS TO LOCATE RANDOM REFERENCE
|
- GameManager.cs: Contains logic for game management, including randomization for card selection and gameplay interactions:
`SomeMethod()`, `AnotherMethod()`.
- Gameplay.cs: Contains the core gameplay mechanics, including randomization for environmental settings and interactions:
`ExecuteGameplay()`.
- GameState.cs: Contains the logic for managing game states, including randomization for determining player sides:
`ActivateGameState()`.
|
|
SUMMARY OF THE RANDOMIZATION PROCESS
|
- `GameModel.GetRandomSynced(int minInclusive, int maxExclusive)`
Used to obtain a random number within a given range. Calls `Random.Range(minInclusive, maxExclusive)` to generate the result.
- `UnityEngine.Random.Range(int min, int max)`
Used in several files to generate random values for game decisions.
- `GameManager.SomeMethod()`
Calls `UnityEngine.Random.Range(0, 99999)` to generate a random number, likely for tracking or logging.
- `Gameplay.ExecuteGameplay()`
Calls `UnityEngine.Random.Range(0, 4)` to set a random environment.
- `GameState.ActivateGameState()`
Calls `GameModel.SetCurSide(Random.Range(0, 2))` to randomly determine which player goes first.
|
DETAILED CODE
|
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));
}
|
Randomization explanation
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
- Random Number Generation Algorithm
Unity uses a pseudo-random number generation (PRNG) algorithm based on the 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.
- State Control
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.
- Ease of Use
The use of methods like `Random.Range` allows developers to quickly obtain random values within specific ranges, thereby facilitating the implementation of game logic.
- Applications in Games
Many games developed in Unity (Hollow Knight, Among Us & Legends of Runeterra) use this method for mechanics such as card drawing, enemy placement, and other random elements. This would demonstrate its robustness and effectiveness in real game scenarios.