Class NegamaxOpts

Options to configure the behaviour of the negamax search.

opts property of Negamax.

Recommended usage

Set the optimal flag to true for fast searching, effective pruning and reduced memory usage. Then use the method property along with the corresponding depth or timeout properties accordingly.

Advanced usage

Search tuning

Set the optimal flag to false and try different combinations of pruning, presort, sortMethod and genBased to achieve the desired performance.

Initial Depth

Setting initialDepth > 1 could potentially speed up searches.

Prune by path length

The pruneByPathLength flag enables fast wins and slow losses. When choosing between 2 nodes with the same value, if the value is positive, it will favour one that is fewer moves away (or is a leaf node). If the value is negative, the one that is more moves away. The opposite holds if the parent is a minimising node.

Does not work with optimal set to true.

Node removal

The removalMethod option allows for trimming nodes that aren't needed from the game tree in between successive searches in DEEPENING and TIME modes. This can greatly reduce memory usage and allow for far deeper searches, but with more computation required.

There are 3 options:

Random selections

These options can be useful for making the AI less 'robotic'. Neither of them work with pruneByPathLength or optimal set to true. The randomWeight option does not work with pruning set to ALPHA_BETA. They will run but likely give incorrect results.

The randomBest option will randomly select from the child nodes that all have the best value.

The randomWeight option selects from all the children, but is weighted towards the best valued. The weighting effect is outlined in the property documentation.

Hierarchy

Constructors

Properties

optimal: boolean = false

Set to true to override other options and run an optimised negamax function.

Overrides:

Invalidates:

See

Optimal function in blog post.

method: SearchMethod = SearchMethod.DEPTH

Method used to search for best move. See SearchMethod for details

timeout: number = 0

Timeout used when method is TIME. Timeout disabled when set to 0.

depth: number = 0

Default search depth for depth and deepening searches.

pruning: PruningType = PruningType.NONE

Node pruning type, default none

See

Alpha-beta pruning in blog post.

initialDepth: number = 1

Depth to start from for deepening and time based. Bypassing early depths may improve performance.

genBased: boolean = false

Use the child generator instead of creating all children for each node. Should be faster and use less memory.

See

Generators in blog post.

presort: boolean = false

Sort children of node before searching deeper.

See

Presort in blog post

sortMethod: SortMethod = SortMethod.DEFAULT

Method used to sort nodes if presort is enabled

nodeLimit: number = 0

Maximum number of nodes allowed in the tree. Search will finish if exceeded, returning 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)

pruneByPathLength: boolean = false

Set to true to shorten winning paths and lengthen losing paths. Only works when combined with PruningType.ALPHA_BETA. Is disabled for Negamax when optimal is true.

Check Negamax, Minimax or Maxn (and corresponing Opts) for specific support.

randomBest: boolean = false

Select randomly from all of the children with the best value.

Check Negamax, Minimax or Maxn (and corresponing Opts) for specific support.

randomWeight: number = 0

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 Negamax, Minimax or Maxn (and corresponing Opts) for specific support.

removalMethod: RemovalMethod = RemovalMethod.NONE

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.

removalDepth: number = 0

Controls the way removal behaves for DEPTH

removalCount: number = 0

Controls the way removal behaves for COUNT

Generated using TypeDoc