CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//Tic Tac Toe best move
/*
Write a program to:
-generate a valid intermediate board in a tic tac toe game
-Computer plays x
-Computer plays o
-output final board and rate moves
*/
#include <iostream>
#include <vector>
#include <ctime>
#include <iomanip> //setw()
using namespace std;
// define class tic tac toe with methods for the board
class ttt {
int n;
vector <int>v={0,0,0,0,0,0,0,0,0};
public:
//ttt():v(9, 0) { to initialise vector in constructor
ttt(){ // constructor initialise random field, check validity
int k=2*(1+rand()%4),j=0,i=-1,l;
while(j<k){
l=rand()%9;
if(v[l])continue;
v[l]=i;
i*=-1;
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run