UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

59 lines 1.64 kB
/** * Hill climbing optimizer based on testing random moves one move at a time, if overall fitness improves - that move is committed, otherwise it's rejected * Very dumb, but quite effective. Requires very little code to write a competent optimizer, especially when state space is relatively small * @template S * @class */ export class RandomOptimizer<S> { /** * * @type {S|null} */ state: S | null; /** * * @type {function(S):S} */ cloneState: (arg0: S) => S; /** * * @type {function(S):Function[]} */ computeValidActions: (arg0: S) => Function[]; /** * * @type {function(S):number} */ scoreFunction: (arg0: S) => number; /** * * @type {function(S,random:function():number)|null} */ randomAction: (arg0: S, arg1: random) => () => number; /** * * @type {function():number} */ random: () => number; /** * * @param {S} state * @param {function(S):Function[]} [computeValidActions] * @param {function(S):S} cloneState * @param {function(S):number} scoreFunction * @param {function(S,random:function():number)} [randomAction] */ initialize({ state, computeValidActions, cloneState, scoreFunction, randomAction }: S): void; /** * Perform a single optimization step * @returns {boolean} True if state was improved, false if no change has occurred */ step(): boolean; /** * * @param {number} tries * @returns {boolean} */ stepThrough(tries: number): boolean; } //# sourceMappingURL=RandomOptimizer.d.ts.map