Skip to content

Instantly share code, notes, and snippets.

Created September 30, 2012 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3808692 to your computer and use it in GitHub Desktop.
Save anonymous/3808692 to your computer and use it in GitHub Desktop.
endless if-else ladder
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
using namespace std;
int main (){
srand(time(0));
int comp=rand()%9+1,a=2,GameMode,d;
char n1='1',n2='2',n3='3',n4='4',n5='5',n6='6',n7='7',n8='8',n9='9',n,nn;
string p1,p2;
cout<<"Lets Play tic, tac, toe!"<<endl;
cout<<"Option 1. Play against a CPU"<<endl;
cout<<"Option 2. Two player"<<endl<<endl;
cout<<"Enter 1 or 2 to choose."<<endl;
cin>>GameMode;
cout<<"Heres how you play:\nEnter the number which you want to put your X."<<endl;
cout<<"Here is the value grid:"<<endl<<endl;
cout<<" "<<n1<<" | "<<n2<<" | "<<n3<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n4<<" | "<<n5<<" | "<<n6<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n7<<" | "<<n8<<" | "<<n9<<" "<<endl;
cout<<endl;
n1=' ',n2=' ',n3=' ',n4=' ',n5=' ',n6=' ',n7=' ',n8=' ',n9=' ',n;
if (GameMode==1){
cout<<"You chose to play against a CPU"<<endl<<endl;
cout<<"What dificulty would you like to play on???"<<endl;
cout<<"Option 1. Effortlessly easy."<<endl;
cout<<"Option 2. Easy."<<endl;
cout<<"Option 3. Medium."<<endl;
cout<<"Option 4. Hard."<<endl;
cout<<"Option 5. IMPOSSIBLE."<<endl;
cout<<"Enter 1-5 to choose."<<endl;
cin>>d;
cout<<"Ok, lets get started, enter your first number (1-9)."<<endl;
cin>>n;
cout<<endl;
if (n=='1'&&n1==' ')
n1='X';
else if (n=='2'&&n2==' ')
n2='X';
else if (n=='3'&&n3==' ')
n3='X';
else if (n=='4'&&n4==' ')
n4='X';
else if (n=='5'&&n5==' ')
n5='X';
else if (n=='6'&&n6==' ')
n6='X';
else if (n=='7'&&n7==' ')
n7='X';
else if (n=='8'&&n8==' ')
n8='X';
else if (n=='9'&&n9==' ')
n9='X';
else {cout<<"nice try, dont cheat!"<<endl; goto end;}
cout<<" "<<n1<<" | "<<n2<<" | "<<n3<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n4<<" | "<<n5<<" | "<<n6<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n7<<" | "<<n8<<" | "<<n9<<" "<<endl;
cout<<endl;
cout<<"Ok, Now its the computers turn."<<endl;
loop1:
if (n1=='O'&&n7=='O'&&n4==' '&&(d==2||d==3||d==4||d==5))
comp=4;
else if (n1=='O'&&n3=='O'&&n2==' '&&(d==2||d==3||d==4||d==5))
comp=2;
else if (n2=='O'&&n8=='O'&&n5==' '&&(d==2||d==3||d==4||d==5))
comp=5;
else if (n3=='O'&&n9=='O'&&n6==' '&&(d==2||d==3||d==4||d==5))
comp=6;
else if (n3=='O'&&n7=='O'&&n5==' '&&(d==2||d==3||d==4||d==5))
comp=5;
else if (n4=='O'&&n6=='O'&&n5==' '&&(d==2||d==3||d==4||d==5))
comp=5;
else if (n7=='O'&&n9=='O'&&n8==' '&&(d==2||d==3||d==4||d==5))
comp=8;
else if (n1=='O'&&n2=='O'&&n3==' '&&(d==3||d==4||d==5))
comp=3;
else if (n2=='O'&&n3=='O'&&n1==' '&&(d==3||d==4||d==5))
comp=1;
else if (n1=='O'&&n5=='O'&&n9==' '&&(d==3||d==4||d==5))
comp=9;
else if (n4=='O'&&n5=='O'&&n6==' '&&(d==3||d==4||d==5))
comp=6;
else if (n5=='O'&&n6=='O'&&n4==' '&&(d==3||d==4||d==5))
comp=4;
else if (n7=='O'&&n8=='O'&&n9==' '&&(d==3||d==4||d==5))
comp=9;
else if (n8=='O'&&n9=='O'&&n7==' '&&(d==4||d==5))
comp=7;
else if (n1=='O'&&n4=='O'&&n7==' '&&(d==4||d==5))
comp=7;
else if (n4=='O'&&n7=='O'&&n1==' '&&(d==4||d==5))
comp=1;
else if (n2=='O'&&n5=='O'&&n8==' '&&(d==4||d==5))
comp=8;
else if (n5=='O'&&n8=='O'&&n2==' '&&(d==4||d==5))
comp=2;
else if (n3=='O'&&n6=='O'&&n9==' '&&(d==4||d==5))
comp=9;
else if (n6=='O'&&n9=='O'&&n3==' '&&d==5)
comp=3;
else if (n5=='O'&&n9=='O'&&n1==' '&&d==5)
comp=1;
else if (n3=='O'&&n5=='O'&&n7==' '&&d==5)
comp=7;
else if (n5=='O'&&n7=='O'&&n3==' '&&d==5)
comp=3;
else if (n1=='X'&&n9=='X'&&n5==' '&&(d==2||d==3||d==4||d==5))
comp=5;
else if (n1=='X'&&n7=='X'&&n4==' '&&(d==2||d==3||d==4||d==5))
comp=4;
else if (n1=='X'&&n3=='X'&&n2==' '&&(d==2||d==3||d==4||d==5))
comp=2;
else if (n2=='X'&&n8=='X'&&n5==' '&&(d==2||d==3||d==4||d==5))
comp=5;
else if (n3=='X'&&n9=='X'&&n6==' '&&(d==2||d==3||d==4||d==5))
comp=6;
else if (n3=='X'&&n7=='X'&&n5==' '&&(d==2||d==3||d==4||d==5))
comp=5;
else if (n4=='X'&&n6=='X'&&n5==' '&&(d==3||d==4||d==5))
comp=5;
else if (n7=='X'&&n9=='X'&&n8==' '&&(d==3||d==4||d==5))
comp=8;
else if (n1=='X'&&n2=='X'&&n3==' '&&(d==3||d==4||d==5))
comp=3;
else if (n2=='X'&&n3=='X'&&n1==' '&&(d==3||d==4||d==5))
comp=1;
else if (n1=='X'&&n5=='X'&&n9==' '&&(d==3||d==4||d==5))
comp=9;
else if (n4=='X'&&n5=='X'&&n6==' '&&(d==3||d==4||d==5))
comp=6;
else if (n5=='X'&&n6=='X'&&n4==' '&&(d==3||d==4||d==5))
comp=4;
else if (n7=='X'&&n8=='X'&&n9==' '&&(d==3||d==4||d==5))
comp=9;
else if (n8=='X'&&n9=='X'&&n7==' '&&(d==4||d==5))
comp=7;
else if (n1=='X'&&n4=='X'&&n7==' '&&(d==4||d==5))
comp=7;
else if (n4=='X'&&n7=='X'&&n1==' '&&(d==4||d==5))
comp=1;
else if (n2=='X'&&n5=='X'&&n8==' '&&(d==4||d==5))
comp=8;
else if (n5=='X'&&n8=='X'&&n2==' '&&(d==4||d==5))
comp=2;
else if (n3=='X'&&n6=='X'&&n9==' '&&(d==4||d==5))
comp=9;
else if (n6=='X'&&n9=='X'&&n3==' '&&(d==4||d==5))
comp=3;
else if (n5=='X'&&n9=='X'&&n1==' '&&(d==4||d==5))
comp=1;
else if (n3=='X'&&n5=='X'&&n7==' '&&d==5)
comp=7;
else if (n5=='X'&&n7=='X'&&n3==' '&&d==5)
comp=3;
else if (n1=='X'&&n9=='X'&&n5=='O'&&n6==' '&&d==5)
comp=6;
else if (n3=='X'&&n7=='X'&&n5=='O'&&n6==' '&&d==5)
comp=6;
else if (n5=='X'&&n1==' '&&d==5)
comp=1;
else if (n5=='X'&&n3==' '&&d==5)
comp=3;
else if (n5=='X'&&n7==' '&&d==5)
comp=7;
else if (n5=='X'&&n9==' '&&d==5)
comp=9;
else if (n6=='X'&&n1=='X'&&n3==' '&&(d==5||d==4))
comp=3;
else if (n6=='X'&&n7=='X'&&n9==' '&&(d==5||d==4))
comp=9;
else if (n2=='X'&&n7=='X'&&n1==' '&&(d==5||d==4))
comp=1;
else if (n2=='X'&&n9=='X'&&n3==' '&&(d==5||d==4))
comp=3;
else if (n4=='X'&&n3=='X'&&n1==' '&&(d==5||d==4))
comp=1;
else if (n4=='X'&&n9=='X'&&n7==' '&&(d==5||d==4))
comp=7;
else if (n8=='X'&&n1=='X'&&n7==' '&&(d==5||d==4))
comp=7;
else if (n8=='X'&&n3=='X'&&n9==' '&&(d==5||d==4))
comp=9;
else if (n6=='X'&&n1==' '&&(d==5||d==4))
comp=1;
else if (n6=='X'&&n7==' '&&(d==5||d==4))
comp=7;
else if (n8=='X'&&n3==' '&&(d==5||d==4))
comp=3;
else if (n8=='X'&&n1==' '&&(d==5||d==4))
comp=1;
else if (n4=='X'&&n3==' '&&(d==5||d==4))
comp=3;
else if (n4=='X'&&n9==' '&&(d==5||d==4))
comp=9;
else if (n2=='X'&&n7==' '&&(d==5||d==4))
comp=7;
else if (n2=='X'&&n9==' '&&(d==5||d==4))
comp=9;
else if (n5==' '&&(d==5||d==4))
comp=5;
else
comp=rand()%9+1;
if (comp==1&&n1!=' ')
goto loop1;
if (comp==2&&n2!=' ')
goto loop1;
if (comp==3&&n3!=' ')
goto loop1;
if (comp==4&&n4!=' ')
goto loop1;
if (comp==5&&n5!=' ')
goto loop1;
if (comp==6&&n6!=' ')
goto loop1;
if (comp==7&&n7!=' ')
goto loop1;
if (comp==8&&n8!=' ')
goto loop1;
if (comp==9&&n9!=' ')
goto loop1;
cout<<"Computer chose "<<comp<<endl;
cout<<endl;
if (comp==1&&n1==' ')
n1='O';
if (comp==2&&n2==' ')
n2='O';
if (comp==3&&n3==' ')
n3='O';
if (comp==4&&n4==' ')
n4='O';
if (comp==5&&n5==' ')
n5='O';
if (comp==6&&n6==' ')
n6='O';
if (comp==7&&n7==' ')
n7='O';
if (comp==8&&n8==' ')
n8='O';
if (comp==9&&n9==' ')
n9='O';
cout<<" "<<n1<<" | "<<n2<<" | "<<n3<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n4<<" | "<<n5<<" | "<<n6<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n7<<" | "<<n8<<" | "<<n9<<" "<<endl;
cout<<endl;
/////////////////////////////////////////
while (a!=0){
n=0;
cout<<"Your turn again"<<endl;
cin>>n;
cout<<endl;
if (n=='1'&&n1==' ')
n1='X';
else if (n=='2'&&n2==' ')
n2='X';
else if (n=='3'&&n3==' ')
n3='X';
else if (n=='4'&&n4==' ')
n4='X';
else if (n=='5'&&n5==' ')
n5='X';
else if (n=='6'&&n6==' ')
n6='X';
else if (n=='7'&&n7==' ')
n7='X';
else if (n=='8'&&n8==' ')
n8='X';
else if (n=='9'&&n9==' ')
n9='X';
else {cout<<"nice try, dont cheat!"<<endl; goto end;}
cout<<" "<<n1<<" | "<<n2<<" | "<<n3<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n4<<" | "<<n5<<" | "<<n6<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n7<<" | "<<n8<<" | "<<n9<<" "<<endl;
cout<<endl;
if ((n1=='X'&&n2=='X'&&n3=='X')||(n1=='X'&&n4=='X'&&n7=='X')||(n1=='X'&&n5=='X'&&n9=='X')||(
n2=='X'&&n5=='X'&&n8=='X')||(n3=='X'&&n6=='X'&&n9=='X')||
(n8=='X'&&n7=='X'&&n9=='X')||(n4=='X'&&n5=='X'&&n6=='X')||(n3=='X'&&n5=='X'&&n7=='X')
){
cout<<"You WINN!!!!!"<<endl;
break;}
if (n1!=' '&&n2!=' '&&n3!=' '&&n4!=' '&&n5!=' '&&n6!=' '&&n7!=' '&&n8!=' '&&n9!=' '){
cout<<"TIE!!!"<<endl;
break;}
cout<<"Ok, Now its the computers turn."<<endl;
loop:
if (n1=='O'&&n7=='O'&&n4==' '&&(d==2||d==3||d==4||d==5))
comp=4;
else if (n1=='O'&&n3=='O'&&n2==' '&&(d==2||d==3||d==4||d==5))
comp=2;
else if (n2=='O'&&n8=='O'&&n5==' '&&(d==2||d==3||d==4||d==5))
comp=5;
else if (n3=='O'&&n9=='O'&&n6==' '&&(d==2||d==3||d==4||d==5))
comp=6;
else if (n3=='O'&&n7=='O'&&n5==' '&&(d==2||d==3||d==4||d==5))
comp=5;
else if (n4=='O'&&n6=='O'&&n5==' '&&(d==2||d==3||d==4||d==5))
comp=5;
else if (n7=='O'&&n9=='O'&&n8==' '&&(d==2||d==3||d==4||d==5))
comp=8;
else if (n1=='O'&&n2=='O'&&n3==' '&&(d==3||d==4||d==5))
comp=3;
else if (n2=='O'&&n3=='O'&&n1==' '&&(d==3||d==4||d==5))
comp=1;
else if (n1=='O'&&n5=='O'&&n9==' '&&(d==3||d==4||d==5))
comp=9;
else if (n4=='O'&&n5=='O'&&n6==' '&&(d==3||d==4||d==5))
comp=6;
else if (n5=='O'&&n6=='O'&&n4==' '&&(d==3||d==4||d==5))
comp=4;
else if (n7=='O'&&n8=='O'&&n9==' '&&(d==3||d==4||d==5))
comp=9;
else if (n8=='O'&&n9=='O'&&n7==' '&&(d==4||d==5))
comp=7;
else if (n1=='O'&&n4=='O'&&n7==' '&&(d==4||d==5))
comp=7;
else if (n4=='O'&&n7=='O'&&n1==' '&&(d==4||d==5))
comp=1;
else if (n2=='O'&&n5=='O'&&n8==' '&&(d==4||d==5))
comp=8;
else if (n5=='O'&&n8=='O'&&n2==' '&&(d==4||d==5))
comp=2;
else if (n3=='O'&&n6=='O'&&n9==' '&&(d==4||d==5))
comp=9;
else if (n6=='O'&&n9=='O'&&n3==' '&&d==5)
comp=3;
else if (n5=='O'&&n9=='O'&&n1==' '&&d==5)
comp=1;
else if (n3=='O'&&n5=='O'&&n7==' '&&d==5)
comp=7;
else if (n5=='O'&&n7=='O'&&n3==' '&&d==5)
comp=3;
else if (n1=='X'&&n9=='X'&&n5==' '&&(d==2||d==3||d==4||d==5))
comp=5;
else if (n1=='X'&&n7=='X'&&n4==' '&&(d==2||d==3||d==4||d==5))
comp=4;
else if (n1=='X'&&n3=='X'&&n2==' '&&(d==2||d==3||d==4||d==5))
comp=2;
else if (n2=='X'&&n8=='X'&&n5==' '&&(d==2||d==3||d==4||d==5))
comp=5;
else if (n3=='X'&&n9=='X'&&n6==' '&&(d==2||d==3||d==4||d==5))
comp=6;
else if (n3=='X'&&n7=='X'&&n5==' '&&(d==2||d==3||d==4||d==5))
comp=5;
else if (n4=='X'&&n6=='X'&&n5==' '&&(d==3||d==4||d==5))
comp=5;
else if (n7=='X'&&n9=='X'&&n8==' '&&(d==3||d==4||d==5))
comp=8;
else if (n1=='X'&&n2=='X'&&n3==' '&&(d==3||d==4||d==5))
comp=3;
else if (n2=='X'&&n3=='X'&&n1==' '&&(d==3||d==4||d==5))
comp=1;
else if (n1=='X'&&n5=='X'&&n9==' '&&(d==3||d==4||d==5))
comp=9;
else if (n4=='X'&&n5=='X'&&n6==' '&&(d==3||d==4||d==5))
comp=6;
else if (n5=='X'&&n6=='X'&&n4==' '&&(d==3||d==4||d==5))
comp=4;
else if (n7=='X'&&n8=='X'&&n9==' '&&(d==3||d==4||d==5))
comp=9;
else if (n8=='X'&&n9=='X'&&n7==' '&&(d==4||d==5))
comp=7;
else if (n1=='X'&&n4=='X'&&n7==' '&&(d==4||d==5))
comp=7;
else if (n4=='X'&&n7=='X'&&n1==' '&&(d==4||d==5))
comp=1;
else if (n2=='X'&&n5=='X'&&n8==' '&&(d==4||d==5))
comp=8;
else if (n5=='X'&&n8=='X'&&n2==' '&&(d==4||d==5))
comp=2;
else if (n3=='X'&&n6=='X'&&n9==' '&&(d==4||d==5))
comp=9;
else if (n6=='X'&&n9=='X'&&n3==' '&&(d==4||d==5))
comp=3;
else if (n5=='X'&&n9=='X'&&n1==' '&&(d==4||d==5))
comp=1;
else if (n3=='X'&&n5=='X'&&n7==' '&&d==5)
comp=7;
else if (n5=='X'&&n7=='X'&&n3==' '&&d==5)
comp=3;
else if (n1=='X'&&n9=='X'&&n5=='O'&&n6==' '&&d==5)
comp=6;
else if (n3=='X'&&n7=='X'&&n5=='O'&&n6==' '&&d==5)
comp=6;
else if (n5=='X'&&n1==' '&&d==5)
comp=1;
else if (n5=='X'&&n3==' '&&d==5)
comp=3;
else if (n5=='X'&&n7==' '&&d==5)
comp=7;
else if (n5=='X'&&n9==' '&&d==5)
comp=9;
else if (n6=='X'&&n1=='X'&&n3==' '&&(d==5||d==4))
comp=3;
else if (n6=='X'&&n7=='X'&&n9==' '&&(d==5||d==4))
comp=9;
else if (n2=='X'&&n7=='X'&&n1==' '&&(d==5||d==4))
comp=1;
else if (n2=='X'&&n9=='X'&&n3==' '&&(d==5||d==4))
comp=3;
else if (n4=='X'&&n3=='X'&&n1==' '&&(d==5||d==4))
comp=1;
else if (n4=='X'&&n9=='X'&&n7==' '&&(d==5||d==4))
comp=7;
else if (n8=='X'&&n1=='X'&&n7==' '&&(d==5||d==4))
comp=7;
else if (n8=='X'&&n3=='X'&&n9==' '&&(d==5||d==4))
comp=9;
else if (n6=='X'&&n1==' '&&(d==5||d==4))
comp=1;
else if (n6=='X'&&n7==' '&&(d==5||d==4))
comp=7;
else if (n8=='X'&&n3==' '&&(d==5||d==4))
comp=3;
else if (n8=='X'&&n1==' '&&(d==5||d==4))
comp=1;
else if (n4=='X'&&n3==' '&&(d==5||d==4))
comp=3;
else if (n4=='X'&&n9==' '&&(d==5||d==4))
comp=9;
else if (n2=='X'&&n7==' '&&(d==5||d==4))
comp=7;
else if (n2=='X'&&n9==' '&&(d==5||d==4))
comp=9;
else if (n5==' '&&(d==5||d==4))
comp=5;
else
comp=rand()%9+1;
if (comp==1&&n1!=' ')
goto loop;
if (comp==2&&n2!=' ')
goto loop;
if (comp==3&&n3!=' ')
goto loop;
if (comp==4&&n4!=' ')
goto loop;
if (comp==5&&n5!=' ')
goto loop;
if (comp==6&&n6!=' ')
goto loop;
if (comp==7&&n7!=' ')
goto loop;
if (comp==8&&n8!=' ')
goto loop;
if (comp==9&&n9!=' ')
goto loop;
cout<<"Computer chose "<<comp<<endl;
cout<<endl;
if (comp==1&&n1==' ')
n1='O';
if (comp==2&&n2==' ')
n2='O';
if (comp==3&&n3==' ')
n3='O';
if (comp==4&&n4==' ')
n4='O';
if (comp==5&&n5==' ')
n5='O';
if (comp==6&&n6==' ')
n6='O';
if (comp==7&&n7==' ')
n7='O';
if (comp==8&&n8==' ')
n8='O';
if (comp==9&&n9==' ')
n9='O';
cout<<" "<<n1<<" | "<<n2<<" | "<<n3<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n4<<" | "<<n5<<" | "<<n6<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n7<<" | "<<n8<<" | "<<n9<<" "<<endl;
cout<<endl;
if (n1!=' '&&n2!=' '&&n3!=' '&&n4!=' '&&n5!=' '&&n6!=' '&&n7!=' '&&n8!=' '&&n9!=' '){
cout<<"TIE!!!"<<endl;
break;}
if ((n1=='O'&&n2=='O'&&n3=='O')||(n1=='O'&&n4=='O'&&n7=='O')||(n1=='O'&&n5=='O'&&n9=='O')||(
n2=='O'&&n5=='O'&&n8=='O')||(n3=='O'&&n6=='O'&&n9=='O')||
(n8=='O'&&n7=='O'&&n9=='O')||(n4=='O'&&n5=='O'&&n6=='O')||(n3=='O'&&n5=='O'&&n7=='O')
){
cout<<"You lose..."<<endl;
break;}
}}
////////////////////////////////////////////////////////////////////////////////////////
if (GameMode==2){
cout<<"You chose to play two player."<<endl<<endl;
cout<<"Enter your names"<<endl<<endl;
cout<<"Player 1"<<endl;
cin>>p1;
cout<<"Player 2"<<endl;
cin>>p2;
cout<<"Ok, lets get started, "<<p1<<" enter your first number (1-9)."<<endl;
cin>>n;
cout<<endl;
if (n=='1'&&n1==' ')
n1='X';
else if (n=='2'&&n2==' ')
n2='X';
else if (n=='3'&&n3==' ')
n3='X';
else if (n=='4'&&n4==' ')
n4='X';
else if (n=='5'&&n5==' ')
n5='X';
else if (n=='6'&&n6==' ')
n6='X';
else if (n=='7'&&n7==' ')
n7='X';
else if (n=='8'&&n8==' ')
n8='X';
else if (n=='9'&&n9==' ')
n9='X';
else {cout<<"nice try, dont cheat!"<<endl; goto end;}
cout<<" "<<n1<<" | "<<n2<<" | "<<n3<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n4<<" | "<<n5<<" | "<<n6<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n7<<" | "<<n8<<" | "<<n9<<" "<<endl;
cout<<endl;
cout<<"Ok, Now its "<<p2<<"'s turn."<<endl;
cin>>nn;
cout<<endl;
if (nn=='1'&&n1==' ')
n1='O';
else if (nn=='2'&&n2==' ')
n2='O';
else if (nn=='3'&&n3==' ')
n3='O';
else if (nn=='4'&&n4==' ')
n4='O';
else if (nn=='5'&&n5==' ')
n5='O';
else if (nn=='6'&&n6==' ')
n6='O';
else if (nn=='7'&&n7==' ')
n7='O';
else if (nn=='8'&&n8==' ')
n8='O';
else if (nn=='9'&&n9==' ')
n9='O';
else {cout<<"nice try, dont cheat!"<<endl; goto end;}
cout<<" "<<n1<<" | "<<n2<<" | "<<n3<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n4<<" | "<<n5<<" | "<<n6<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n7<<" | "<<n8<<" | "<<n9<<" "<<endl;
cout<<endl;
/////////////////////////////////////////
while (a!=0){
n=0;
cout<<p1<<", your turn again"<<endl;
cin>>n;
cout<<endl;
if (n=='1'&&n1==' ')
n1='X';
else if (n=='2'&&n2==' ')
n2='X';
else if (n=='3'&&n3==' ')
n3='X';
else if (n=='4'&&n4==' ')
n4='X';
else if (n=='5'&&n5==' ')
n5='X';
else if (n=='6'&&n6==' ')
n6='X';
else if (n=='7'&&n7==' ')
n7='X';
else if (n=='8'&&n8==' ')
n8='X';
else if (n=='9'&&n9==' ')
n9='X';
else {cout<<"nice try, dont cheat!"<<endl; goto end;}
cout<<" "<<n1<<" | "<<n2<<" | "<<n3<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n4<<" | "<<n5<<" | "<<n6<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n7<<" | "<<n8<<" | "<<n9<<" "<<endl;
cout<<endl;
if ((n1=='X'&&n2=='X'&&n3=='X')||(n1=='X'&&n4=='X'&&n7=='X')||(n1=='X'&&n5=='X'&&n9=='X')||(
n2=='X'&&n5=='X'&&n8=='X')||(n3=='X'&&n6=='X'&&n9=='X')||
(n8=='X'&&n7=='X'&&n9=='X')||(n4=='X'&&n5=='X'&&n6=='X')||(n3=='X'&&n5=='X'&&n7=='X')
){
cout<<p1<<" WINNSSS!!!!!"<<endl;
break;}
if (n1!=' '&&n2!=' '&&n3!=' '&&n4!=' '&&n5!=' '&&n6!=' '&&n7!=' '&&n8!=' '&&n9!=' '){
cout<<"TIE!!!"<<endl;
break;}
cout<<"Ok, Now its "<<p2<<"'s turn."<<endl;
cin>>nn;
cout<<endl;
if (nn=='1'&&n1==' ')
n1='O';
else if (nn=='2'&&n2==' ')
n2='O';
else if (nn=='3'&&n3==' ')
n3='O';
else if (nn=='4'&&n4==' ')
n4='O';
else if (nn=='5'&&n5==' ')
n5='O';
else if (nn=='6'&&n6==' ')
n6='O';
else if (nn=='7'&&n7==' ')
n7='O';
else if (nn=='8'&&n8==' ')
n8='O';
else if (nn=='9'&&n9==' ')
n9='O';
else {cout<<"nice try, dont cheat!"<<endl; goto end;}
cout<<" "<<n1<<" | "<<n2<<" | "<<n3<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n4<<" | "<<n5<<" | "<<n6<<" "<<endl;
cout<<" _ _ _ "<<endl;
cout<<" "<<n7<<" | "<<n8<<" | "<<n9<<" "<<endl;
cout<<endl;
if (n1!=' '&&n2!=' '&&n3!=' '&&n4!=' '&&n5!=' '&&n6!=' '&&n7!=' '&&n8!=' '&&n9!=' '){
cout<<"TIE!!!"<<endl;
break;}
if ((n1=='O'&&n2=='O'&&n3=='O')||(n1=='O'&&n4=='O'&&n7=='O')||(n1=='O'&&n5=='O'&&n9=='O')||(
n2=='O'&&n5=='O'&&n8=='O')||(n3=='O'&&n6=='O'&&n9=='O')||
(n8=='O'&&n7=='O'&&n9=='O')||(n4=='O'&&n5=='O'&&n6=='O')||(n3=='O'&&n5=='O'&&n7=='O')
){
cout<<p2<<" WINNNSSS"<<endl;
break;}
}}
end:
cout<<"Thanks for playing!!"<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment