Contents

isWin(for:)

Returns a Boolean value indicating whether the current state of the game model reflects a win for the specified player.

Declaration

optional func isWin(for player: any GKGameModelPlayer) -> Bool

Parameters

  • player:

    An instance of your game’s player class (a custom class implementing the Gkgamemodelplayer protocol) representing the player evaluating the game model.

Return Value

true if this game model represents a winning state for the specified player; false if the game has been won or has not yet concluded.

Discussion

If the game has been won or lost, a strategist evaluating the game model can avoid evaluating further moves in the game and can therefore plan a successful move more efficiently.

For some games, merely identifying winning and losing states of the game model and using a sufficiently large maxLookAheadDepth value is enough for a strategist to play the game well. However, you can improve both the game performance and the runtime efficiency of move planning by also implementing the score(for:) method to distinguish the relative desirability of non-game-ending states.

See Also

Evaluating a Game Model