---
description: This page shows what can be and how to customize for TypeI AI.
---

# TypeI AI

## **TypeI AI Behaviour**

On ChessAITypeIMechanism class, there are min max value that can be modified for a different AI behaviour. Min will increase the importance of the valuation of a function against others. Max will amplify the priority the function being taken into account first. For example, lowering the max value of ChessAIBoardRaterPawnProgression from 10.0 to 5.0 may reduce the chance AI rush their pawn to opponent side during early game. The change of AI behaviour from changing min value might not as obvious as of changing max value. &#x20;

<figure><img src="https://2079102914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA7OKfIba5xvQF1lhv60z%2Fuploads%2F7lJl1pCohdmY47wIG4Ir%2Fdevenv_3LbSQNHK13.png?alt=media&#x26;token=7cddb3c0-7592-4179-af75-2e6c14913cd8" alt=""><figcaption></figcaption></figure>

**ChessAIBoardRaterCenterOwnership** - Evaluate pieces that are getting closer to the center square D4,D5,E4,E5, this will make pieces wanting to get closer to the center tile.

**ChessAIBoardRaterMobilityDominance** - Evaluate The mobility of all pieces on the board for the chess board position, get and evaluate scores for each move of each piece available. This will make AI pick pieces that can move the most tile.

**BoardRaterCenterMobilityDominance** - Evaluate pieces that are getting closer to the center square D4,D5,E4,E5 while considering their movability. Like ChessAIBoardRaterCenterOwnership, but will consider the number of tiles needed for pieces to reach the center tile.

**ChessAIBoardRaterPawnProgression** - Evaluate pawn progression toward being promoted, this will encourage pawn to walk into promotion tile, but also make pawn more aggressive toward their progression.

**ChessAIBoardRaterKingSurroundingPossession** - Evaluate the attackable piece by the king surrounding the king and alliance piece of the king surrounding it. This will discourage king moving to tile that has potential threat while favoring move that keep it further away from opponent pieces and also getting closer to pieces that can protect it.

**ChessAIBoardRaterCenterFourOccupation** - Evaluate pieces that dominate the center square D4,D5,E4,E5, this will make pieces wanting to stay at the center tile.

**ChessAIBoardRaterCountPieces** - Evaluate the number of pieces on the board, by taking into account pieces valuation, like queen will have the highest valuation since it's the most useful piece. This will discourage AI throwing away their more important pieces.&#x20;

**ChessAIBoardRaterOpponentCheckMateOpportunity** - Evaluate the tendency of checkmaking by opponent. This will straight away avoiding being checkmate.

**ChessAIBoardRaterThreatenedPieces** - Evaluate the tendency to protect own pieces & piece trade valuation. This will evaluate if trading pieces worthwhile.

**ChessAIBoardRaterCastle** - Evaluate castle move. This will force making castle move if there's one.

**ChessAIBoardRaterEndGameForceCheckKing** - Evaluate a checking move. This will encourage moves that can check king, only when during endgame, when pieces count for AI is less than 7.

**ChessAIBoardRaterShouldFinishGame** - Evaluate the tendency to finish a game. This will prioritize move that can checkmate opponent.

**ChessAIBoardRaterStickToOpponentKing** - Make king get closer to opponent king, for easier checkmate when pieces count on the board are getting lower.

Tips - It is also possible to add a new evaluating function by extending `ChessAIBoardRater` class, like all others evaluating functions from above did.



There is also a multiplier value in this class that can be changed to reflect the overall change to the strength of TypeI AI.&#x20;

<figure><img src="https://2079102914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA7OKfIba5xvQF1lhv60z%2Fuploads%2F8FOW7EkVOR3IaOuAANHD%2Fdevenv_PiAMF8dLZN.png?alt=media&#x26;token=efa91b27-7276-4ca4-87e6-b02f00a37a5a" alt=""><figcaption></figcaption></figure>





## Adding new difficulty

Adding a new difficulty to TypeI AI has to be done manually in this ChessAITypeIMechanism class, first by adding a new enum value to Difficulty enum, in this case Eleven = 11.

<figure><img src="https://2079102914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA7OKfIba5xvQF1lhv60z%2Fuploads%2FnaNtiPHCEK4wU9G6Rpq1%2Fdevenv_GNStTmOfHQ.png?alt=media&#x26;token=798de068-129e-4b93-8bb3-ca656be4443f" alt=""><figcaption></figcaption></figure>

Subsequently, add a new case to DrawToleranceLevel getter, like the code below

```
case Difficulty.Eleven:
    return DrawToleranceLevel.Two;
```

Also, on the multiplier getter, a new case is also needed for the overall strength for the new AI. The value 2.5 is an example only.&#x20;

<pre><code>case Difficulty.Eleven:
<strong>    return 2.5; //elo ??? 
</strong></code></pre>

In the LoadScriptableObjects function, add the following new case. A new scriptable object named Difficulty11 needed for when AI reject draw comment.&#x20;

```
case Difficulty.Eleven:
    {
        drawCommentSO = Resources.Load<ChessAIDrawCommentSO>(resourceFilePath + "Difficulty11");
    }
    break;
```

Go to path Resources/ScriptableObjects/ChessAI/DrawComments and create a new ChessAIDrawCommentSO scriptable object and named it Difficulty11 because the string from above code is refering to Difficulty11.

<figure><img src="https://2079102914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA7OKfIba5xvQF1lhv60z%2Fuploads%2FUZ1OpRSkwFCn8EPbkYZu%2FUnity_RlzLiuFMCK.gif?alt=media&#x26;token=97a85f13-4d28-40c2-b3c3-5516767eaf51" alt=""><figcaption></figcaption></figure>

Finally, the last step is to add a new dropdown to TypeI AI Level In the AIUIs prefabs from the folder Prefabs/UIs/Others, it can be named whatever for the new dropdown. That's all, the new TypeI AI level is ready in scene with AI.&#x20;

<figure><img src="https://2079102914-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA7OKfIba5xvQF1lhv60z%2Fuploads%2Fz3uluOUfJk9g17jeM34i%2FUnity_lOT9AxtffD.png?alt=media&#x26;token=a846a22d-f6b9-4fd9-bd0b-b7467fda7c9d" alt=""><figcaption></figcaption></figure>

