Im busy writing my tic tac toe program, and this is what i have:
Code:
#include <stdlib.h>//rand
#include <iostream.h>// cout
#include <time.h>//time
#include <stdio.h>//getchar
/*
player is O, AI is X
status [row or x-coordinate][collum or y-coordinate]
*/
char status[3][3]={' ',' ',' ',' ',' ',' ',' ',' ',' '}; // the stat is decided with this, and can be O,X, or ' '
int printer();// show the status
int AI(); //the AI
int main()
{
AI(); //run the AI
AI();
AI();
AI();
return 0;
}
/***********************/
int AI() // get random numbers for the AI
{
srand(time(NULL));
int row, collum;
row = rand() % 2;
srand(time(NULL));
collum = rand() % 2;
if (status[row][collum]==' ')
{
status[row][collum]='X'; // set new stat
printer();
}
else
{
AI();
}
}
/************************/
int printer()//i dont think there's a problem here
{
cout<<"\n+------+\n|"<<status[0][0]<<"|"<<status[0][1]
<<"|"<<status[0][2]<<"|\n+------+\n|"<<status[1][0]
<<"|"<<status[1][1]<<"|"<<status[1][2]<<"|\n+------+\n|"<<status[2][0]
<<"|"<<status[2][1]<<"|"<<status[2][2]<<"|\n+------+\n";
getchar();
}
/***************************/
the problem is that it always fills in this
Code:
+------+
|X|X| |
+------+
|X|X| |
+------+
| | | |
+------+
could someone help me? I use Dev-C++.