The GameplayKit namespace provides classes for high-level game-playing mechanics such as pathfinding, rules engines, and AI opponents.
A GKComponent that can move and has goals.
A GKAgent whose movement is restricted to two dimensions.
A 3D agent that responds to goals.
Delegate object that provides methods relating to synchronizing the state of a GKAgent with external constraints, goals, and representations.
Random generator based on the ARC4 algorithm. Often a good choice.
A collection of GKGoal objects and weights, together defining a cohesive game behavior.
A GKCoherentNoiseSource whose output is similar to Perlin noise but with more rounded features.
A GKNoiseSource whose output consists of alternating black and white squares.
A GKObstacle defined by a location and a radius.
A GKNoiseSource whose output varies smoothly and continuously.
Abstract superclass for components, including GKAgent objects, in an Entity-Component architecture (see remarks).
Holds GKComponent objects of a specific subtype and updates them periodically.
A GKNoiseSource whose output is a single value.
A GKNoiseSource whose output consists of concentric cylindrical shells. Appropriate for wood-grain textures.
An element in a GKDecisionTree.
A tree of questions, answers, and actions.
A type that is composed of a number of GKComponent objects in an Entity-Component architecture.
Describes gameplay in a way that can be optimized with a GKMinMaxStrategist.
A GKRandomDistribution that produces a Gaussian (normal) distribution.
Influences the movement of one or more GKAgent objects.
A mathematical graph used for navigability and pathfinding.
The base class for nodes in a GKGraph.
A GKGraphNode that contains a 2D floating-point position.
A GKGraphNode that exists in three-dimensional space.
A GKGraph in which movement is constrained to an integer grid
A GKGraphNode that contains a 2D integer position.
A IGKStrategist that combines Monte Carlo Tree Search and local search via MinMax.
A slow GKRandomSource with very good randomness.
Game AI that evaluates potential game states, scores them, and attempts to maximize it's own score while minimizing it's opponents.
A strategist that reaches a solution that is probably close to optimal in a deterministic amount of time.
Uses a GKNoiseSource to procedurally generate an infinite three-dimensional noise field.
Slices a finite, two-dimensional rectangle from a GKNoise object's infinite, three-dimensional noise field.
Abstract base class for procedural noise generators.
Abstract class representing areas that GKAgent objects cannot traverse.
A GKGraph that generates a space-filling network for representation, allowing smooth, but inefficient, paths.
A data structure that efficiently organizes three-dimensional elements.
Holds a 2D polygonal path that can be followed by a GKAgent.
A GKCoherentNoiseSource that generates improved Perlin noise.
A GKObstacle with an arbitrarily complex shape.
A data structure that efficiently organizes objects in two-dimensional space.
A node in a quadtree.
Defines a probability distribution. This class defines a uniform distribution (all values equally likely), while subclasses GKGaussianDistribution and GKShuffledDistribution provide different likelihoods.
Base class for game-appropriate pseudo-random number generators. Do not use for cryptographic or security purposes.
A GKCoherentNoiseSource whose output is similar to Perlin noise but with sharp boundaries.
A data structure for efficiently searching objects arranged in two-dimensional space.
A single element, comprising a predicate and an action, that represents a discrete rule in a GKRuleSystem.
Maintains a collection of GKRule objects, activating them as appropriate.
Associates GameplayKit objects with a SpriteKit SKScene.
A GKRandomDistribution that shuffles a collection in a manner that makes sequences of similar values unlikely (minimal hot/cold streaks).
A GKObstacle that is an impassable spherical volume.
A GKNoiseSource whose output consists of concentric shells. Appropriate for wood-grain textures.
An abstract class representing a discrete state in a GKStateMachine.
Holds GKState objects and manages transitions between them.
A GKNoiseSource whose output divides space into cells surrounding seed points. Appropriate for crystalline textures.
An axis-aligned rectangular three-dimensional box.
Interface representing the required methods (if any) of the protocol GKAgentDelegate.
The current game state. Particularly useful in conjunction with GKMinMaxStrategist.
A uniquely-identified player of a game. Developers must implement GetPlayerId(IGKGameModelPlayer).
A valid game move. The minimal data necessary to transition a valid IGKGameModel into a valid subsequent state.
Interface for GameplayKit pseudo-random number generators.
Interface for a game strategist (AI).
Holds options for how nodes should be generated in a GKMeshGraph<NodeType>.
Introduced in iOS 9, GameplayKit provides classes for high-level game-playing mechanics such as pathfinding, rules engines (both fuzzy and classical), and a prebuilt AI opponent in the form of GKMinMaxStrategist.
The minimax theorem, first stated by John von Neumann in 1928, holds that in a two-person, zero-sum, game with finite strategies, there exists some optimal play (or plays) that simultaneously maximizes the expected value for the current player and minimizes the expected value for the opposing player. In other words, in such games, there is a "best move" (although, of course, even the best move might lead to a loss or a tie, depending upon the state of the game).
GameplayKit implements the minimax algorithm in its GKMinMaxStrategist class and related classes (especially GKGameModel). The GKMinMaxStrategist is an optimized version of the minimax algorithm that uses memory efficiently and pares the search-tree at terminal nodes, but developer's should be aware that the algorithm can be costly: minimax algorithm's time efficiency is
b is the number of states in a single look-ahead "ply" and
m is the number of plies searched (see
The minimax theorem applies to a very large number of games, from trivial ones such as Nim and Tic-Tac-Toe, to complex games such as Chess and Go. However, games such as Chess and Go have so many possible game states and plies that the expense of calculating the optimal move quickly becomes astronomical. Even in such cases, the GKMinMaxStrategist may be used to evaluate several hundred or thousand moves and, if the developer can accurately program an estimate of the strength or weakness of a given game state, produce a strong opponent.
Developers implement this interface in order to model the game and it's current state.
In a board game, for instance, this will typically be the board and all pieces and a reference to the active player.
In addition, if it is to be used with GKMinMaxStrategist, this class must implement
the functions that describes potential moves (|
|IGKGameModelUpdate||This class describes a game "move" and contains enough information to transition the IGKGameModel between it's current state and a valid new one. Many thousand instances of this class may be required by the GKMinMaxStrategist, so the developer should take care to make it lightweight.|
The GKMinMaxStrategist relies on the value of |
First, the IGKGameModelPlayer objects are retrieved. Then, starting with the current game state, and while the ply depth is less than MaxLookAheadDepth, the set of legal possible moves from the current state is returned by
The GKMinMaxStrategist then evaluates each of the potential moves by calling, first, IsWin and IsLoss. If either of these methods returns
true, the GKMinMaxStrategist marks that game state as a terminal node and will not attempt to investigate it further in later plies. If neither method returns
true, though, the method
The developer should write a
true within MaxLookAheadDepth, the
Developers should note that the GKMinMaxStrategist may allocate many copies of IGKGameModelPlayer and IGKGameModel as well as many IGKGameModelUpdate objects. Developers should rely on value, not reference, equality, and should exercise care when it comes to these objects manipulating global or static state.
Send feedback about: