Finally i managed to found this solution code.
int ticBestMove ( int player, int &bestMove )
{
int bestScore, score;
if ( fullBoard() )
return DRAW;
else if ( marked3 ( player ))
return WIN;
else if ( marked3 ( 1 - player ))
return LOSS;
else {
bestScore = LOSS;
int not_used;
for ( int i = 0; i < 9; ++i ) {
if ( isEmpty ( i ) ) {
mark ( i, player );
score = -ticBestMove (1-player, not_used );
if ( score > bestScore ) {
bestMove = i;
bestScore = score;
}
unmark ( i );
}
}
}
return bestScore;
}
But i found one problem that is computer always choose the first best solution,How do i add the random function in it?
Maybe if bestscore==score i store the bestmove into an array,
and count the length of array then random a number between the length of array to choose a move?
Somebody please guide me...