Strategy

public protocol Strategy

Protocol to be implemented for strategy algorithms.

Requires

Must be immutable & have value semantics.
  • Evaluates the available moves for the game’s current state.

    Declaration

    Swift

    func evaluatedMoves(game: Game) -> AnySequence<(Game.Move, Evaluation<Game.Score>)>

    Return Value

    Lazy sequence of evaluated moves.

  • The given game type to be reasoned about.

    Declaration

    Swift

    associatedtype Game: Strategist.Game
  • Updates strategy’s internal state for chosen move.

    Declaration

    Swift

    func update(move: Game.Move) -> Self

    Return Value

    Updated strategy.

  • bestMoves(_:) Extension method

    Evaluates the available moves for the game’s current state.

    Declaration

    Swift

    public func bestMoves(game: Game) -> [Game.Move]

    Return Value

    Lazy sequence of evaluated moves.

  • firstMaximizingMove(_:) Extension method

    Greedily selects the first encountered maximizing available move for the game’s current state.

    Note

    The selection is deterministic.

    Declaration

    Swift

    public func firstMaximizingMove(game: Game) -> Game.Move?

    Return Value

    First maximizing available move.

  • Randomly selects from the encountered maximizing available move for the game’s current state.

    Note

    The selection is deterministic.

    Declaration

    Swift

    public func randomMaximizingMove(game: Game, randomSource: (UInt32 -> UInt32)? = nil) -> Game.Move?

    Return Value

    Randomly chosen maximizing available move.