DSA Final Assignment
DSA Final Assignment
Algorithm:
Step-1: Initialize the Board: Create a 3x3 grid using a 2D array initialized with empty
characters.
Step-2: Display the Board: Create a function to print the current state of the board.
Step-3: Player Move: Create a function to handle player moves, ensuring the move is
Step-4: Check for Win: Create a function to check all possible winning conditions
Step-5: Check for Draw: Create a function to check if the board is full without a winner.
int main() {
char board[3][3] = {
{' ', ' ', ' '},
{' ', ' ', ' '},
{' ', ' ', ' '}
};
r = -1;
c = -1;
cin.clear();
cin.ignore(10000, '\n');
board[r][c] = currentPlayer;
currentPlayer = (currentPlayer == playerX) ? playerO : playerX;
for (int r = 0; r < 3; r++) {
if (board[r][0] != ' ' && board[r][0] == board[r][1] && board[r][1] == board[r][2]) {
winner = board[r][0];
break;
}
}
Output: