Hi I'm writing a tic tac toe game and I am wondering how to go about making an AI, here is my code:
any help would be greatly appreciated
Code:
#include <iostream>
using namespace std;
int main()
{
int firstTurnRow;
int firstTurnColumn;
int secondTurnRow;
int secondTurnColumn;
int thirdTurnRow;
int thirdTurnColumn;
const int ROWS = 3;
const int COLUMNS = 3;
char board[ROWS][COLUMNS] = { {' ',' ',' '},
{' ', ' ',' '},
{' ',' ',' '} };
cout << "Here's the tic-tac-toe board:" << endl;
for (int i = 0; i < ROWS; ++i)
{
for (int j = 0; j < COLUMNS; ++j)
cout << board[i][j];
cout << endl;
}
cout << endl;
cout << "enter the row you want to move into" << endl;
cin >> firstTurnRow;
cout << "enter column you want to move into" << endl;
cin >> firstTurnColumn;
board[firstTurnRow - 1][firstTurnColumn - 1] = 'X';
cout << "Now the tic tac toe board is:" << endl;
for (int i = 0; i < ROWS; ++i)
{
for (int j = 0; j < COLUMNS; ++j)
cout << board[i][j];
cout << endl;
}
cout << endl;
cout << "enter the row you want to move into" << endl;
cin >> secondTurnRow;
cout << "enter column you want to move into" << endl;
cin >> secondTurnColumn;
board[secondTurnRow - 1][secondTurnColumn - 1] = 'X';
cout << "Now the tic tac toe board is:" << endl;
for (int i = 0; i < ROWS; ++i)
{
for (int j = 0; j < COLUMNS; ++j)
cout << board[i][j];
cout << endl;
}
cout << endl;
cout << "enter the row you want to move into" << endl;
cin >> thirdTurnRow;
cout << "enter column you want to move into" << endl;
cin >> thirdTurnColumn;
board[thirdTurnRow - 1][thirdTurnColumn - 1] = 'X';
cout << "Now the tic tac toe board is:" << endl;
for (int i = 0; i < ROWS; ++i)
{
for (int j = 0; j < COLUMNS; ++j)
cout << board[i][j];
cout << endl;
}
cout << endl;
return 0;
}
any help would be greatly appreciated