Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "std_lib_facilities.h"
- int main()
- {
- vector<int>board;
- vector<int>ex;
- vector<int>oh;
- int num;
- int over=0;
- int xscore=0;
- int oscore=0;
- string again="y";
- cout<<endl;
- for(int i=0;i<10;++i)
- {
- ex.push_back(0);
- }
- for(int i=0;i<10;++i)
- {
- oh.push_back(0);
- }
- while(again=="y"||again=="Y")
- {
- for(int i=0;i<10;++i)
- {
- board.push_back(i);
- if(i!=0)
- {
- cout<<" "<<board[i]<<" ";
- if(i==3||i==6)
- cout<<"\n ---------\n";
- else if(i==9)
- cout<<endl;
- else
- cout<<"|";
- }
- }
- while(over==0)
- {
- if(over==0)
- {
- num=0;
- cout<<"\n\nX turn: ";
- cin>>num;
- while(num>9||num<1||oh[num]==1||ex[num]==1)
- {
- cout<<"\nCan't move there!\n";
- cout<<"\n\nX turn: ";
- cin>>num;
- }
- ex[num]=1;
- cout<<"\n\n\n\n";
- for(int i=0;i<10;++i)
- {
- board.push_back(i);
- if(i!=0)
- {
- if(ex[i]==1)
- cout<<" X ";
- else if(oh[i]==1)
- cout<<" O ";
- else
- cout<<" "<<board[i]<<" ";
- if(i==3||i==6)
- cout<<"\n ---------\n";
- else if(i==9)
- cout<<endl;
- else
- cout<<"|";
- }
- }
- }
- if((ex[1]==1&&ex[2]==1&&ex[3]==1)||(ex[4]==1&&ex[5]==1&&ex[6]==1)||(ex[7]==1&&ex[8]==1&&ex[9]==1)||(ex[1]==1&&ex[4]==1&&ex[7]==1)||(ex[2]==1&&ex[5]==1&&ex[8]==1)||(ex[3]==1&&ex[6]==1&&ex[9]==1)||(ex[1]==1&&ex[5]==1&&ex[9]==1)||(ex[3]==1&&ex[5]==1&&ex[7]==1))
- over=1;
- if((ex[1]==1||oh[1]==1)&&(ex[2]==1||oh[2]==1)&&(ex[3]==1||oh[3]==1)&&(ex[4]==1||oh[4]==1)&&(ex[5]==1||oh[5]==1)&&(ex[6]==1||oh[6]==1)&&(ex[7]==1||oh[7]==1)&&(ex[8]==1||oh[8]==1)&&(ex[9]==1||oh[9]==1))
- over=3;
- if(over==0)
- {
- num=0;
- cout<<"\n\nO turn: ";
- cin>>num;
- while(num>9||num<1||oh[num]==1||ex[num]==1)
- {
- cout<<"\nCan't move there!\n";
- cout<<"\n\nO turn: ";
- cin>>num;
- }
- oh[num]=1;
- cout<<"\n\n\n\n";
- for(int i=0;i<10;++i)
- {
- board.push_back(i);
- if(i!=0)
- {
- if(ex[i]==1)
- cout<<" X ";
- else if(oh[i]==1)
- cout<<" O ";
- else
- cout<<" "<<board[i]<<" ";
- if(i==3||i==6)
- cout<<"\n ---------\n";
- else if(i==9)
- cout<<endl;
- else
- cout<<"|";
- }
- }
- }
- if((oh[1]==1&&oh[2]==1&&oh[3]==1)||(oh[4]==1&&oh[5]==1&&oh[6]==1)||(oh[7]==1&&oh[8]==1&&oh[9]==1)||(oh[1]==1&&oh[4]==1&&oh[7]==1)||(oh[2]==1&&oh[5]==1&&oh[8]==1)||(oh[3]==1&&oh[6]==1&&oh[9]==1)||(oh[1]==1&&oh[5]==1&&oh[9]==1)||(oh[3]==1&&oh[5]==1&&oh[7]==1))
- over=2;
- }
- if(over==1)
- {
- xscore+=1;
- cout<<"\nX wins!!!\n\nX: "<<xscore<<" O: "<<oscore<<"\n\nWould you like to play again?\n(Y/N): ";
- }
- else if(over==2)
- {
- oscore+=1;
- cout<<"\nO wins!!!\n\nX: "<<xscore<<" O: "<<oscore<<"\n\nWould you like to play again?\n(Y/N): ";
- }
- else
- {
- cout<<"\nIt's a Tie!!!\n\nX: "<<xscore<<" O: "<<oscore<<"\n\nWould you like to play again?\n(Y/N): ";
- }
- cin>>again;
- if(again=="n"||again=="N")
- cout<<"\n\nThanks for Playing!";
- else
- over=0;
- while(again!="Y"&&again!="y"&&again!="N"&&again!="n")
- {
- cout<<"Please type either a 'Y' or a 'N': ";
- cin>>again;
- if(again=="n"||again=="N")
- cout<<"\nThanks for Playing!";
- else if(again=="y"||again=="Y")
- over=0;
- }
- cout<<"\n\n";
- for(int i=0;i<10;++i)
- {
- ex[i]=0;
- oh[i]=0;
- }
- }
- cout<<"\n\n";
- keep_window_open();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement