Join Tammy Coron for an in-depth discussion in this video What is randomization?, part of Programming iOS 9 and GamePlayKit.
- GamePlayKit includes a set of classes that allow you to build randomization into your games. Without randomization, games can quickly become predictable and boring. So, what is randomization in GamePlayKit? Randomization is all about generating random values such as numbers or Boolean values. These random values are obtained using a random source and a random distribution pattern. Random values are typically used for things like rolling dice, drawing cards in a poker game, or even as a way to determine the enemy's movement but not all random values are created equally.
Some are too predictable while others create way more chaos than intended. The trick is to find the right balance. According to Apple, there are five traits to consider when building your pseudo random behavior. They are randomness, performance, determinism, independence and known distribution. When you're developing your game, it's important to understand the level of randomness required in order to keep the player coming back for more. As humans, we expect a random number to be random but the truth is random numbers in a computer need to be computed.
They do this with an algorithm. So that means any random numbers are really just pseudo random. That's to say that these numbers feel random but they're actually not. So the question is, how random does it need to feel? And the answer to that question is how fast does it need to go. Understanding and evaluating each of these traits is essential when creating your random pattern. If your game's randomization becomes too predictable or is painfully slow and running complex algorithms, players will notice. What that means is don't opt for complex randomization that will slow your game down when a simple one might do instead.
Randomness and performance is often a compromise and equally important. Also important is determinism. If you create unpredictable randomness, it will be difficult for you as the developer to recreate specific results when required. But at the same time, it needs to feel random to the player which leads to the next trait, independence. Random sources are based on number sequences and the random values generated rely on the sequence. In a card game, you may want a single random source to be used when drawing cards.
But in the game where a character's behavior is determined by random values and multiple characters exist within the same game, using independence sources for each one lets the math independently. Thus making it more difficult for the player to predict each one's next move. And finally, known distribution. This is important in situations where your game play might have a need to follow a uniform distribution or a normal distribution. For example, you could use a normal distribution to help create an average high generator for creating your character's stats or you could use a uniform distribution on a dice roll where the probability exists for any number of the dice to come up equally.
Whatever the case is, game play makes it easy to add randomization to your game.
- What is GameplayKit?
- Working with random sources and distributions
- Adding randomization to games
- Working with entities and components
- Defining and creating states and behaviors
- Designing a game for AI
- Adding pathfinding to avoid obstacles
- Using the agent system to manage player movement
- Creating a simple rules system