How would I check if the user gets 3 in a row in a tic tac toe game? I'm stumped
Here is the code I have:
Code:
#include <iostream>
#include <time.h>
#include <windows.h>
using namespace std;
void draw(char board[3][3])
{
for(int i = 0; i < 3; i ++)
{
for(int t = 0; t < 3; t ++)
{
cout << board[i][t] << ' ';
}
cout << endl;
}
}
void moveEnemey(char board[3][3], char icon[2])
{
srand(time(NULL));
int i, t;
while(1)
{
i = rand()%3;
t = rand()%3;
if(board[i][t] == '_')
{
board[i][t] = icon[1];
break;
}
}
}
int main()
{
int input;
char icon[2] = { 'X', 'O' };
char board[3][3] =
{
'_', '_', '_',
'_', '_', '_',
'_', '_', '_'
};
while(1)
{
draw(board);
cout << "\nMake your move: ";
cin >> input;
if(board[0][input - 1] != icon[1])
{
board[0][input - 1] = icon[0];
moveEnemey(board, icon);
}
else cout << '\a';
system("cls");
}
return 0;
}