/// <summary> /// public wrapper for recursion /// try each possible move, find the one with the best score /// </summary> /// <param name="lookahead">how far to look ahead</param> /// <param name="playerX">is this for player x</param> /// <returns>The data on the best move location and score</returns> public MinimaxResult DoMinimax(int lookahead, bool playerX) { // set up inital state DateTime startTime = DateTime.Now; if (lookahead < 1) { throw new Exception("Invalid lookahead of " + lookahead); } this.debugDataItems.Clear(); Occupied player = playerX.ToPlayer(); int alpha = MoveScoreConverter.ConvertWin(player.Opponent(), 0); int beta = MoveScoreConverter.ConvertWin(player, 0); MinimaxResult bestMove = this.ScoreBoard(lookahead, this.ActualBoard, playerX, alpha, beta); if (bestMove.Move != Location.Null) { GoodMoves.AddGoodMove(0, bestMove.Move); } DateTime endTime = DateTime.Now; this.MoveTime = endTime - startTime; return(bestMove); }
public MinimaxResult DoMinimax(int depth, bool isComputer) { // megmondja, hogy ki a jatekos, ha a gep, akkor az isComputerben true van, es akkor a plyaerben xPlayer lesz. Occupied player = isComputer.ToPlayer(); // a gep az alpha this.alpha = MoveScoreConverter.ConvertWin(player.Opponent(), 0); // ember a beta this.beta = MoveScoreConverter.ConvertWin(player, 0); // a minimax algoritmus magaban MinimaxResult bestMove = this.MiniMaxAlg(depth, isComputer, board); if (bestMove.Move != Location.Null) { // killer heurisztika GoodMoves.AddGoodMove(0, bestMove.Move); } return(bestMove); }