src/players/MiniMaxPlayer.js
/** The `minimax(game, player, depth, options)` method calculates the Minimax evaluation of the 
	given game for the given player. If the game is not finished and the depth is greater than the 
	horizon, `heuristic` is used.
	
	The `options` optional argument may include:

	+ `hook`: A callback function to be called in every node with the game state and its value. A
	result other than NaN overrides the minimax evaluation.
	*/
The `minimax(game, player, depth, options)` method calculates the Minimax evaluation of the
given game for the given player. If the game is not finished and the depth is greater than the
horizon, `heuristic` is used.

The `options` optional argument may include.

+ `hook`: A callback function to be called in every node with the game state and its value. A
result other than NaN overrides the minimax evaluation.
The ` minimax ( game player depth options ) ` method calculates the Minimax evaluation of the given game for the given player . If the game is not finished and the depth is greater than the horizon ` heuristic ` is used . The ` options ` optional argument may include . + ` hook ` : A callback function to be called in every node with the game state and its value . A result other than NaN overrides the minimax evaluation .
function minimax(game, player, depth, options) {
		if (game.isContingent) {
			return this.expectiMinimax(game, player, depth, options);
		}
		var value = this.quiescence(game, player, depth);
		if (isNaN(value)) { 
			var activePlayer = game.activePlayer(),
				moves = this.movesFor(game, activePlayer), 
				comparison, next;
			if (moves.length < 1) {
				throw new Error('No moves for unfinished game '+ game +'.');
			}
			if (activePlayer == player) {
				value = -Infinity;
				comparison = Math.max;
			} else {
				value = +Infinity;
				comparison = Math.min;
			}
			for (var i = 0; i < moves.length; ++i) {
				next = game.next(obj(activePlayer, moves[i]));
				value = comparison(value, this.minimax(next, player, depth + 1, options));
			}
		}
		if (options && typeof options.hook === 'function') {
			var hookValue = options.hook(game, value);
			if (!isNaN(hookValue)) {
				value = hookValue;
			}
		}
		return value;
	}
function minimax ( game , player , depth , options ) { if ( game . isContingent ) { return this . expectiMinimax ( game , player , depth , options ) ; } var value = this . quiescence ( game , player , depth ) ; if ( isNaN ( value ) ) { var activePlayer = game . activePlayer ( ) , moves = this . movesFor ( game , activePlayer ) , comparison , next ; if ( moves . length < 1 ) { throw new Error ( 'No moves for unfinished game ' + game + '.' ) ; } if ( activePlayer == player ) { value = - Infinity ; comparison = Math . max ; } else { value = + Infinity ; comparison = Math . min ; } for ( var i = 0 ; i < moves . length ; ++ i ) { next = game . next ( obj ( activePlayer , moves [ i ] ) ) ; value = comparison ( value , this . minimax ( next , player , depth + 1 , options ) ) ; } } if ( options && typeof options . hook === 'function' ) { var hookValue = options . hook ( game , value ) ; if ( ! isNaN ( hookValue ) ) { value = hookValue ; } } return value ; }
The `minimax(game, player, depth, options)` method calculates the Minimax evaluation of the
given game for the given player.
The ` minimax ( game player depth options ) ` method calculates the Minimax evaluation of the given game for the given player .
// game is not quiescent.