I have a project to build a Tic Tac Toe agent that uses minimax to always either win or tie a game. A requirement is that we make a recursive function that can calculate the "cost" of going down each respective path. I'm a little lost on minimax and how it works.
My professor has already defined the two functions we're allowed to use so I can't be flexible with the parameters, return types, or building another function. My question is: how can I get calcScoreForMove to be recursive and find the "cost" of each path? Every solution I've seen online so far has had some concept of "depth" so that it's a simple depth+1, but as said before, I can't change any parameters.
Below is what I have so far:
public class SearchBasedAgent implements TicTacToeSearchPlayer{
public Pair<Integer, Integer> chooseSquare(TicTacToeBoard curBoard, char yourSymbol){ List<Pair<Integer, Integer>> openMovesList= new ArrayList<>(); //get all possible moves openMovesList = curBoard.findAllOpenSquares(); double bestScore = -1; Pair<Integer, Integer> bestMove; //move thru the list of possible moves to find best move for (int i = 0; i < openMovesList.length(); i++) { double currentMove = calcScoreForMove(curBoard, curSymbolToMove, i, yourSymbol); if(currentMove > bestScore){ bestScore = currentMove; bestMove = i; } } return bestMove; } public double calcScoreForMove(TicTacToeBoard curBoard, char curSymbolToMove, Pair<Integer, Integer> move, char yourSymbol){ if(curSymbolToMove == yourSymbol){ //calcScoreForMove(curBoard, curSymbolToMove, ?????, yourSymbol); } else{ //??????? } return moveTotal; } }
https://stackoverflow.com/questions/66620014/how-to-build-an-unbeatable-tic-tac-toe-agent-using-minimax March 14, 2021 at 08:48AM
没有评论:
发表评论