Class Minimax<GS, M, D>

Class for performing a minimax search.

Probability based searches coming soon

Usage

See the Negamax documentation for general usage, its is very similar.

The differences are as follows:

Type Parameters

  • GS

    The object representing the state of the game

  • M

    The object representing a move in the game

  • D

    Extra data used in evaluation not suitable for storing in the gamestate

Hierarchy

  • SearchTree<GS, M, D>
    • Minimax

Constructors

  • Type Parameters

    • GS

    • M

    • D

    Parameters

    • root: Node<GS, M, D>

      Root node to start the tree from

    • opts: MinimaxOpts = ...

      Optional options to configure the minimax algorithm

    Returns Minimax<GS, M, D>

Methods

  • Implements the minimax algorithm up to a given depth of search. Recursively calls itself until depth is 0 or LEAF node is reached and evaluated.

    Node values and best child are chosen according to the NodeAim of the parent nodes.

    Returns early if timeout occurs

    Returns

    Reason for returning.

    Parameters

    • node: Node<GS, M, D>

      Node to evaluate or search children

    • depth: number

      Depth to search from this node

    • alpha: number

      minimum guaranteed score

    • beta: number

      maximum guaranteed score from minimising player

    Returns SearchExit

  • Goes through all of nodes children to find child with minimum inherited value

    Parameters

    • node: Node<GS, M, D>
    • depth: number

    Returns {
        exit: SearchExit;
        best: undefined | Node<GS, M, D>;
    }

  • Goes through all of nodes children to find child with minimum inherited value

    Parameters

    • node: Node<GS, M, D>
    • depth: number

    Returns {
        exit: SearchExit;
        best: undefined | Node<GS, M, D>;
    }

  • Find the best child of a node using alpha beta pruning

    Returns

    Reason for exit and opional best child

    Parameters

    • node: Node<GS, M, D>

      Node to find best child of

    • depth: number

      Depth to limit search to

    • alpha: number

      Current alpha value

    • beta: number

      current beta value

    Returns {
        exit: SearchExit;
        best: undefined | Node<GS, M, D>;
    }

  • Search the tree according to the options specified by the options (opts).

    Returns

    Result from the tree search

    Returns SearchResult<M>

  • Called during deepening search between each depth. Does nothing until overidden

    Parameters

    Returns void

  • Checks if expiry is enable and has happened

    Returns

    true if time has expired, otherwise false

    Returns boolean

  • Checks if node limit is enabled and returns true if it has been exceeded, otherwise returns false.

    Returns boolean

  • Returns either the array of node children or a generator which may create children on the fly Also presorts children if enabled

    Returns

    An iterable for going through children of node

    Parameters

    • node: Node<GS, M, D>

      Node to return an iterable of children

    Returns Iterable<Node<GS, M, D>>

  • Sorts the child nodes of given parent Node according to inherited value. Sort is descending by default

    Sorts using the method specififed in opts.SearchOpts.SortMethod.

    Returns

    The child with the highest value

    Parameters

    • node: Node<GS, M, D>

      parent Node of children to sort

    • Optional reverse: boolean

      Optionally sort ascending instead

    Returns Node<GS, M, D>

  • Selects from the nodes children which all have an equal best value (and depth) Uniform random weighting Node.child must already represent best child

    Returns

    randomly selected best child with same value as best

    Parameters

    • node: Node<GS, M, D>

      Parent to select best child from

    Returns Node<GS, M, D>

  • Selects best child from nodes children according to the weighting factor

    Parameters

    • node: Node<GS, M, D>
    • weight: number

    Returns Node<GS, M, D>

  • Generator that yields all the nodes along the optimal path, starting from and including node

    Parameters

    • node: Node<GS, M, D>

    Returns Generator<Node<GS, M, D>, any, unknown>

  • Generator that yields all the moves along the optimal path

    Parameters

    • node: Node<GS, M, D>

    Returns Generator<M, any, unknown>

  • Function to return the list of moves starting from the root that are the 'optimal' path.

    Must be called after evaluating the tree.

    Returns

    A list of moves from the active root Node that represent the optimal sequence through the game.

    Returns M[]

  • Recursively go through node and its children removing all nodes that are not best

    Parameters

    • node: Node<GS, M, D>
    • depth: number
    • keep: boolean

    Returns number

  • Generates all children of given node. Does nothing if branches and children already present

    Returns

    true if nodes created, false if already existed

    Parameters

    • node: Node<GS, M, D>

      Node to create children for

    Returns boolean

  • Creates the full game tree recursively starting from given node

    Parameters

    • node: Node<GS, M, D>

      Parent node

    Returns void

  • Generate all the children of node, starting from those already created

    Parameters

    • node: Node<GS, M, D>

      Node to create children for

    Returns Generator<Node<GS, M, D>, any, unknown>

Properties

expired: boolean = false

Tracks whether a searched has expired due to time

expireTime: number = 0

Time the search will expire. 0 disables expiry

fullDepth: boolean = true

Flags that full depth has not been reached when set to false

presortEnable: boolean = false

Enables presort of children internally

outcomes: number = 0

Number of leaf or depth = 0 reached during current call

nodeLimitExceeded: boolean = false

Flag set if node limit has been reached

opts: SearchOpts = ...
EvaluateNode: EvaluateNodeFunc<GS, M, D> = ...

Callback to evaluate the value of gamestate attached to node

root: Node<GS, M, D>

Original root when tree was created

activeRoot: Node<GS, M, D>

Active root used for the creation and searching of tree. Set to root in constructor.

nodeCount: number = 0

Number of nodes in tree

leafCount: number = 0

Number of leaf nodes in tree

activeDepth: number = 0

Maximum depth of current search

GetMoves: GetMovesFunc<GS, M, D> = ...

Callback to get the moves for a gamestate attached to a Node.

CreateChildNode: CreateChildNodeFunc<GS, M, D> = ...

Callback to create a child of a parent node using a move

Generated using TypeDoc