Academia.eduAcademia.edu

Code Overview

Abstract

The game board is represented by an array `b[]` containing characters '0' to '9' representing the positions on the Tic-Tac-Toe grid. 2. Functions: ➢ `printboard()`: Prints the current state of the Tic-Tac-Toe board. ➢ `checkwin()`: Checks if any player has won the game based on the current board configuration. ➢ `aiMove()`: Represents the AI (Player 2) making a random move by generating a random number between 1 and 9. 3. Main Function: ➢ The `main()` function controls the flow of the game. ➢ It alternates between Player 1 and Player 2 (where Player 2 is the AI). ➢ Each player is prompted to make a move by entering a number corresponding to an empty position on the board. ➢ Player moves are denoted by 'X' and AI moves by 'O'. ➢ The game continues until there's a win, a draw, or an invalid move.