Good morning. I was making a tic-tac-toe program to become a little more experienced with C++, but I've come to an error I can't remove.
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int AI(int board[3][3]);
int wincon(int board[3][3]);
int board()
{
int board[3][3]={};
int j=1;
int XorO;
int *pXorO=&XorO;
pXorO=new int;
for (int i=0;j==1; i++)
{
XorO=i%2+1;
int choice;
if (XorO==1)
{
cin>>choice;
}
else
{
choice=AI(board);
}
switch(choice)
{
case 1:
board[0][2]=XorO;
break;
case 2:
board[1][2]=XorO;
break;
case 3:
board[2][2]=XorO;
break;
case 4:
board[0][1]=XorO;
break;
case 5:
board[1][1]=XorO;
break;
case 6:
board[2][1]=XorO;
break;
case 7:
board[0][0]=XorO;
break;
case 8:
board[1][0]=XorO;
break;
case 9:
board[2][0]=XorO;
break;
}
for(int j=0; j<3; j++)
{
for (int k=0; k<3; k++)
{
cout<<board[k][j];
}
cout<<"\n";
}
wincon(board);
}
return 0;
}
int main()
{
cout<<"Would you like to play a game of tic-tac-toe?\n";
cout<<"If so, please make the first move.\n";
board();
return 0;
}
int AI((int board)[3][3])
{
int reroll;
do
{
int x=rand()%3;
int y=rand()%3;
if ((board[x][y]==1)||(board[x][y]==2))
{
reroll=1;
}
else
{
reroll=0;
}
}
While (reroll)
return (3*x+y+1);
}
int wincon(int (&board)[3][3])
{
for (int i = 0; i < 3; i++){
if ((board[i][1] == board[i][2] == board[i][3])||(board[1][i] == board[2][i] == board[3][i]))
{
cout<<"Player "<<*pXorO<<" wins!";
break;
}
else if ((board[1][1] == board[2][2] == board[3][3])||(board[1][3] == board[2][2] == board[3][1]))
{
cout<<"Player "<<XorO<<" wins!";
break;
}
}
return 0;
}
}
I'm confident that the error isn't in board(), since that was the first function I took care of, and it handled two-player tic-tac-toe well. Whenever I compile, I get the errors "'Int AI' redeclared as different type of symbol" on line 80, with "int AI((int board)[3][3])", and "Previous declaration of 'int AI((*)[3])'", on line 6 with the prototype of AI.
Can anyone see where I went wrong?