Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////You gonna get raped
- #include <iostream>
- //#include <cmath>
- //#include <vector>
- //#include <cstdlib>
- //#include <iomanip>
- //#include "std_lib_facilities.h"
- using namespace std;
- //////Tic, tac, toe for command line//////
- // This program is free software; you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation; either version 2 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program; if not, write to the Free Software
- // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- // MA 02110-1301, USA.
- ///////////////////////////////// >inb4 nobody wants your piece of shit code
- //class wrong_x_or_o { };
- class false_win { };
- class already_used { };
- class bad_pos_input { };
- string pos1 = "1";
- string pos2 = "2";
- string pos3 = "3";
- string pos4 = "4";
- string pos5 = "5";
- string pos6 = "6";
- string pos7 = "7";
- string pos8 = "8";
- string pos9 = "9";
- bool pos1_changed = false;
- bool pos2_changed = false;
- bool pos3_changed = false;
- bool pos4_changed = false;
- bool pos5_changed = false;
- bool pos6_changed = false;
- bool pos7_changed = false;
- bool pos8_changed = false;
- bool pos9_changed = false;
- bool win=false;
- string winner="nobody";
- int checks = 0;
- bool tie = false;
- void change_it(int pos_specify, string x_or_o) {
- // if(x_or_o != "x" && x_or_o !="X" && x_or_o != "o" && x_or_o != "O") {
- // throw wrong_x_or_o(); }
- // if(x_or_o == "x") x_or_o="X";
- // if(x_or_o == "o") x_or_o="O";
- if(!cin) throw bad_pos_input(); //check if anything but int
- if(pos_specify>9 || pos_specify<1) throw bad_pos_input();
- if(pos_specify==1) {
- if(pos1_changed==true) throw already_used();
- pos1=x_or_o;
- pos1_changed=true;
- }
- if(pos_specify==2) {
- if(pos2_changed==true) throw already_used();
- pos2=x_or_o;
- pos2_changed=true;
- }
- if(pos_specify==3) {
- if(pos3_changed==true) throw already_used();
- pos3=x_or_o;
- pos3_changed=true;
- }
- if(pos_specify==4) {
- if(pos4_changed==true) throw already_used();
- pos4=x_or_o;
- pos4_changed=true;
- }
- if(pos_specify==5) {
- if(pos5_changed==true) throw already_used();
- pos5=x_or_o;
- pos5_changed=true;
- }
- if(pos_specify==6) {
- if(pos6_changed==true) throw already_used();
- pos6=x_or_o;
- pos6_changed=true;
- }
- if(pos_specify==7) {
- if(pos7_changed==true) throw already_used();
- pos7=x_or_o;
- pos7_changed=true;
- }
- if(pos_specify==8) {
- if(pos8_changed==true) throw already_used();
- pos8=x_or_o;
- pos8_changed=true;
- }
- if(pos_specify==9) {
- if(pos9_changed==true) throw already_used();
- pos9=x_or_o;
- pos9_changed=true;
- }
- }
- void draw_board() {
- cout << pos1 << "\t" << pos2 << "\t" << pos3 << "\n" << pos4
- << "\t" << pos5 << "\t" << pos6 << "\n" << pos7 << "\t"
- << pos8 << "\t" << pos9 << endl;
- }
- void win_logic_append() {
- if(winner=="nobody") throw false_win();
- cout << winner << " wins!\n\n";
- win=true;
- }
- int main() {
- //string pos1, pos2, pos3, pos4, pos5, pos6, pos7, pos8, pos9 = "f";
- //draw the board
- draw_board();
- //gameplay
- int pos_specify = 0;
- string x_or_o = " ";
- int count = 1;
- string turn = " ";
- cout << "\nX plays first.\n";
- while(win==false) {
- //////////determine turn
- if( (count%2)==0 ) { //if even
- //change_it(pos_specify, "O");
- turn="O";
- ++count;
- }
- else { //if odd
- //change_it(pos_specify, "X");
- turn="X";
- ++count;
- }
- //end of determine turn
- cout << "\n\n" << turn << "'s turn. What position? (1-9)\n";
- cin >> pos_specify;
- //cout << "What would you like to change it to? (X or O)\n";
- try {
- cout << "\n\n";
- change_it(pos_specify, turn);
- draw_board();
- }
- /*catch (wrong_x_or_o) {
- cerr << "Wrong input for X or O. It may only be X or O. Try again.\n";
- }*/
- catch (already_used) {
- cout << "That square is occupied. Try a different one.\n";
- }
- catch (bad_pos_input) {
- win=true; //not really, just want to terminate loop
- //tie=false;
- cout << "Bad input for your position. It can only be digits 1-9.\n";
- }
- try {
- //logic
- if(pos1==pos2 && pos2==pos3) {
- winner=pos1;
- win_logic_append(); }
- else if(count==9) ++checks;
- if(pos4==pos5 && pos5==pos6) {
- winner=pos4;
- win_logic_append(); }
- else if(count==9) ++checks;
- if(pos7==pos8 && pos8==pos9) {
- winner=pos7;
- win_logic_append(); }
- else if(count==9) ++checks;
- if(pos1==pos4 && pos4==pos7) {
- winner=pos1;
- win_logic_append(); }
- else if(count==9) ++checks;
- if(pos2==pos5 && pos5==pos8) {
- winner=pos2;
- win_logic_append(); }
- else if(count==9) ++checks;
- if(pos3==pos6 && pos6==pos9) {
- winner=pos3;
- win_logic_append(); }
- else if(count==9) ++checks;
- if(pos1==pos5 && pos5==pos9) {
- winner=pos1;
- win_logic_append(); }
- else if(count==9) ++checks;
- if(pos3==pos5 && pos5==pos7) {
- winner=pos3;
- win_logic_append(); }
- else if(count==9) ++checks;
- if(checks==8) {
- tie=true;
- win=true;
- cout << "\nTie game!\n";
- }
- }
- catch (false_win) {cerr << "Error: False win.\n";}
- }
- return 0;
- }
- //////I dun told you was gonna get raped
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement