Thread: Smart Tic Tac Toe!!

  1. #1
    Registered User
    Join Date
    Aug 2010
    Location
    Torreon
    Posts
    1

    Smart Tic Tac Toe!!

    Help to complete this code :S

    Code:
    #include<iostream>
    #include<fstream.h>
    #include<time.h>
    #include <stdlib.h>
    #include <windows.h>  
    using namespace std;
    
    int XOBoard[3][3];     /*global variable board */
    class Player          /*Class of Players*/
    {
    public:
          Player()  
          {
                    //CODE
                    
          }
          void Draw()          /*Function of Player class to draw the game board  */
          {
               
               cout<<"\n\n\n\n\n";
               cout<<"\t\t\t            Top        ";
                          cout<<"\n\t\t\t***************************\n";
               cout<<"\t\t\t*  .  1       2       3   *\n\t\t\t*.........................*\n";
               if ( XOBoard[0][0] == 0 )      /*If else condition to draw the game board */
               {
                  cout<<"\t\t\t* 1.     |";
               }
               else if ( XOBoard[0][0] == 1) 
               {
                    cout<<"\t\t\t* 1.  X  |";
                    }
               else if ( XOBoard[0][0] == -1) {
                    cout<<"\t\t\t* 1.  O  |";
                    }
               if ( XOBoard[1][0] == 0) {
                    cout<<"        |";
                    }
               else if ( XOBoard[1][0] == 1) {
                    cout<<"    X   |";
                    }
               else if ( XOBoard[1][0] == -1) {
                    cout<<"    O   |";
                    }
               if ( XOBoard[2][0] == 0) {
                    cout<<"       *";
                    }
               else if ( XOBoard[2][0] == 1) {
                    cout<<"   X   *";
               }
               else if ( XOBoard[2][0] == -1) {
                    cout<<"   O   *";
                    }
               cout<<"\n\t\t\t*  .----------------------*\n";
               if ( XOBoard[0][1] == 0) {
                  cout<<"\t\t  Side  * 2.     |";
                  }
               else if ( XOBoard[0][1] == 1) {
                    cout<<"\t\t  Side  * 2.  X  |";
                    }
               else if ( XOBoard[0][1] == -1) {
                    cout<<"\t\t  Side  * 2.  O  |";
                    }
               if ( XOBoard[1][1] == 0) {
                    cout<<"        |";
                    }
               else if ( XOBoard[1][1] == 1) {
                    cout<<"    X   |";
                    }
               else if ( XOBoard[1][1] == -1) {
                    cout<<"    O   |";
                    }
               if ( XOBoard[2][1] == 0) {
                    cout<<"       *";
                    }
               else if ( XOBoard[2][1] == 1) {
                    cout<<"   X   *";
                    }
               else if ( XOBoard[2][1] == -1) {
                    cout<<"   O   *";
                    }
               cout<<"\n\t\t\t*  .----------------------*\n";
               if ( XOBoard[0][2] == 0) {
                  cout<<"\t\t\t* 3.     |";
                  }
               else if ( XOBoard[0][2] == 1) {
                    cout<<"\t\t\t* 3.  X  |";
                    }
               else if ( XOBoard[0][2] == -1) {
                    cout<<"\t\t\t* 3.  O  |";
                    }
               if ( XOBoard[1][2] == 0) {
                    cout<<"        |";
                    }
               else if ( XOBoard[1][2] == 1) {
                    cout<<"    X   |";
                    }
               else if ( XOBoard[1][2] == -1) {
                    cout<<"    O   |";
                    }
               if ( XOBoard[2][2] == 0) {
                    cout<<"       *";
                    }
               else if ( XOBoard[2][2] == 1) {
                    cout<<"   X   *";
                    }
               else if ( XOBoard[2][2] == -1) {
                    cout<<"   O   *";
                    }
               cout<<"\n\t\t\t***************************\n";
               }
    
          int Human_win()   /*function of class Player to output when user has won*/
          {
                            //code
    		  return 0;
          }
          int Computer_win()  /*function of class Player to output when computer has won*/
          {
               //code
               return 0;   
          }
          int chkwinner()     
          {
    	
               return 0;
    		}
         void Reset_board ()                                                                  
         {
         
         
         }
         void fill_XOBoard(int column, int row, int move_by)    
         {
              
         }
         bool used_cell_check_for_Human(int column, int row)                                                   /*function of class Player to check whether the cell inout by Player has been occupied earlier or not*/
         {
              
                 return true;
         }
          bool used_cell_check_for_Computer(int column, int row)                                                   /*function of class Player to check whether the cell inout by Player has been occupied earlier or not*/
         {
             
                 return true;
          }
          int Chk_tie()
          {
           
           return 0;
           }
           
              int chk_cols()                                             
              {
               
               return 0;
               }
          
    
               int chk_rows()      
               {
               
              return 0;
              }
              
    
          int chk_diags()           
          {
           
           return 0;
             } 
          
                    
    };            /*end class Player*/
          
    class Human_Player : public Player                                                        
    {
         
    };            /*end class human*/
          
    class Computer_Player: public Player    /*inherited class computer from Player class*/
    {
          
    };           /*end class computer*/
    
    
    
    int main()        /*main function begins*/
    {
         Player Play;         /*object of class Player*/
         Human_Player h;     /*object of class human*/
         Computer_Player c;
         
         int trn=1;    /*variable to denote turn of Player*/
         int i=1;
         char ch='y';    /*character to input if Player wants to play again or not*/
         int winner=1;    /*integer to denote winner*/
         int ctrl1,ctrl2;   /*integer to denote winner*/
         int ctr=0;
         int check_for_tie;
         char begin, Instruct;
        
         
             cout<<"\n\n\n\n\n";
             
             cout<<"\n**     **  ********  *******";
             cout<<"\n**     **  ********  ********";
             cout<<"\n**     **  **    **  **    **";
             cout<<"\n**  *  **  ********  *******";
             cout<<"\n** *** **  ********  *******";
             cout<<"\n***   ***  **    **  **    **";
             cout<<"\n**     **  **    **  **    **";
             cout<<"\n\n\n";
             for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
             {
              for(ctrl2 = 0; ctrl2 < 20000; ctrl2++)
               {
               }
               }        
             cout<<"\n\t\t********  ********";
             cout<<"\n\t\t********  ********";
             cout<<"\n\t\t**    **  **";
             cout<<"\n\t\t**    **  *****";
             cout<<"\n\t\t**    **  *****";
             cout<<"\n\t\t********  **";
             cout<<"\n\t\t********  **";
             cout<<"\n\n\n";
             for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
             {
              for(ctrl2 = 0; ctrl2 < 20000; ctrl2++)
               {
               }
               }
             cout<<"\n\t\t\t********  **    **  ********";
             cout<<"\n\t\t\t********  **    **  ********";
             cout<<"\n\t\t\t   **     ********  **";
             cout<<"\n\t\t\t   **     ********  *****";
             cout<<"\n\t\t\t   **     **    **  **";
             cout<<"\n\t\t\t   **     **    **  ********";
             cout<<"\n\t\t\t   **     **    **  ********";
             cout<<"\n\n\n";
             for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
             {
              for(ctrl2 = 0; ctrl2 < 20000; ctrl2++)
               {
               }
               }
             cout<<"\n\t\t\t       **        ********  **    **  *******    *******";
             cout<<"\n\t\t\t       **        ********  ***   **  ********  ********";
             cout<<"\n\t\t\t       **        **    **  ****  **  **    **   **";
             cout<<"\n\t\t\t       **        ********  ** ** **  **    **    **";
             cout<<"\n\t\t\t       **        ********  **  ****  **    **      **";
             cout<<"\n\t\t\t       ********  **    **  **   ***  ********  ********";
             cout<<"\n\t\t\t       ********  **    **  **    **  *******   *******";
            
         cout<<"\n\n\n\n\n\t\t    Welcome to the game WAR OF THE LANDS.\n\n\t\t";    
        
         cout<<"\nHello , I need to tell you the story of War of the Lands. ";
         cout<<"\nDo you want to read the instructions or simply proceede with the game ? \n(R)ead or (P)roceede :";
         cin>>Instruct;
         if (Instruct=='R' ||Instruct=='r')
         {
        
         
         
         
         cout<<"\n\n     A disputed area of 900 square meters lies between two neighboring villages. ";
         cout<<"\n     The dispute between the neighboring villages has been running for  ";
         cout<<"\n     generations. The government has finally taken a decision to resolve  ";
         cout<<"\n     the dispute and grant the possession of this land to one of the ";
         cout<<"\n     villages using a fair method. ";
         cout<<"\n\n\n     The government has divided the disputed land into 9 equal square plots each";
         cout<<"\n     of 300 square meters as shown in the following figure:";
         for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
             {
              for(ctrl2 = 0; ctrl2 < 20000; ctrl2++)
               {
               }
               }
         Play.Draw(); 
         for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
             {
              for(ctrl2 = 0; ctrl2 < 20000; ctrl2++)
               {
               }
               }
         cout<<"\n\n     The following method will be used to grant possession of the land to \n     one of the villages: ";      
         for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
             {
              for(ctrl2 = 0; ctrl2 < 80000; ctrl2++)
               {
               }
               }
         cout<<"\n\n     The government has decided that the entire land will be given to the \n     village that makes three successful plantations.";
         for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
             {
              for(ctrl2 = 0; ctrl2 < 80000; ctrl2++)
               {
               }
               }
         cout<<"\n\n     At one point of time, only one village will plant vegetation on a \n     square plot. Each village will be given a fair chance to grow \n     vegetation in a square block, turn-by-turn.";
         for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
             {
              for(ctrl2 = 0; ctrl2 < 80000; ctrl2++)
               {
               }
               }
         cout<<"\n\n     The first village that will plant vegetation on three square plots\n     from one corner to the opposite corner (vertically, horizontally,\n     or diagonally) will be given possession. For example,\n     on plots (1,1), (2,2) and (3,3) or (2,1), (2,2), and (2, 3) and so on";
         for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
             {
              for(ctrl2 = 0; ctrl2 < 80000; ctrl2++)
               {
               }
               }
         cout<<"\n\n     Each village can plant in a way to block the other village from planting\n     vegetation in three consecutive plots of land.";
         for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
             {
              for(ctrl2 = 0; ctrl2 < 80000; ctrl2++)
               {
               }
               }
         cout<<"\n\n     In case all the plots have been planted and neither village has planted\n     threeconsecutive plots of land, the government holds\n     possession of the entire land. Both villages will be then\n     given another chance to restart the plantation all over again.";
              for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
             {
              for(ctrl2 = 0; ctrl2 < 80000; ctrl2++)
               {
               }
               }
         cout<<"\n\n     In the current scenario, one village is represented by I, the computer\n     and the other village is by you, that is .\n     The decision that who makes the first move lies with the you.\n     Your plantation will be represented by 'X' on the plot of land\n     and the computer's by 'O'.";       
         cout<<"\n\n     Each player will choose a plot of land by selecting the top and left\n     coordinate pointing to the specific plot of land.";    
         cout<<"\n\n\n\n\n     Go ahead...Press ENTER when you are ready to face the challenge!!!";
         cin.get();
          
    }
         while(ch=='y' || ch=='Y')     /*while loop to continue playing until user quits*/
         {
        
         cout<<"\n\n    So, do you want to make the first move or \n    Should I make the first move?\n    Enter (C) if you want me to begin , else press (I): ";
         cin>>begin;
         if (begin=='I'||begin=='i')
         trn=1;
         else if (begin=='c'||begin=='C')
         trn=-1;
         
         do                    /*do wbile loop to continue until there is a winner*/
              {
                Play.Draw();
                
                                /*call function of class Player to draw the XOBoard*/
                
            }while (winner!=1);   
            
                ch='n';
            }
            
            cout<<"\n\n\n\n\n\n\n\n\n\t\tBye bye !!!. See you soon...";
            cin.get(); 
            system("pause");
            return 0;
    }
    IDEAS?
    Last edited by VirtualAce; 08-26-2010 at 08:22 PM.

  2. #2
    C lover
    Join Date
    Oct 2007
    Location
    Virginia
    Posts
    266
    Heh, that could sure use some "[code]" tags.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    IDEAS?
    Several:

    • Reformat your code so it is actually readable
    • Tell us what is wrong with it
    • Be more specific about your particular question
    • If you want me to complete your code then give me say...500 bucks and I'll think about it.

  4. #4
    C lover
    Join Date
    Oct 2007
    Location
    Virginia
    Posts
    266
    Quote Originally Posted by Bubba View Post
    Several:

    • Reformat your code so it is actually readable
    • Tell us what is wrong with it
    • Be more specific about your particular question
    • If you want me to complete your code then give me say...500 bucks and I'll think about it.
    Yes yes, reformat this. Hard to tell where most of the blocks begin and end.

  5. #5
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    IDEAS?
    Code:
    for(ctrl1 = 0; ctrl1 < 2000; ctrl1++)
             {
              for(ctrl2 = 0; ctrl2 < 80000; ctrl2++)
               {
               }
               }
    please Please PLEASE don't do that. I beg you.

    EDIT: Sorry, didn't offer an alternative. Take a look at this.
    Last edited by bernt; 08-26-2010 at 11:23 PM.
    Consider this post signed

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Has any work been done?

    I mean, by the time you rip out all the trivial print statements, there isn't actually ANY code there at all to implement the game.

    In fact, it rather looks like boilerplate code from the tutor, which the student is supposed to complete.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    ideas? the only one that comes to mind is GetReal()
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    This has got to be homework...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tic tac toe check winner
    By dhardin in forum C++ Programming
    Replies: 15
    Last Post: 12-20-2009, 07:57 PM
  2. Help me with my simple Tic tac toe prog
    By maybnxtseasn in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 06:25 PM
  3. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 06:25 PM
  4. Tic Tac Toe AI help please...
    By Rune Hunter in forum Game Programming
    Replies: 12
    Last Post: 11-05-2004, 04:24 PM
  5. Help with Tic Tac Toe game
    By snef73 in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2003, 08:33 AM

Tags for this Thread