please help... my computer moves wont work. it not an error it a crash or infinite loop.
#include <stdio.h>
#include "strlib.h"
#include "simpio.h"
#include "genlib.h"
#include "string.h"
#define size 9
void main()
{
int rand, x = 0, i, player = 0, turn = 0, row = 0, column = 0, line = 0, winner = 0, used[size], check;
bool space=true;
char board[size][size] = { {'1','2','3'}, {'4','5','6'},{'7','8','9'}};
printf("Welcome to Tic Tac Toe: Player 1 = you-Player 2 = computer\n");
for(check=0; check<10; check++)
{
used[check] = 1;
}
for( i = 1; i<size && winner==0; i++)
{
//-----------------------------Display board--------------------------------//
printf("\n\n");
printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
printf("-----------\n");
printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
printf("-----------\n");
printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
//--------------------------------------------------------------------------//
player = i%2 + 1;
if(player == 1)
{
printf("\nPlayer 1, place your X: ");
turn = GetInteger();
used[x] = turn;
x++;
}
else
{
if(x==0) turn = 1;
else
{
for(rand=9; rand<10 && space == true; rand--)
{
space = true;
for(check=0; check<10; check++)
{
if(used[check] == rand)
{
check = 10;
space = false;
}
else;
}
}
turn = rand;
}
}
row = --turn/3;
column = turn%3;
while(turn<0 || turn>size || board[row][column]>'9');
board[row][column] = (player == 1) ? 'X' : 'O';
if((board[0][0] == board[1][1] && board[0][0] == board[2][2]) || (board[0][2] == board[1][1] && board[0][2] == board[2][0]))
{
winner = player;
}
else
{
for(line = 0; line <= 2; line ++) if((board[line][0] == board[line][1] && board[line][0] == board[line][2]) || (board[0][line] == board[1][line] && board[0][line] == board[2][line]))winner = player;
}
}
//-----------------------------Display board--------------------------------//
printf("\n\n");
printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
printf("---+---+---\n");
printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
printf("---+---+---\n");
printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
//--------------------------------------------------------------------------//
if(winner == 0)
{
printf("\nIt is a draw\n");
}
else
{
printf("\nCongratulations, player %d!\n", winner);
}
system("pause");
}