AITreeStrategy

class AITreeStrategy : AIGameStrategy

A subclass of the AI game strategy designed for use with decision trees.

Agents that use the tree strategy will attempt to use a state assessement and determine the best action by submitting that assessement to a decision tree, depending on the tree’s implementation.

  • A history of all of the previous assessements this agent has made.

    Declaration

    Swift

    var history: [ActionHistoryItem]
  • Whether the agent should record all of its previous attempts. Defaults to false.

    Declaration

    Swift

    var recordsHistory: Bool
  • A list of all of the available actions the agent can make.

    Declaration

    Swift

    var actions: [NSObjectProtocol] { get }
  • A structure that represents an action history item.

    See more

    Declaration

    Swift

    public struct ActionHistoryItem

State Assessements

  • Recalculates the closest input and object.

    Declaration

    Swift

    func evaluateEnvironmentVariables(from state: AIAbstractGameState)
  • Returns a given decision tree that the agent will use to grab its next best move.

    Important

    This method must be overridden in all subclasses; otherwise, the decision tree may not be able to generate an answer, and the agent will use a fallback action.

    Declaration

    Swift

    func makeDecisionTree() -> GKDecisionTree

    Return Value

    A decision tree (GKDecisionTree)

  • Returns an active assessement of the given state.

    Declaration

    Swift

    func assess(state: AIAbstractGameState) -> AIAbstractGameState.Assessement

    Parameters

    state

    The state to assess.

  • Returns whether the agent is wearing the correct costume for the selected input.

    Declaration

    Swift

    func wearingCorrectCostume(for input: AIAbstractGameSignalSender?, in state: AIAbstractGameState) -> Bool

    Parameters

    input

    The input device to check for costume switching.

    state

    The state to assess for.

Best Move for Player

  • Returns the best move for the active player.

    The agent will attempt to create an assessement of the current state and receive a response from AITreeStrategy.makeDecisionTree. Any special processing after the response collection will be performed before returning the action back to the strategist.

    Note

    This function may be overridden in subclasses, if necessary.

    Precondition

    The AITreeStrategy.makeDecisionTree must be fully implemented.

    Declaration

    Swift

    override func bestMoveForActivePlayer() -> GKGameModelUpdate?

Action Processing

  • Returns a specified action if the action is a special keyword.

    Declaration

    Swift

    func process(_ action: String, from state: AIAbstractGameState) -> String

    Parameters

    action

    The action to process.

    state

    The current state the action derived from.

  • Returns the default action from the response tree.

    Declaration

    Swift

    func defaultAction() -> AIGameDecision
  • Returns a random move.

    Declaration

    Swift

    func moveRandom() -> String

    Return Value

    A random move from the movement set of actions.