A randomizer object to be used when the strategist randomly selects a move.
Required.
SDKs
- iOS 9.1+
- macOS 10.11.2+
- Mac Catalyst 13.0+
- tvOS 9.0+
Framework
- Gameplay
Kit
Declaration
var randomSource: GKRandom? { get set }
Discussion
A strategist class uses this random source when you call the best
method. Different strategist classes use randomization in different ways:
A deterministic strategy, such as that of the
GKMinmax
class, can reach states where multiple moves are rated the most desirable. In such cases, the strategist can randomly choose from among the best possible moves, making the behavior of a computer-controlled player appear more natural and unpredictable.Strategist If this property is set to
nil
(the default), theGKMinmax
class method does not randomize—that is, when repeatedly presented with the same set of equally-optimal moves, theStrategist best
method always makes the same choice.Move For Active Player() A probabilistic strategy, such as that of the
GKMonte
class, requires a random source in order to randomly explore the set of possible moves.Carlo Strategist If this property is set to
nil
(the default), theGKMonte
class throws an exception when you call theCarlo Strategist best
method.Move For Active Player()
A randomizer is any object that implements the GKRandom
protocol, such as the GKRandom
and GKRandom
classes and their subclasses. Choosing a separate randomizer instance from that used by other systems in your game ensures that the randomization of moves is independent; that is, the strategist's selection of moves does not depend on your game’s other uses of randomization APIs. You can also use randomizer classes to reproduce a specific sequence of random actions for debugging, and to fine-tune the randomization behavior.