> For the complete documentation index, see [llms.txt](https://freedom-developer.gitbook.io/the-chess/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://freedom-developer.gitbook.io/the-chess/customization/time-ai.md).

# Time AI

## Add Coroutine To AI

The default behaviour of AI is execute immediately when it's on their turn. However, a delay, before they starts their calculation can be done through steps below.

**Steps 1 - Remove unnecessary code**

In ChessGameAIGUI script, there are numerous line of code contains preprocessor directive `#if (UNITY_WEBGL && !UNITY_EDITOR)`, uncomment or remove them entirely. Do the same for the **content** inside the `#else` statement, if there's any. In the end, what remains will be those code within the if statement.&#x20;

\*EXCEPT those preprocessor directive in `RequestAIMove()` function, just don't do this step in the function, otherwise, screen will freeze while AI is calculating.

**Steps 2 - Migrate code to next steps**

In the `RequestAIMove()` function,  remove the line `AITurnEffect(isAIMoving);`&#x20;

**Steps 3 - Making the request to AI move function a timed coroutine**

In the IEnumerator `AITurn()` function, the code within should become something like

```
        //Letting AI turn effect starts spinning before AI starts it's calculation
        AITurnEffect(!HasGameFinished());

        //The seconds should be the time to delay AI before it starts calculation
        yield return new WaitForSeconds(seconds); 

        RequestAIMove();
```
