objc2_gameplay_kit/generated/
GKGameModel.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// Maximum / minimum values for GKGameModel scoreForPlayer. Values must be within these ranges.
11///
12/// See also [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkgamemodelmaxscore?language=objc)
13pub static GKGameModelMaxScore: NSInteger = 1 << 24;
14
15/// [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkgamemodelminscore?language=objc)
16pub static GKGameModelMinScore: NSInteger = -(1 << 24);
17
18extern_protocol!(
19    /// A protocol used to encapsulate the data needed to affect an update to a game model.
20    /// Typically represents an action or move performed by a player.
21    ///
22    /// See also [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkgamemodelupdate?language=objc)
23    pub unsafe trait GKGameModelUpdate: NSObjectProtocol {
24        /// Property get/set by GKMinmaxStrategist to sort GKGameModelUpdates.
25        #[unsafe(method(value))]
26        #[unsafe(method_family = none)]
27        unsafe fn value(&self) -> NSInteger;
28
29        /// Setter for [`value`][Self::value].
30        #[unsafe(method(setValue:))]
31        #[unsafe(method_family = none)]
32        unsafe fn setValue(&self, value: NSInteger);
33    }
34);
35
36extern_protocol!(
37    /// A protocol used to represent an individual player within a game model.
38    ///
39    /// See also [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkgamemodelplayer?language=objc)
40    pub unsafe trait GKGameModelPlayer: NSObjectProtocol {
41        /// Identifier used by GKMinmaxStrategist differentiate players from one another.
42        #[unsafe(method(playerId))]
43        #[unsafe(method_family = none)]
44        unsafe fn playerId(&self) -> NSInteger;
45    }
46);
47
48extern_protocol!(
49    /// A protocol for abstracting a game model for use with the GKMinmaxStrategist class. The minmax
50    /// strategist uses the game model class, along with GKGameModelPlayer and GKGameModelUpdate to
51    /// find optimal moves in an adversarial, turn-based game.
52    ///
53    /// See also [Apple's documentation](https://developer.apple.com/documentation/gameplaykit/gkgamemodel?language=objc)
54    pub unsafe trait GKGameModel: NSObjectProtocol + NSCopying {
55        /// Array of instances of GKGameModelPlayers representing players within this game model. When the
56        /// GKMinmaxStrategist class is used to find an optimal move for a specific player, it uses this
57        /// array to rate the moves of that player’s opponent(s).
58        #[unsafe(method(players))]
59        #[unsafe(method_family = none)]
60        unsafe fn players(
61            &self,
62        ) -> Option<Retained<NSArray<ProtocolObject<dyn GKGameModelPlayer>>>>;
63
64        /// The player whose turn it is to perform an update to the game model. GKMinmaxStrategist assumes
65        /// that the next call to the applyGameModelUpdate: method will perform a move on behalf of this player.
66        #[unsafe(method(activePlayer))]
67        #[unsafe(method_family = none)]
68        unsafe fn activePlayer(&self) -> Option<Retained<ProtocolObject<dyn GKGameModelPlayer>>>;
69
70        /// Sets the data of another game model. All data should be copied over, and should not maintain
71        /// any pointers to the copied game state. This is used by the GKMinmaxStrategist to process
72        /// permutations of the game without needing to apply potentially destructive updates to the
73        /// primary game model.
74        #[unsafe(method(setGameModel:))]
75        #[unsafe(method_family = none)]
76        unsafe fn setGameModel(&self, game_model: &ProtocolObject<dyn GKGameModel>);
77
78        /// Returns an array of all the GKGameModelUpdates (i.e. actions/moves) that the active
79        /// player can undertake, with one instance of GKGameModelUpdate for each possible move.
80        /// Returns nil if the specified player is invalid, is not a part of the game model, or
81        /// if there are no valid moves available.
82        #[unsafe(method(gameModelUpdatesForPlayer:))]
83        #[unsafe(method_family = none)]
84        unsafe fn gameModelUpdatesForPlayer(
85            &self,
86            player: &ProtocolObject<dyn GKGameModelPlayer>,
87        ) -> Option<Retained<NSArray<ProtocolObject<dyn GKGameModelUpdate>>>>;
88
89        /// Applies a GKGameModelUpdate to the game model, potentially resulting in a new activePlayer.
90        /// GKMinmaxStrategist will call this method on a copy of the primary game model to speculate
91        /// about possible future moves and their effects. It is assumed that calling this method performs
92        /// a move on behalf of the player identified by the activePlayer property.
93        #[unsafe(method(applyGameModelUpdate:))]
94        #[unsafe(method_family = none)]
95        unsafe fn applyGameModelUpdate(
96            &self,
97            game_model_update: &ProtocolObject<dyn GKGameModelUpdate>,
98        );
99
100        /// Returns the score for the specified player. A higher value indicates a better position for
101        /// the player than a lower value. Required by GKMinmaxStrategist to determine which
102        /// GKGameModelUpdate is the most advantageous for a given player. If the player is invalid, or
103        /// not a part of the game model, returns NSIntegerMin.
104        #[optional]
105        #[unsafe(method(scoreForPlayer:))]
106        #[unsafe(method_family = none)]
107        unsafe fn scoreForPlayer(
108            &self,
109            player: &ProtocolObject<dyn GKGameModelPlayer>,
110        ) -> NSInteger;
111
112        /// Returns YES if the specified player has reached a win state, NO if otherwise. Note that NO does not
113        /// necessarily mean that the player has lost. Optionally used by GKMinmaxStrategist to improve move selection.
114        #[optional]
115        #[unsafe(method(isWinForPlayer:))]
116        #[unsafe(method_family = none)]
117        unsafe fn isWinForPlayer(&self, player: &ProtocolObject<dyn GKGameModelPlayer>) -> bool;
118
119        /// Returns YES if the specified player has reached a loss state, NO if otherwise. Note that NO does not
120        /// necessarily mean that the player has won. Optionally used by GKMinmaxStrategist to improve move selection.
121        #[optional]
122        #[unsafe(method(isLossForPlayer:))]
123        #[unsafe(method_family = none)]
124        unsafe fn isLossForPlayer(&self, player: &ProtocolObject<dyn GKGameModelPlayer>) -> bool;
125
126        #[optional]
127        #[unsafe(method(unapplyGameModelUpdate:))]
128        #[unsafe(method_family = none)]
129        unsafe fn unapplyGameModelUpdate(
130            &self,
131            game_model_update: &ProtocolObject<dyn GKGameModelUpdate>,
132        );
133    }
134);