// Main game loop handling turns private IEnumerator GameLoop() { // Run game loop while the game isn't over (won/lost) or tied while (!aiManager.GameOver && !aiManager.GameTied) { turn = GameTurn.Player; List <Point> PiecesToConvert_Player = new List <Point>(); aiManager.GenerateAvailableMoves(); // if (aiManager.PossibleToMove) { WhiteCantMove = false; while (playerMove == null) { yield return(null); } // Clears the debug log // ClearLog(); Debug.Log("Player's turn."); if (aiManager.AvailableMove(playerMove, ref PiecesToConvert_Player)) { Debug.Log("Converting pieces from " + playerMove.X + "," + playerMove.Y); yield return(StartCoroutine(ConvertPieces(PiecesToConvert_Player))); } else { StartCoroutine(uiManager.ShowMessage("Invalid move.", 1)); playerMove = null; continue; } } else { Debug.Log("No possible player moves."); StartCoroutine(uiManager.ShowMessage("Player is unable to move.", 1)); WhiteCantMove = true; } // Wait 0.5 seconds before computer moves for a more natural feel yield return(new WaitForSeconds(0.5f)); // Check whether game over before computer turn aiManager.CheckGameOver(); if (!aiManager.GameOver) { Debug.Log("Computer's turn."); List <Point> PiecesToConvert_Computer = new List <Point>(); turn = GameTurn.Computer; aiManager.GenerateAvailableMoves(); // If the computer can move, make the best possible move if (aiManager.PossibleToMove) { BlackCantMove = false; PiecesToConvert_Computer = aiManager.ComputerMove(); Debug.Log("Converting pieces from " + PiecesToConvert_Computer[0].X + "," + PiecesToConvert_Computer[0].Y); yield return(StartCoroutine(ConvertPieces(PiecesToConvert_Computer))); } else { Debug.Log("No possible computer moves."); StartCoroutine(uiManager.ShowMessage("Computer is unable to move.", 1)); BlackCantMove = true; } } // Check whether game over before player turn aiManager.CheckGameOver(); playerMove = null; } }