IEnumerator PlayerTurn() { playerColorChanged.Invoke(board.CurrentPlayer); yield return(new WaitForSeconds(delayBetweenTurns)); currentState = GameState.PlayerTurn; ShowSelection(true); yield return(new WaitUntil(() => playerMoved)); currentState = GameState.Processing; playerMoved = false; ShowSelection(false); debugOutput.AddText((movesMade + 1) + ". Player " + (board.CurrentPlayer + 1) + " in column " + (playerMovedSelection + 1)); board.MakeMove(playerMovedSelection); inputManager.selectionActivated.Invoke(playerMovedSelection, movesMade & 1); if (board.HasConnectedFour(movesMade & 1)) { currentState = GameState.Ending; gameResult = GameResult.WinLoss; } else if (board.MovesMade >= 42) { currentState = GameState.Ending; gameResult = GameResult.Tie; } movesMade++; if (currentState == GameState.Ending) { currentState = GameState.End; yield return(new WaitForSeconds(delayBetweenTurns)); GameOver(); } else { Engine nextMover = movesMade % 2 == 0 ? moverOne : moverTwo; if (nextMover == null) { StartCoroutine(PlayerTurn()); } else { StartCoroutine(ComputerTurn(nextMover)); } } }