// Somewhat naive approach to implement a Tic Tac Toe A.I. // I honestly don't know much about the strategy involved in the game, but i'm assuming // the steps described below make sense and work as a base for a somewhat decent A.I. that can play this sort of games public Vector2Int MakeMove(Board gameplayBoard, TurnTracker turnTracker, GameplayBotDifficulty difficulty = GameplayBotDifficulty.EASY) { // Get available spaces var boardFreePositions = gameplayBoard.GetAvailableLocations(); // if the game is set to easy difficulty if (difficulty == GameplayBotDifficulty.EASY) { // Just pick something at random return(boardFreePositions[Mathf.FloorToInt(Random.Range(0, boardFreePositions.Count))]); } // Else make a move using a better strategy // Get the play pieces for each player GameplayPieceTypes ownedPieces = turnTracker.GetCurrentTurnPieceType(); GameplayPieceTypes rivalPieces = turnTracker.GetRivalTurnPieceType(); //if first move, or the center has not been taken, take center (assuming this is the best possible position to take, as this is the case in most board games) var bestMove = new Vector2Int(1, 1); if (difficulty == GameplayBotDifficulty.MEDIUM) { if (boardFreePositions.Contains((bestMove))) { // Just pick something at random return(boardFreePositions[Mathf.FloorToInt(Random.Range(0, boardFreePositions.Count))]); } var scoresMedium = this.AlphaBetaMax(gameplayBoard, 0, Mathf.Infinity, -Mathf.Infinity, ownedPieces); // return bestMove; return(new Vector2Int(scoresMedium[0], scoresMedium[1])); } //if first move, or the center has not been taken, take center (assuming this is the best possible position to take, as this is the case in most board games) if (boardFreePositions.Contains((bestMove))) { return(bestMove); } // higher depth means, even further analisis of deeper brancher of the possible plays var scoresHard = this.AlphaBetaMax(gameplayBoard, 3, Mathf.Infinity, -Mathf.Infinity, ownedPieces); // return bestMove; return(new Vector2Int(scoresHard[0], scoresHard[1])); }
private void initializeTurnTracker() { TurnTracker = new TurnTracker((List <BaseUnit>)Allies.Concat(Enemies)); }
void Start() { turnTracker = FindObjectOfType <TurnTracker>(); sliceAnimator = FindObjectOfType <SliceAnimator>(); audioSource = GetComponent <AudioSource>(); }
public void pTwoSelectButton() { playerTurn = TurnTracker.playerTwo; }
public void pThreeSelectButton() { playerTurn = TurnTracker.playerThree; }
//Changes the player who is selecting their character public void pOneSelectButton() { playerTurn = TurnTracker.playerOne; }
public void pFourSelectButton() { playerTurn = TurnTracker.playerFour; }