public ScoringMove MTD(AIBoard board) { int gamma, guess = globalGuess; ScoringMove scoringMove = null; maximumExploredDepth = 0; string output = ""; for (byte i = 0; i < MAX_ITERATIONS; i++) { gamma = guess; scoringMove = Test(board, 0, gamma - 1); guess = scoringMove.score; if (guess == gamma) { globalGuess = guess; output += "guess encontrado en iteracion " + i; //MTDPathTest.text = output; return(scoringMove); } } output += "guess no encontrado"; globalGuess = guess; //MTDPathTest.text = output; return(scoringMove); }
// segun el movimiento - borra la ficha del rival, quita las 3 que hay hecho linea y suma un punto void MoverEspecial(ScoringMove scoringMove) { contadorO++; buttonList[scoringMove.move.takeficha].text = ""; buttonList[board.toDelete[0]].text = ""; buttonList[board.toDelete[1]].text = ""; buttonList[board.toDelete[2]].text = ""; }
ScoringMove NegamaxAB(Board board, byte depth, int alfa, int beta) { // Devuelve el score del tablero y la jugada con la que se llega a él. int[] bestMove = new int[2]; int bestScore = 0; int currentScore; ScoringMove scoringMove; // score, movimiento Board newBoard; // Comprobar si hemos terminado de hacer recursión if (board.IsEndOfGame() || depth == MAX_DEPTH) { if (depth % 2 == 0) { scoringMove = new ScoringMove(board.Evaluate(activePlayer), 0, 0); } else { scoringMove = new ScoringMove(-board.Evaluate(activePlayer), 0, 0); } } else { bestScore = MINUS_INFINITE; int[,] possibleMoves; possibleMoves = board.PossibleMoves(); //foreach (int move in possibleMoves) for (int move = 0; move < possibleMoves.GetLength(0); move++) { newBoard = board.GenerateNewBoardFromMove(possibleMoves[move, 0], possibleMoves[move, 1]); // Recursividad scoringMove = NegamaxAB(newBoard, (byte)(depth + 1), -beta, -Math.Max(alfa, bestScore)); int invertedScore = -scoringMove.score; // Actualizar mejor score if (invertedScore > bestScore) { bestScore = invertedScore; bestMove[0] = possibleMoves[move, 0]; bestMove[1] = possibleMoves[move, 1]; } if (bestScore >= beta) { scoringMove = new ScoringMove(bestScore, bestMove[0], bestMove[1]); return(scoringMove); } } scoringMove = new ScoringMove(bestScore, bestMove[0], bestMove[1]); } return(scoringMove); }
ScoringMove Minimax(Board board, string activePlayer, byte depth) { // Devuelve el score del tablero y la jugada con la que se llega a él. Move bestMove = null; int bestScore = 0; ScoringMove scoringMove; // score, movimiento Board newBoard; // Comprobar si hemos terminado de hacer recursión if (board.IsEndOfGame() || depth == MAX_DEPTH) { scoringMove = new ScoringMove(board.Evaluate(activePlayer), new Move(0, -1)); } else { if (board.activePlayer == activePlayer) { bestScore = MINUS_INFINITE; } else { bestScore = INFINITE; } Move[] possibleMoves; possibleMoves = board.PossibleMoves(); foreach (Move move in possibleMoves) { newBoard = board.GenerateNewBoardFromMove(move); // Recursividad scoringMove = Minimax(newBoard, activePlayer, (byte)(depth + 1)); // Actualizar mejor score if (board.activePlayer == activePlayer) { if (scoringMove.score > bestScore) { bestScore = scoringMove.score; bestMove = move; } } else { if (scoringMove.score < bestScore) { bestScore = scoringMove.score; bestMove = move; } } } scoringMove = new ScoringMove(bestScore, bestMove); } return(scoringMove); }
ScoringMove NegamaxAB(Board board, byte depth, int alfa, int beta) { // Devuelve el score del tablero y la jugada con la que se llega a él. Move bestMove = null; int bestScore = 0; ScoringMove scoringMove; // score, movimiento Board newBoard; // Comprobar si hemos terminado de hacer recursión if (board.IsEndOfGame() || depth == MAX_DEPTH) { if (depth % 2 == 0) { scoringMove = new ScoringMove(board.Evaluate(activePlayer), new Move(0, -1)); } else { scoringMove = new ScoringMove(-board.Evaluate(activePlayer), new Move(0, -1)); } } else { bestScore = MINUS_INFINITE; Move[] possibleMoves; possibleMoves = board.PossibleMoves(); foreach (Move move in possibleMoves) { newBoard = board.GenerateNewBoardFromMove(move); // Recursividad scoringMove = NegamaxAB(newBoard, (byte)(depth + 1), -beta, -Math.Max(alfa, bestScore)); int invertedScore = -scoringMove.score; // Actualizar mejor score if (invertedScore > bestScore) { bestScore = invertedScore; bestMove = move; } if (bestScore >= beta) { scoringMove = new ScoringMove(bestScore, bestMove); return(scoringMove); } } scoringMove = new ScoringMove(bestScore, bestMove); } return(scoringMove); }
ScoringMove Test(AIBoard board, byte depth, int gamma) { // Devuelve el score del tablero y la jugada con la que se llega a él. List <MoveMarble> bestMove = new List <MoveMarble>(); int bestScore = 0; ScoringMove scoringMove; // score, movimiento AIBoard newBoard; Record record; if (depth > maximumExploredDepth) { maximumExploredDepth = depth; } record = transpositionTable.GetRecord(board.hashValue); if (record != null) { if (record.depth > MAX_DEPTH - depth) { if (record.minScore > gamma) { scoringMove = new ScoringMove(record.minScore, record.bestMove); return(scoringMove); } if (record.maxScore < gamma) { scoringMove = new ScoringMove(record.maxScore, record.bestMove); return(scoringMove); } } } else { record = new Record(); record.hashValue = board.hashValue; record.depth = MAX_DEPTH - depth; record.minScore = MINUS_INFINITE; record.maxScore = INFINITE; } // Comprobar si hemos terminado de hacer recursión if (board.IsEndOfGame() || depth == MAX_DEPTH) { if (depth % 2 == 0) { record.maxScore = board.Evaluate(activePlayer); } else { record.maxScore = -board.Evaluate(activePlayer); } record.minScore = record.maxScore; transpositionTable.SaveRecord(record); scoringMove = new ScoringMove(record.maxScore); } else { bestScore = MINUS_INFINITE; //modificar AIBoard.possibleMoves() para que devuelva los posibles movimientos List <MoveMarble>[] possibleMoves; possibleMoves = board.PossibleMoves(); foreach (List <MoveMarble> move in possibleMoves) { //newBoard = board.GenerateNewBoardFromMove(move); newBoard = board.HashGenerateNewBoardFromMove(move);//cambiar // Recursividad scoringMove = Test(newBoard, (byte)(depth + 1), -gamma); int invertedScore = -scoringMove.score; // Actualizar mejor score if (invertedScore > bestScore) { bestScore = invertedScore; bestMove = move;//cambiar record.bestMove = move; } if (bestScore < gamma) { record.maxScore = bestScore; } else { record.minScore = bestScore; } } transpositionTable.SaveRecord(record); scoringMove = new ScoringMove(bestScore, bestMove); } return(scoringMove); }
private IEnumerator MakeMove(ScoringMove scoringMove) { yield return(StartCoroutine(movementHandler.ExecuteMovement(scoringMove.move))); GameManager.Instance.EndTurn(); }
void Move(ScoringMove scoringMove) { StartCoroutine(MakeMove(scoringMove)); }
// pone una ficha en una posicion segun el move dado void Move(ScoringMove scoringMove) { buttonList[scoringMove.move.putFicha].text = activePlayer; }
void Move(ScoringMove scoringMove) { gameController.FillColumn((byte)scoringMove.row, (byte)scoringMove.column); gameController.EndTurn(); }