GKGameModel

Trait GKGameModel 

Source
pub unsafe trait GKGameModel: NSObjectProtocol + NSCopying {
    // Provided methods
    unsafe fn players(
        &self,
    ) -> Option<Retained<NSArray<ProtocolObject<dyn GKGameModelPlayer>>>>
       where Self: Sized + Message { ... }
    unsafe fn activePlayer(
        &self,
    ) -> Option<Retained<ProtocolObject<dyn GKGameModelPlayer>>>
       where Self: Sized + Message { ... }
    unsafe fn setGameModel(&self, game_model: &ProtocolObject<dyn GKGameModel>)
       where Self: Sized + Message { ... }
    unsafe fn gameModelUpdatesForPlayer(
        &self,
        player: &ProtocolObject<dyn GKGameModelPlayer>,
    ) -> Option<Retained<NSArray<ProtocolObject<dyn GKGameModelUpdate>>>>
       where Self: Sized + Message { ... }
    unsafe fn applyGameModelUpdate(
        &self,
        game_model_update: &ProtocolObject<dyn GKGameModelUpdate>,
    )
       where Self: Sized + Message { ... }
    unsafe fn scoreForPlayer(
        &self,
        player: &ProtocolObject<dyn GKGameModelPlayer>,
    ) -> NSInteger
       where Self: Sized + Message { ... }
    unsafe fn isWinForPlayer(
        &self,
        player: &ProtocolObject<dyn GKGameModelPlayer>,
    ) -> bool
       where Self: Sized + Message { ... }
    unsafe fn isLossForPlayer(
        &self,
        player: &ProtocolObject<dyn GKGameModelPlayer>,
    ) -> bool
       where Self: Sized + Message { ... }
    unsafe fn unapplyGameModelUpdate(
        &self,
        game_model_update: &ProtocolObject<dyn GKGameModelUpdate>,
    )
       where Self: Sized + Message { ... }
}
Available on crate feature GKGameModel only.
Expand description

A protocol for abstracting a game model for use with the GKMinmaxStrategist class. The minmax strategist uses the game model class, along with GKGameModelPlayer and GKGameModelUpdate to find optimal moves in an adversarial, turn-based game.

See also Apple’s documentation

Provided Methods§

Source

unsafe fn players( &self, ) -> Option<Retained<NSArray<ProtocolObject<dyn GKGameModelPlayer>>>>
where Self: Sized + Message,

Array of instances of GKGameModelPlayers representing players within this game model. When the GKMinmaxStrategist class is used to find an optimal move for a specific player, it uses this array to rate the moves of that player’s opponent(s).

Source

unsafe fn activePlayer( &self, ) -> Option<Retained<ProtocolObject<dyn GKGameModelPlayer>>>
where Self: Sized + Message,

The player whose turn it is to perform an update to the game model. GKMinmaxStrategist assumes that the next call to the applyGameModelUpdate: method will perform a move on behalf of this player.

Source

unsafe fn setGameModel(&self, game_model: &ProtocolObject<dyn GKGameModel>)
where Self: Sized + Message,

Sets the data of another game model. All data should be copied over, and should not maintain any pointers to the copied game state. This is used by the GKMinmaxStrategist to process permutations of the game without needing to apply potentially destructive updates to the primary game model.

Source

unsafe fn gameModelUpdatesForPlayer( &self, player: &ProtocolObject<dyn GKGameModelPlayer>, ) -> Option<Retained<NSArray<ProtocolObject<dyn GKGameModelUpdate>>>>
where Self: Sized + Message,

Returns an array of all the GKGameModelUpdates (i.e. actions/moves) that the active player can undertake, with one instance of GKGameModelUpdate for each possible move. Returns nil if the specified player is invalid, is not a part of the game model, or if there are no valid moves available.

Source

unsafe fn applyGameModelUpdate( &self, game_model_update: &ProtocolObject<dyn GKGameModelUpdate>, )
where Self: Sized + Message,

Applies a GKGameModelUpdate to the game model, potentially resulting in a new activePlayer. GKMinmaxStrategist will call this method on a copy of the primary game model to speculate about possible future moves and their effects. It is assumed that calling this method performs a move on behalf of the player identified by the activePlayer property.

Source

unsafe fn scoreForPlayer( &self, player: &ProtocolObject<dyn GKGameModelPlayer>, ) -> NSInteger
where Self: Sized + Message,

Returns the score for the specified player. A higher value indicates a better position for the player than a lower value. Required by GKMinmaxStrategist to determine which GKGameModelUpdate is the most advantageous for a given player. If the player is invalid, or not a part of the game model, returns NSIntegerMin.

Source

unsafe fn isWinForPlayer( &self, player: &ProtocolObject<dyn GKGameModelPlayer>, ) -> bool
where Self: Sized + Message,

Returns YES if the specified player has reached a win state, NO if otherwise. Note that NO does not necessarily mean that the player has lost. Optionally used by GKMinmaxStrategist to improve move selection.

Source

unsafe fn isLossForPlayer( &self, player: &ProtocolObject<dyn GKGameModelPlayer>, ) -> bool
where Self: Sized + Message,

Returns YES if the specified player has reached a loss state, NO if otherwise. Note that NO does not necessarily mean that the player has won. Optionally used by GKMinmaxStrategist to improve move selection.

Source

unsafe fn unapplyGameModelUpdate( &self, game_model_update: &ProtocolObject<dyn GKGameModelUpdate>, )
where Self: Sized + Message,

Trait Implementations§

Source§

impl ProtocolType for dyn GKGameModel

Source§

const NAME: &'static str = "GKGameModel"

The name of the Objective-C protocol that this type represents. Read more
Source§

fn protocol() -> Option<&'static AnyProtocol>

Get a reference to the Objective-C protocol object that this type represents. Read more
Source§

impl<T> ImplementedBy<T> for dyn GKGameModel
where T: ?Sized + Message + GKGameModel,

Implementations on Foreign Types§

Source§

impl<T> GKGameModel for ProtocolObject<T>
where T: ?Sized + GKGameModel,

Implementors§