/** * Enum and class definitions associated with searching the game tree */ import { SortMethod } from "./sorting.js"; /** * Search method to use when traversing the game tree. * * Located in an instance of {@link SearchOpts} at {@link SearchOpts.method | SearchOpts.method}. */ export declare const enum SearchMethod { /** Go to depth specified by * {@link SearchOpts.depth | SearchOpts.depth}. */ DEPTH = 0, /** * Search iteratively deeper starting from {@link SearchOpts.initialDepth | SearchOpts.initialDepth} * up to {@link SearchOpts.depth | SearchOpts.depth}. */ DEEPENING = 1, /** * Same as {@link SearchMethod.DEEPENING} but stops after the time * in {@link SearchOpts.timeout | SearchOpts.timeout} has elapsed. * * If {@link SearchOpts.depth | SearchOpts.depth} is non-zero, performs a time * and depth limited search. * * If {@link SearchOpts.timeout | SearchOpts.timeout} * and {@link SearchOpts.depth | SearchOpts.depth} * are 0, performs a full depth search. */ TIME = 2 } /** Pruning types. Located in an instance of {@link SearchOpts} at {@link SearchOpts.pruning | SearchOpts.pruning}.*/ export declare const enum PruningType { /** Do not prune any nodes */ NONE = 0, /** Prune using alpha-beta */ ALPHA_BETA = 1 } /** * Control the removal of nodes in between iterative searches when using * {@link SearchMethod.DEEPENING} or {@link SearchMethod.TIME}. * */ export declare const enum RemovalMethod { /** Disable node removal */ NONE = 0, /** Run node removal at the end of each depth search */ ALWAYS = 1, /** Run node removal above a certain depth ({@link SearchOpts.removalDepth}) */ DEPTH = 2, /** Run node removal when the node count exceeds a certain value ({@link SearchOpts.removalCount}) */ COUNT = 3 } /** * Class representing common options for searching a {@link Tree}. * * Derived classes are used and attached to their corresponding tree. */ export declare class SearchOpts { /** Method used to search for best move. See {@link SearchMethod} for details*/ method: SearchMethod; /** Timeout used when method is {@link SearchMethod.TIME}. Timeout disabled when set to 0.*/ timeout: number; /** Default search depth for depth and deepening searches.*/ depth: number; /** Node pruning type, default none * @see [Alpha-beta pruning in blog post](https://domwil.co.uk/minimaxer/part2/#alpha-beta-pruning). */ pruning: PruningType; /** * Depth to start from for deepening and time based. * Bypassing early depths *may* improve performance. */ initialDepth: number; /** * Use the child generator instead of creating all children for each node. * Should be faster and use less memory. * * @see [Generators in blog post](https://domwil.co.uk/minimaxer/part4/#the-node-generator). */ genBased: boolean; /** Sort children of node before searching deeper. * @see [Presort in blog post](https://domwil.co.uk/minimaxer/part2/#pre-sorting) */ presort: boolean; /** Method used to sort nodes if {@link SearchOpts.presort} is enabled */ sortMethod: SortMethod; /** * @alpha * Maximum number of nodes allowed in the tree. Search will finish if exceeded, * returning {@link SearchExit.NODE_LIMIT}. * * Actual nodes in tree will be between nodeLimit and nodeLimit + x where x, * is the number of moves/children being checked when the nodeLimit is exceeded. * * Disabled by setting to 0 * * Only works with Negamax (optimal = false) */ nodeLimit: number; /** Set to `true` to shorten winning paths and lengthen losing paths. * Only works when combined with {@link PruningType.ALPHA_BETA | PruningType.ALPHA_BETA}. * Is disabled for {@link Negamax} when {@link NegamaxOpts.optimal} is `true`. * * Check {@link Negamax}, {@link Minimax} or {@link Maxn} (and corresponing Opts) for * specific support. */ pruneByPathLength: boolean; /** * @experimental * Select randomly from all of the children with the best value. * * Check {@link Negamax}, {@link Minimax} or {@link Maxn} (and corresponing Opts) for * specific support. */ randomBest: boolean; /** * @experimental * Select randomly, weighted in favour of better values * Weighting is determined by config value. * - randomWeight = 0, disabled * - randomWeight = 1, equal probabilty * - randomWeight = 5, 5 times more likely for every +1 valuation * * Check {@link Negamax}, {@link Minimax} or {@link Maxn} (and corresponing Opts) for * specific support. */ randomWeight: number; /** * For removing nodes in between iterative searches. * Allows for deeper searches that would otherwise be memory limited. * * Good for reduced memory usage but takes extra time. */ removalMethod: RemovalMethod; /** * Controls the way removal behaves for {@link RemovalMethod.DEPTH} */ removalDepth: number; /** * Controls the way removal behaves for {@link RemovalMethod.COUNT} */ removalCount: number; } /** * Represents the reason for terminating the search. * * Property of {@link SearchResult}. */ export declare const enum SearchExit { /** * At least 1 path did not reach a leaf node, and the depth set by * {@link SearchOpts.depth | SearchOpts.depth} was reached. */ DEPTH = 0, /** All paths reached leaf nodes */ FULL_DEPTH = 1, /** Searched concluded because of timeout set in * {@link SearchOpts.timeout | SearchOpts.timeout}. */ TIME = 2, /** * Search concluded as the node limit was reached */ NODE_LIMIT = 3 } /** Object that is returned after a search has been completed */ export declare class SearchResult { exit: SearchExit; move: M; value: number; depth: number; outcomes: number; nodes: number; pathLength: number; /** * @param exit Reason the search has stopped and result returned. * @param move The best move from the {@link Tree.activeRoot}. * @param value Value of {@link Tree.activeRoot} according to search. * @param depth Depth reached and fully searched. * @param outcomes Number of nodes at bottom of tree (not neccessarily leaves). * @param nodes Number of nodes in full tree. * @param pathLength Minimum number of moves until a leaf node. */ constructor(exit: SearchExit, move: M, value: number, depth: number, outcomes: number, nodes: number, pathLength: number); }