You are on page 1of 3

#include <iostream>

#include <cstdlib>

#include <ctime>

using namespace std;

char X[9];

void Print();

bool Vittoria;

bool Pieno;

int main()

srand(time(0));

int p,c;

while(Pieno==false and Vittoria==false)

cout<<"--------- TRIS ---------\n"<<endl;

Print();

cout<<"\nInserisci posizione da 1 a 9: \n"<<endl;

cin>>p;

X[p-1]='x';

if (Pieno==false)

c=rand()%9;

if (X[c]==' ')

while(X[c]!=' ')

c=rand()%9;
}

X[c]='o';

system("cls");

if ( X[0]!=' ' and X[1]!=' ' and X[2]!=' ' and X[3]!=' ' and X[4]!=' ' and X[5]!=' ' and X[6]!=' ' and X[7]!=' ' and
X[8]!=' ')

Pieno=true;

if (

(X[0]=X[1]=X[2]) or

(X[3]=X[4]=X[5]) or

(X[6]=X[7]=X[8]) or

(X[0]=X[3]=X[6]) or

(X[1]=X[4]=X[7]) or

(X[2]=X[5]=X[8]) or

(X[0]=X[4]=X[8]) or

(X[2]=X[4]=X[6])

Vittoria=true;

else{Vittoria=false;}

return 0;

}
void Print()

cout<<" "<<X[0]<<" | "<<X[1]<<" | "<<X[2]<<endl;

cout<<" "<<"---------\n";

cout<<" "<<X[3]<<" | "<<X[4]<<" | "<<X[5]<<endl;

cout<<" "<<"---------\n";

cout<<" "<<X[6]<<" | "<<X[7]<<" | "<<X[8]<<endl;

You might also like