src/players/AlphaBetaPlayer.js
/** The `minimax(game, player, depth, alfa, beta)` 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, the heuristic is
	used.
	*/
The `minimax(game, player, depth, alfa, beta)` 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, the heuristic is
used.
The ` minimax ( game player depth alfa beta ) ` 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 the heuristic is used .
function minimax(game, player, depth, alpha, beta) {
		if (game.isContingent) {
			return this.expectiMinimax(game, player, depth, alpha, beta);
		}
		var value = this.quiescence(game, player, depth);
		if (!isNaN(value)) {
			return value;
		}
		var activePlayer = game.activePlayer(),
			isActive = activePlayer == player,
			moves = this.movesFor(game, activePlayer), next;
		if (moves.length < 1) {
			raise("No moves for unfinished game "+ game +"!");
		}
		for (var i = 0; i < moves.length; i++) {
			next = game.next(obj(activePlayer, moves[i]));
			value = this.minimax(next, player, depth + 1, alpha, beta);
			if (isActive) {
				if (alpha < value) { 
					alpha = value;
				}
			} else {
				if (beta > value) { 
					beta = value;
				}
			}
			if (beta <= alpha) {
				break;
			}
		}
		return isActive ? alpha : beta;
	}
function minimax ( game , player , depth , alpha , beta ) { if ( game . isContingent ) { return this . expectiMinimax ( game , player , depth , alpha , beta ) ; } var value = this . quiescence ( game , player , depth ) ; if ( ! isNaN ( value ) ) { return value ; } var activePlayer = game . activePlayer ( ) , isActive = activePlayer == player , moves = this . movesFor ( game , activePlayer ) , next ; if ( moves . length < 1 ) { raise ( "No moves for unfinished game " + game + "!" ) ; } for ( var i = 0 ; i < moves . length ; i ++ ) { next = game . next ( obj ( activePlayer , moves [ i ] ) ) ; value = this . minimax ( next , player , depth + 1 , alpha , beta ) ; if ( isActive ) { if ( alpha < value ) { alpha = value ; } } else { if ( beta > value ) { beta = value ; } } if ( beta <= alpha ) { break ; } } return isActive ? alpha : beta ; }
The `minimax(game, player, depth, alfa, beta)` method calculates the
Minimax evaluation of the given game for the given player.
The ` minimax ( game player depth alfa beta ) ` method calculates the Minimax evaluation of the given game for the given player .
// MAX // MIN