/* Assumes that board is not full and neither players has won. * Updates board with a random O move */ #include #include #include #include #include #include #include int K; // KxK board int main(int argc, char*argv[]){ K = atoi(argv[1]); char* board = new char[K*K]; memset(board, 0, K*K*sizeof(char)); FILE* f = fopen("b.txt", "rt"); int i = 0; while (!feof(f) && i < K*K){ fscanf(f, "%c", &board[i]); i++; } fclose(f); time_t result = time(NULL); unsigned int seed = result; srand(seed); int move; do{ move = (int) rint(rand() * 1.0 /RAND_MAX * (K*K - 1)); } while (board[move]!='_'); board[move] = 'O'; f = fopen("b.txt", "wt"); for(i = 0; i < K*K; i++) fprintf(f, "%c", board[i]); fclose(f); delete []board; exit(0); }