The Coolest Chess
  • The Chess Documentation
    • Chess Game Introduction
    • Essential Prefabs
    • Components
  • Importing Stockfish AI
  • Controller
    • Base Controller
    • Two Player Controller
  • The UIs
    • Button Prefabs
    • UI Events
    • Enquiry
    • Replacing UI
    • Others
  • Scenes Details
    • ChessPGN
    • ChessPuzzleEditor
    • ChessPuzzle
    • ChessAI
  • Honorable Mentioned
    • ChessBoard class
    • GUI Classes
    • Game Logic Classes
    • The Architecture Notice
  • Customization
    • Time AI
    • AI Draw Game
    • TypeI AI
    • TypeII AI
    • Event Based Functions
    • Chess Game Finishing Rule
  • Unit Tests
Powered by GitBook
On this page
  1. Customization

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 macro #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.

*EXCEPT those macro 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);

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();

PreviousCustomizationNextAI Draw Game

Last updated 3 months ago