<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GameplayKit",
  "identifier" : "/documentation/GameplayKit/GKMinmaxStrategist",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKMinmaxStrategist"
  },
  "title" : "GKMinmaxStrategist"
}
-->

# GKMinmaxStrategist

An AI that chooses moves in turn-based games using a *deterministic* strategy.

```
class GKMinmaxStrategist
```

## Overview

To use this strategy, you provide scores that rate possible states of your game model for their desirability to a player, and the strategist exhaustively searches all possible game model states in order to make choices that maximize the rating for its own moves and minimize the rating for an opponent’s moves. You provide information about your game model to the strategist by implementing the [`GKGameModel`](/documentation/GameplayKit/GKGameModel), [`GKGameModelPlayer`](/documentation/GameplayKit/GKGameModelPlayer), and [`GKGameModelUpdate`](/documentation/GameplayKit/GKGameModelUpdate) protocols in your custom classes, and then use the strategist’s methods to find optimal moves.

### Choosing a Strategist

GameplayKit provides multiple strategist classes. The advantage of the [`GKMinmaxStrategist`](/documentation/GameplayKit/GKMinmaxStrategist) class is its deterministic, exhaustive strategy: If allowed, the minmax strategist searches the entire space of possible moves and the game states they lead to, so it can find the best possible move at any time. The cost of this strategy is performance: searching every possible game state takes time, especially for complex games where many moves are possible at any given time. Additionally, this strategy requires that your game model implement the [`score(for:)`](/documentation/GameplayKit/GKGameModel/score(for:)) method to rate the desirability of each game state.

See the [`GKStrategist`](/documentation/GameplayKit/GKStrategist) protocol for alternate strategies, as well as the methods and properties supported by all strategist classes.

### Using a Minmax Strategist

Using the minmax strategist in a game requires the following steps:

1. Create classes describing your gameplay model, adopting the [`GKGameModel`](/documentation/GameplayKit/GKGameModel), [`GKGameModelPlayer`](/documentation/GameplayKit/GKGameModelPlayer), and [`GKGameModelUpdate`](/documentation/GameplayKit/GKGameModelUpdate) protocols.
2. Create [`GKMinmaxStrategist`](/documentation/GameplayKit/GKMinmaxStrategist) instance and configure its properties [`maxLookAheadDepth`](/documentation/GameplayKit/GKMinmaxStrategist/maxLookAheadDepth) and [`randomSource`](/documentation/GameplayKit/GKStrategist/randomSource) to determine its gameplay behavior.
3. Point the minmax strategist’s [`gameModel`](/documentation/GameplayKit/GKStrategist/gameModel) property at the instance of your game model class (that is, your class that implements the [`GKGameModel`](/documentation/GameplayKit/GKGameModel) protocol) representing the current state of the game in play.
4. Use the [`bestMoveForActivePlayer()`](/documentation/GameplayKit/GKStrategist/bestMoveForActivePlayer()) method to select the best possible move for the current player. This method returns a move object (that is, an instance of the custom class you create to adopt the [`GKGameModelUpdate`](/documentation/GameplayKit/GKGameModelUpdate) protocol).
5. Examine the move object to make use of the move selected by the strategist. You created this instance in the [`gameModelUpdates(for:)`](/documentation/GameplayKit/GKGameModel/gameModelUpdates(for:)) method of your game model class to describe a possible move in your game, so examining the object gives you the information needed to perform that move.

For more information about describing your gameplay model and using strategists, see [The Minmax Strategist](https://developer.apple.com/library/archive/documentation/General/Conceptual/GameplayKit_Guide/Minmax.html#//apple_ref/doc/uid/TP40015172-CH2) in [GameplayKit Programming Guide](https://developer.apple.com/library/archive/documentation/General/Conceptual/GameplayKit_Guide/index.html#//apple_ref/doc/uid/TP40015172).

## Topics

### Configuring a Strategist

[`maxLookAheadDepth`](/documentation/GameplayKit/GKMinmaxStrategist/maxLookAheadDepth)

The number of future turns for the strategist to consider when planning moves.

### Planning Game Moves

[`-  bestMoveForPlayer:`](/documentation/GameplayKit/GKMinmaxStrategist/bestMove(for:))

Computes and returns the best possible move for the specified player.

[`-  randomMoveForPlayer:fromNumberOfBestMoves:`](/documentation/GameplayKit/GKMinmaxStrategist/randomMove(for:fromNumberOfBestMoves:))

Computes several of the best possible moves for the specified player, and returns a move randomly selected from among them.

## Relationships

### Conforms To

[`CVarArg`](/documentation/Swift/CVarArg)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`GKStrategist`](/documentation/GameplayKit/GKStrategist)

[`Hashable`](/documentation/Swift/Hashable)

[`Equatable`](/documentation/Swift/Equatable)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)