Game AI/heuristic algorithms are used in a wide variety of quite disparate fields inside a game. The most obvious is in the control of any NPCs in the game, although "scripting" (decision tree) is currently the most common means of control.
Pathfinding, another common use for AI, is widely seen in real-time strategy games. Pathfinding is the method for determining how to get the NPC from one point on a map to another, taking into consideration the terrain, obstacles and possibly "fog of war".
You can implement an AI algorithm in a Tic-Tac-Toe game:
Rules of the Game
The game is to be played between two people (in this program between HUMAN and COMPUTER).
One of the players chooses ‘O’ and the other ‘X’ to mark their respective cells.
The game starts with one of the players and the game ends when one of the players has one whole row/ column/ diagonal filled with his/her respective character (‘O’ or ‘X’).
If no one wins, then the game is said to be a draw.
Implementation: In our program, the moves taken by the computer and the human are chosen randomly. We use rand() function for this.
What more can be done in the program?
The program is not played optimally by both sides because the moves are chosen randomly. The program can be easily modified so that both players play optimally (which will fall under the category of Artificial Intelligence). Also, the program can be modified such that the user himself gives the input (using scanf() or cin).
Winning Strategy – An Interesting Fact
If both players play optimally then it is destined that you will never lose (“although the match can still be drawn”). It doesn’t matter whether you play first or second. In another way – “ Two expert players will always draw ”.
For the code, you can refer the link: https://www.geeksforgeeks.org/implementation-of-tic-tac-toe-game/
Interested in learning Artificial Intelligence? Check out the Artificial Intelligence Online Course!