You know you wanna play TicTacToe in DOS

Started by greg, June 13, 2009, 07:04:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

greg

It's been your dream, ever since you were a kid. When you first laid eyes on that black screen, you imagined those x's battling those o's, and all of the earth shattering excitement that would result, but could never fully realize that dream.
Now, I present to you a gift worthy of your long-suffering unfilled fantasies, a gift in the form of a small downloadable file which contains no viruses whatsoever- cuz I ain't like that.
Try to play against the computer on easy, or use the hard settings and play an epic game of 21!
It's all yours for free, just download now. I wrote it.

http://www.mediafire.com/?3mtaykhyndz

Joe_Campbell

I tried it out, and it wiped out my hard drive! >:(

J/K ;) It works well! I can't tell the difference between easy or hard, though. I beat them both with the same 'moves.' ???

greg

On easy, the computer makes a random move. On hard, it does this:
-Is there a move needed to block or win? Choose that move
-Is there a move to block and also another move to win? Choose the winning move
-Else, choose a random slot

You can easily win on hard if you know the right tricks. I'm going to have to work on choosing who goes first tomorrow, so it can make computer games harder. What's funny is, no one else in class could beat the computer on hard- you must be a TicTacToe King, Joe.  ;D

Joe_Campbell

I think that if the computer were to make the first move, my little "trick" for always winning would be nullified.

Tapio Dmitriyevich

Haha, this could probably be written as a batch file for cmd.exe. Open source!!!11!!! But maybe Haskell is more challenging...

greg

Quote from: Wurstwasser on June 14, 2009, 07:30:32 PM
Haha, this could probably be written as a batch file for cmd.exe. Open source!!!11!!! But maybe Haskell is more challenging...
Hm, I've never tried writing a batch file before. We might get to that later, though.

greg

Oh, wait. Actually, I think I did make a batch file one day in class when the teacher showed us how to... but it was only once, and I can't even remember what batch files are used for.  :P
So.... i added that option to go second when playing against the computer, and I updated the board to look more like a TicTacToe board, though it's still a bit ugly.


this should work:
http://www.mediafire.com/?iy3lny5rmyj

greg

For the hell of it, my source code:
(yes, it's extremely sloppy in the main function- that's why i'm spending the day today trying to clean it up for tomorrow so i can turn it in, with nicer, cleaner code).




#ifndef TICTACTOE_H
#define TICTACTOE_H


#include <iostream>
#include <cstring>
using namespace std;


class TicTacToe
{
public:
    TicTacToe();
   
    const static int boardSlots = 9;
   
   void displayScore();
   void displayBoard(int, bool);
   void compMove();
   void newGame();
   void resetScore();
   
   int menu();
   int playerMove();
   int firstMove();
   
   char checkWinner();
   char postGameMsg(char);
      
private:
    char pos[boardSlots];
   
    char xo;
   char x;
   char o;
   
   string name1;
   string name2;
   
   int playerOneScore;
    int playerTwoScore;
    int compScore;
    int compUser;
   int start;
   int difficulty;
   int moveFirst;
};


#endif








#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include "TicTacToe.h"
using namespace std;


/********************************CONSTRUCTOR***********************************/
TicTacToe::TicTacToe()
{
    //Set all slots to ' '
    for(int i = 0; i < boardSlots; i++)
        pos = ' ';
       
    name1 = " ";
    name2 = " ";
    compUser = 0;
    playerOneScore = 0;
    playerTwoScore = 0;
    compScore = 0;
   start = 0;
   difficulty = 0;
    xo = ' ';
   x = 'x';
   o = 'o';
}


/********************************MENU******************************************/
int TicTacToe::menu()
{
   cout << "Tic Tac Toe\n\n";
   
   //Player 1 chooses between x and o
   cout << "Please select whether you will play as x or o.\n";
   cin >> xo;
   
   while(xo != x && xo != o)
   {
       cout << "Invalid input.\n";
       cout << "Please select whether you will play as x or o.\n";
       cin >> xo;
   }
   
   //Play against computer or another player
   cout << "\nPlease select whether you will play against the computer or another user."
       << "\nType 1 to play against the computer, or 2 to play against a user.\n";
   cin >> compUser;
   
   while(compUser != 1 && compUser != 2)
   {      
       cout << "Invalid input.\n";
       cout << "\nPlease select whether you will play against the computer or another user."
       << "\nType 1 to play against the computer, or 2 to play against a user.\n";
       cin >> compUser;
   }

   //Choose difficulty if against computer
    if(compUser == 1)
   {
      cout << "\nPlease select difficulty- 1 for easy, 2 for hard.\n";
      cin >> difficulty;
      
      while(difficulty != 1 && difficulty != 2)
       {
           cout << "Invalid input.\n";
           cout << "\nPlease select difficulty- 1 for easy, 2 for hard.\n";
           cin >> difficulty;
        }
   
      cout << "\nPlease input your name.\n";
      cin >> name1;
      cout << endl;
   }

   else
   {
      cout << "\nPlease input player 1 name.\n";
      cin >> name1;
      cout << "\nPlease input player 2 name.\n";
      cin >> name2;
      cout << endl;
   }
   
   return compUser;
}


/********************************PLAYER MOVE******************************************/
int TicTacToe::playerMove()
{
    int posInp = 0;

   cout << "Please enter playing position.\n";
        cout << "Positions are as follows: \n"
             << "1   2   3\n"
             << "4   5   6\n"
             << "7   8   9\n"
           << "or type -1 to exit\n";
        cin >> posInp;
        cout << endl;
   
    //Store input for position
    while((posInp != -1 && posInp != 1 && posInp != 2 && posInp != 3 && posInp != 4 &&
      posInp != 5 && posInp != 6 && posInp != 7 && posInp != 8 && posInp != 9) ||
      (pos[posInp - 1] == x) || (pos[posInp - 1] == o))
    {
      cout << "Invalid input.\n";
        cout << "Please enter playing position.\n";
        cout << "Positions are as follows: \n"
             << "1   2   3\n"
             << "4   5   6\n"
             << "7   8   9\n"
           << "or type -1 to exit\n";
        cin >> posInp;
        cout << endl;
    }
   
    return posInp;
}


/*******************************COMPUTER MOVE******************************************/
void TicTacToe::compMove()
{
    int computerMove = 0;
   int winMove = -1;
   int blockMove = -1;
   
    //Easy settings
    if(difficulty == 1)
    {
        //Choose random move
        srand(time(0));
        computerMove = (1 + rand() % 9);
       
        //Keep guessing random slots until unoccupied slot is found
        while(pos[computerMove - 1] == x || pos[computerMove - 1] == o)
        {
           computerMove = (1 + rand() % 9);       
        }
       
        //Fill slot once an unoccupied slot is found
         //If user is x, place move as o
        xo == x ? pos[computerMove - 1] = o : pos[computerMove - 1] = x; 
    }
   
    //Hard settings
    else if(difficulty == 2)
    {
      /*Check and see if opponent has winning move possibility
        AND if computer has winning move possibility at the same time
        If so, take the winning move for the computer
        If not, but there is a single move needed to win or block, choose it*/

      /************************X*********************************/
      //Row 1 Opening
      if(pos[0] == x && pos[1] == x && pos[2] == ' ')
         xo == x ? winMove = 2 : blockMove = 2;
   
      else if(pos[0] == x && pos[1] == ' ' && pos[2] == x)
         xo == x ? winMove = 1 : blockMove = 1;

      else if(pos[0] == ' ' && pos[1] == x && pos[2] == x)
         xo == x ? winMove = 0 : blockMove = 0;

         //Row 2 Opening
      else if(pos[3] == x && pos[4] == x && pos[5] == ' ')
         xo == x ? winMove = 5 : blockMove = 5;

      else if(pos[3] == x && pos[4] == ' ' && pos[5] == x)
         xo == x ? winMove = 4 : blockMove = 4;

      else if(pos[3] == ' ' && pos[4] == x && pos[5] == x)
         xo == x ? winMove = 3 : blockMove = 3;

         //Row 3 Opening
      else if(pos[6] == x && pos[7] == x && pos[8] == ' ')
         xo == x ? winMove = 8 : blockMove = 8;

      else if(pos[6] == x && pos[7] == ' ' && pos[8] == x)    
         xo == x ? winMove = 7 : blockMove = 7;

      else if(pos[6] == ' ' && pos[7] == x && pos[8] == x)
         xo == x ? winMove = 6 : blockMove = 6;

         //Column 1 Opening
      else if(pos[0] == x && pos[3] == x && pos[6] == ' ')
         xo == x ? winMove = 6 : blockMove = 6;

      else if(pos[0] == x && pos[3] == ' ' && pos[6] == x)
         xo == x ? winMove = 3 : blockMove = 3;

      else if(pos[0] == ' ' && pos[3] == x && pos[6] == x)
         xo == x ? winMove = 0 : blockMove = 0;

         //Column 2 Opening
      else if(pos[1] == x && pos[4] == x && pos[7] == ' ')
         xo == x ? winMove = 7 : blockMove = 7;

      else if(pos[1] == x && pos[4] == ' ' && pos[7] == x)    
         xo == x ? winMove = 4 : blockMove = 4;

      else if(pos[1] == ' ' && pos[4] == x && pos[7] == x)
         xo == x ? winMove = 1 : blockMove = 1;

         //Column 3 Opening
      else if(pos[2] == x && pos[5] == x && pos[8] == ' ')
         xo == x ? winMove = 8 : blockMove = 8;

      else if(pos[2] == x && pos[5] == ' ' && pos[8] == x)
         xo == x ? winMove = 5 : blockMove = 5;

      else if(pos[2] == ' ' && pos[5] == x && pos[8] == x)
         xo == x ? winMove = 2 : blockMove = 2;

         //Diagonal LR Opening
      else if(pos[0] == ' ' && pos[4] == x && pos[8] == x)
         xo == x ? winMove = 0 : blockMove = 0;

      else if(pos[0] == x && pos[4] == ' ' && pos[8] == x)
         xo == x ? winMove = 4 : blockMove = 4;

      else if(pos[0] == x && pos[4] == x && pos[8] == ' ')
         xo == x ? winMove = 8 : blockMove = 8;

         //Diagonal RL Opening
      else if(pos[2] == ' ' && pos[4] == x && pos[6] == x)
         xo == x ? winMove = 2 : blockMove = 2;

      else if(pos[2] == x && pos[4] == ' ' && pos[6] == x)
         xo == x ? winMove = 4 : blockMove = 4;

      else if(pos[2] == x && pos[4] == x && pos[6] == ' ')
         xo == x ? winMove = 6 : blockMove = 6;

      
      /************************O*********************************/
      //Row 1 Opening
      if(pos[0] == o && pos[1] == o && pos[2] == ' ')
         xo == x ? winMove = 2 : blockMove = 2;
   
      else if(pos[0] == o && pos[1] == ' ' && pos[2] == o)
         xo == x ? winMove = 1 : blockMove = 1;

      else if(pos[0] == ' ' && pos[1] == o && pos[2] == o)
         xo == x ? winMove = 0 : blockMove = 0;

         //Row 2 Opening
      else if(pos[3] == o && pos[4] == o && pos[5] == ' ')
         xo == x ? winMove = 5 : blockMove = 5;

      else if(pos[3] == o && pos[4] == ' ' && pos[5] == o)
         xo == x ? winMove = 4 : blockMove = 4;

      else if(pos[3] == ' ' && pos[4] == o && pos[5] == o)
         xo == x ? winMove = 3 : blockMove = 3;

         //Row 3 Opening
      else if(pos[6] == o && pos[7] == o && pos[8] == ' ')
         xo == x ? winMove = 8 : blockMove = 8;

      else if(pos[6] == o && pos[7] == ' ' && pos[8] == o)    
         xo == x ? winMove = 7 : blockMove = 7;

      else if(pos[6] == ' ' && pos[7] == o && pos[8] == o)
         xo == x ? winMove = 6 : blockMove = 6;

         //Column 1 Opening
      else if(pos[0] == o && pos[3] == o && pos[6] == ' ')
         xo == x ? winMove = 6 : blockMove = 6;

      else if(pos[0] == o && pos[3] == ' ' && pos[6] == o)
         xo == x ? winMove = 3 : blockMove = 3;

      else if(pos[0] == ' ' && pos[3] == o && pos[6] == o)
         xo == x ? winMove = 0 : blockMove = 0;

         //Column 2 Opening
      else if(pos[1] == o && pos[4] == o && pos[7] == ' ')
         xo == x ? winMove = 7 : blockMove = 7;

      else if(pos[1] == o && pos[4] == ' ' && pos[7] == o)    
         xo == x ? winMove = 4 : blockMove = 4;

      else if(pos[1] == ' ' && pos[4] == o && pos[7] == o)
         xo == x ? winMove = 1 : blockMove = 1;

         //Column 3 Opening
      else if(pos[2] == o && pos[5] == o && pos[8] == ' ')
         xo == x ? winMove = 8 : blockMove = 8;

      else if(pos[2] == o && pos[5] == ' ' && pos[8] == o)
         xo == x ? winMove = 5 : blockMove = 5;

      else if(pos[2] == ' ' && pos[5] == o && pos[8] == o)
         xo == x ? winMove = 2 : blockMove = 2;

         //Diagonal LR Opening
      else if(pos[0] == ' ' && pos[4] == o && pos[8] == o)
         xo == x ? winMove = 0 : blockMove = 0;

      else if(pos[0] == o && pos[4] == ' ' && pos[8] == o)
         xo == x ? winMove = 4 : blockMove = 4;

      else if(pos[0] == o && pos[4] == o && pos[8] == ' ')
         xo == x ? winMove = 8 : blockMove = 8;

         //Diagonal RL Opening
      else if(pos[2] == ' ' && pos[4] == o && pos[6] == o)
         xo == x ? winMove = 2 : blockMove = 2;

      else if(pos[2] == o && pos[4] == ' ' && pos[6] == o)
         xo == x ? winMove = 4 : blockMove = 4;

      else if(pos[2] == o && pos[4] == o && pos[6] == ' ')
         xo == x ? winMove = 6 : blockMove = 6;


       /**********Decide nonrandom position*********************/

        //If a winning move is available, take it
      if(winMove != -1)         
         xo == x ? pos[winMove] = o : pos[winMove] = x;

      //If a blocking move is available, take it
      else if(blockMove!= -1)
         xo == x ? pos[blockMove] = o : pos[blockMove] = x;
      
      //If there is a block AND an opening to win, choose the win over the block

      else if(winMove != -1 && winMove != -1)
         xo == x ? pos[winMove] = o : pos[winMove] = x;


      /****If no case like these exist, choose a random open location to move****/
      else
      {
         //Choose random move
         srand(time(0));
         computerMove = (1 + rand() % 9);
          
         //Keep guessing random slots until unoccupied slot is found
         while(pos[computerMove - 1] == x || pos[computerMove - 1] == o)
         {
            computerMove = (1 + rand() % 9);       
         }
          
         //Fill slot once an unoccupied slot is found
            //If user is x, place move as o
         xo == x ? pos[computerMove - 1] = o : pos[computerMove - 1] = x;
      }
    }
   
}


/*******************************DISPLAY SCORE******************************************/
void TicTacToe::displayScore()
{
    cout << name1 << "'s score: " << playerOneScore << "\n";
    compUser == 1 ?
        cout << "Computer's score: " << compScore << "\n"
            : cout << name2 << "'s score: " << playerTwoScore << "\n";
    cout << endl;
}


/*******************************DISPLAY BOARD******************************************/
void TicTacToe::displayBoard(int m, bool pl2T)
{
    //Occupy square with x or o
   if(compUser == 1)
      pos[m - 1] = (xo == x ? x : o);

   else if(compUser == 2)
   {
      if(pl2T)
         pos[m - 1] = (xo == x ? o : o);
      else
         pos[m - 1] = (xo == x ? x : x);
   }



    //Display all rows and columns of board
    //     Column 1          Column 2          Column 3
    cout << "  " << pos[0] << " | " << pos[1] << " | " << pos[2] << endl << "  " << "---------" << endl; //Row 1
    cout << "  " << pos[3] << " | " << pos[4] << " | " << pos[5] << endl << "  " << "---------" << endl; //Row 2
    cout << "  " << pos[6] << " | " << pos[7] << " | " << pos[8] << endl; //Row 3
   
    cout << "\n\n";   
}


/*******************************CHECK FOR A WINNER******************************************/
char TicTacToe::checkWinner()
{
        //Check x win   
    if( //Horizontal
        (pos[0] == x && pos[1] == x && pos[2] == x) ||
        (pos[3] == x && pos[4] == x && pos[5] == x) ||
        (pos[6] == x && pos[7] == x && pos[8] == x) ||
        //Vertical
        (pos[0] == x && pos[3] == x && pos[6] == x) ||   
        (pos[1] == x && pos[4] == x && pos[7] == x) ||
        (pos[2] == x && pos[5] == x && pos[8] == x) ||
        //Diagonal
        (pos[0] == x && pos[4] == x && pos[8] == x) ||
        (pos[2] == x && pos[4] == x && pos[6] == x))
    {
        if(xo == x)
                playerOneScore++;
        else
         compUser == 1 ? compScore++ : playerTwoScore++;
               
        return 'x';
   } 
   
      
      //Check o win
   else if
      //Horizontal
      ((pos[0] == o && pos[1] == o && pos[2] == o) ||
        (pos[3] == o && pos[4] == o && pos[5] == o) ||
        (pos[6] == o && pos[7] == o && pos[8] == o) ||
        //Vertical
        (pos[0] == o && pos[3] == o && pos[6] == o) ||   
        (pos[1] == o && pos[4] == o && pos[7] == o) ||
        (pos[2] == o && pos[5] == o && pos[8] == o) ||
        //Diagonal
        (pos[0] == o && pos[4] == o && pos[8] == o) ||
        (pos[2] == o && pos[4] == o && pos[6] == o))
        {
           if(xo == o)
                playerOneScore++;
           else
                compUser == 1 ? compScore++ : playerTwoScore++;
               
           return 'o';
       
      }

   //Check tie
   else if
      ((pos[0] == x || pos[0] == o) &&
      (pos[1] == x || pos[1] == o) &&
      (pos[2] == x || pos[2] == o) &&
      (pos[3] == x || pos[3] == o) &&
      (pos[4] == x || pos[4] == o) &&
      (pos[5] == x || pos[5] == o) &&
      (pos[6] == x || pos[6] == o) &&
      (pos[7] == x || pos[7] == o) &&
      (pos[8] == x || pos[8] == o))
   {
      return 't';
   }

   //Return nothing for a default case of nobody winning
   else
   {
      return ' ';
   }
}



/*******************************POST GAME MESSAGE********************************/
char TicTacToe::postGameMsg(char w)
{
   char postGameInp = ' ';

   //X Wins
   if(w == 'x')
   {
      //X is player one
       if(xo == x)
       {
          cout << name1 << " wins!\n";
       }
       
       //X is computer
       else
       {
         compUser == 1 ? cout << "You lose.\n" : cout << name2 << " wins!\n";
       }
   }
   
   //O Wins
   if(w == 'o')
   {
      //O is player one
       if(xo == o)
       {
          cout << name1 << " wins!\n";
       }
       
       //O is computer
       else
       {
          compUser == 1 ? cout << "You lose.\n" : cout << name2 << " wins!\n";
       }
   }

   //Tie game
   if(w == 't')
   {
      cout << "Tie game.\n";
   }
   
   //Post-game message
   while(postGameInp != 'P' && postGameInp != 'p' &&
        postGameInp != 'M' && postGameInp != 'm' &&
        postGameInp != 'Q' && postGameInp != 'q')
   {
      cout << "Do you want to play another game?\n"
          << "Type 'P' to play again, 'M' to return to the menu,\n"
          << "or 'Q' to quit.\n";
      cin >> postGameInp;
   }

   return postGameInp;
}


/**************************************NEW GAME***************************/
void TicTacToe::newGame()
{
    system("cls");
    for(int i = 0; i < boardSlots; i++)
    {
       pos = ' '; 
    }
}


/************************************RESET SCORE**************************/
void TicTacToe::resetScore()
{
   playerOneScore = 0;
   playerTwoScore = 0;
   compScore = 0;
}




/******************************FIRST MOVE********************************/
int TicTacToe::firstMove()
{
    //Decide who makes the first move
    if(compUser == 1)
    {
       cout << "Who will make the first move?\n";
       cout << "Type 1 for " << name1 << " or 2 for Computer.\n";
       cin >> moveFirst;
    }
   
    return moveFirst;
}











/*****************************************************************************
TicTacToe

Description: This program lets you play the game of TicTacToe
Author: Greg Cook
*****************************************************************************/


#include <iostream>
#include <cstring>
#include "TicTacToe.h"
using namespace std;


int main()
{   
   int move = 0;
   int moveFirst = 0;
   char win = ' ';
   int compUser = 0;
   bool newGame = false;
   bool pl2Turn = false;
   char resetScore = ' ';
   char menuGameSel = 'M'; //this variable stores whether player is in menu
                            //or game, and controls where they go   
   TicTacToe game;


   /******************************MENU***********************************/
   while(menuGameSel == 'M' || menuGameSel == 'm')
   {
       compUser = game.menu();
       moveFirst = game.firstMove();
       system("cls");
        game.displayScore();
       game.displayBoard(move, pl2Turn);
       menuGameSel = 'P';

   /******************************GAME LOOP***********************************/
   
       //Player 1 vs. Computer
       if(compUser == 1)
       {
            while(menuGameSel == 'P' || menuGameSel == 'p')
            {
                 //Clear screen and positions in a new game
                 if(newGame == true)
                 {
                    move = 0;
                    game.newGame();
                    game.displayScore();
                    game.displayBoard(move, pl2Turn);
                    newGame = false;
                 }

             //Player goes first if they choose to
                if(moveFirst == 1) //Get player move
                   move = game.playerMove();
               
                else
                   moveFirst = 1; //set back to 1 so while this turn is skipped, next time, player gets to make a move
   
             //Exit in case of -1 input
             if(move == -1)
             {
                return 0;
             }
   
                system("cls");
               
                //Check player win
             game.displayBoard(move, pl2Turn);
             system("cls");
                win = game.checkWinner();

               
             //If it's a win or tie, display board and go to postgame option
                if(win == 'o' || win == 'x' || win == 't')
                {
                   game.displayScore();
                   game.displayBoard(move, pl2Turn);
                   menuGameSel = game.postGameMsg(win);

                   
                   //Selection: P
                   if(menuGameSel == 'P' || menuGameSel == 'p')
                   {
                      newGame = true;
                      system("cls");
                   }//end if
                   
               
                   //Selection: M
                   else if(menuGameSel == 'M' || menuGameSel == 'm')
                   {
                      //Ask if they'd like to keep the score       
                      cout << "\nWould you like to keep the score?\n";
                      cout << "'Y' for 'yes', 'N' for 'no, reset score to 0'.\n";
                      cin >> resetScore;
                     
                      //Invalid input checking
                      while(resetScore != 'Y' && resetScore != 'y' &&
                                resetScore != 'N' && resetScore != 'n')
                      {
                         cout << "\nWould you like to keep the score?\n";
                         cout << "'Y' for 'yes', 'N' for 'no, reset score to 0'.\n";
                         cin >> resetScore;
                      }
                     
                      //Y: Keep score
                      if(resetScore == 'Y' || resetScore == 'y')
                      {
                         cout << "\nScore was not reset.\n";
                         system("PAUSE");
                      }
                     
                      //N: Reset score
                      else if(resetScore == 'N' || resetScore == 'n')
                      {
                         game.resetScore();
                         cout << "\nScore was reset.\n"; 
                         system("PAUSE");
                      }
                     
                    //Q: Quit game
                     else if(menuGameSel == 'Q' || menuGameSel == 'q')
                     {
                        return 0;
                     }
                     
                   }//end elseif
                   
                   newGame = true;
                   system("cls");
                }//endif
               
               
             //If not, continue by letting computer move
             else
             {
                game.compMove();
                game.displayScore();
                   game.displayBoard(move, pl2Turn);
   
                //Check computer win
                win = game.checkWinner();
                
             //If it's a win, display board and go to postgame option
                if(win == 'o' || win == 'x' || win == 't')
                {
                   system("cls");
                   game.displayScore();
                   game.displayBoard(move, pl2Turn);
                   menuGameSel = game.postGameMsg(win);
                   
                   //Selection: P
                   if(menuGameSel == 'P' || menuGameSel == 'p')
                   {
                      newGame = true;
                      system("cls");
                   }//end if
                   
               
                   //Selection: M
                   else if(menuGameSel == 'M' || menuGameSel == 'm')
                   {
                      //Ask if they'd like to keep the score       
                      cout << "\nWould you like to keep the score?\n";
                      cout << "'Y' for 'yes', 'N' for 'no, reset score to 0'.\n";
                      cin >> resetScore;
                     
                      //Invalid input checking
                      while(resetScore != 'Y' && resetScore != 'y' &&
                                resetScore != 'N' && resetScore != 'n')
                      {
                         cout << "\nWould you like to keep the score?\n";
                         cout << "'Y' for 'yes', 'N' for 'no, reset score to 0'.\n";
                         cin >> resetScore;
                      }
                     
                      //Y: Keep score
                      if(resetScore == 'Y' || resetScore == 'y')
                      {
                         cout << "\nScore was not reset.\n";
                         system("PAUSE");
                      }
                     
                      //N: Reset score
                      else if(resetScore == 'N' || resetScore == 'n')
                      {
                         game.resetScore();
                         cout << "\nScore was reset.\n"; 
                         system("PAUSE");
                      }
                     
                    //Q: Quit game
                     else if(menuGameSel == 'Q' || menuGameSel == 'q')
                     {
                        return 0;
                     }
                     
                   }//end elseif
                   
                   newGame = true;
                   system("cls");
             }//end else, continue loop
               
            }//end loop
         } //endif   
    }
       


    //Player 1 vs. Player 2
    else if(compUser == 2)
    {
      while(menuGameSel == 'P' || menuGameSel == 'p')
        {
                 //Clear screen and positions in a new game
                 if(newGame == true)
                 {
                    move = 0;
                    game.newGame();
                    game.displayScore();
                    game.displayBoard(move, pl2Turn);
                    newGame = false;
                 }
                 
                //Get player move
                move = game.playerMove();
   
             //Exit in case of -1 input
             if(move == -1)
             {
                return 0;
             }
   
                system("cls");
               
                //Check player win
             game.displayBoard(move, pl2Turn);
             system("cls");
                win = game.checkWinner();

               
             //If it's a win or tie, display board and go to postgame option
                if(win == 'o' || win == 'x' || win == 't')
                {
                   game.displayScore();
                   game.displayBoard(move, pl2Turn);
                   menuGameSel = game.postGameMsg(win);

                   
                   //Selection: P
                   if(menuGameSel == 'P' || menuGameSel == 'p')
                   {
                      newGame = true;
                      system("cls");
                   }//end if
                   
               
                   //Selection: M
                   else if(menuGameSel == 'M' || menuGameSel == 'm')
                   {
                      //Ask if they'd like to keep the score       
                      cout << "\nWould you like to keep the score?\n";
                      cout << "'Y' for 'yes', 'N' for 'no, reset score to 0'.\n";
                      cin >> resetScore;
                     
                      //Invalid input checking
                      while(resetScore != 'Y' && resetScore != 'y' &&
                                resetScore != 'N' && resetScore != 'n')
                      {
                         cout << "\nWould you like to keep the score?\n";
                         cout << "'Y' for 'yes', 'N' for 'no, reset score to 0'.\n";
                         cin >> resetScore;
                      }
                     
                      //Y: Keep score
                      if(resetScore == 'Y' || resetScore == 'y')
                      {
                         cout << "\nScore was not reset.\n";
                         system("PAUSE");
                      }
                     
                      //N: Reset score
                      else if(resetScore == 'N' || resetScore == 'n')
                      {
                         game.resetScore();
                         cout << "\nScore was reset.\n"; 
                         system("PAUSE");
                      }
                     
                    //Q: Quit game
                     else if(menuGameSel == 'Q' || menuGameSel == 'q')
                     {
                        return 0;
                     }
                     
                   }//end elseif
                   
                   newGame = true;
                   system("cls");
                }//endif
               
               
             //If not, continue by letting player 2 move
             else
             {
               system("cls");
               game.displayScore();
               
                    game.displayBoard(move, pl2Turn);
               
                move = game.playerMove();
               system("cls");
               pl2Turn = true;
                game.displayScore();
                   game.displayBoard(move, pl2Turn);
               pl2Turn = false;
   
                //Check computer win
                win = game.checkWinner();
                
             //If it's a win, display board and go to postgame option
                if(win == 'o' || win == 'x' || win == 't')
                {
                   system("cls");
                   game.displayScore();
                   game.displayBoard(move, pl2Turn);
                   menuGameSel = game.postGameMsg(win);
                   
                   //Selection: P
                   if(menuGameSel == 'P' || menuGameSel == 'p')
                   {
                      newGame = true;
                      system("cls");
                   }//end if
                   
               
                   //Selection: M
                   else if(menuGameSel == 'M' || menuGameSel == 'm')
                   {
                      //Ask if they'd like to keep the score       
                      cout << "\nWould you like to keep the score?\n";
                      cout << "'Y' for 'yes', 'N' for 'no, reset score to 0'.\n";
                      cin >> resetScore;
                     
                      //Invalid input checking
                      while(resetScore != 'Y' && resetScore != 'y' &&
                                resetScore != 'N' && resetScore != 'n')
                      {
                         cout << "\nWould you like to keep the score?\n";
                         cout << "'Y' for 'yes', 'N' for 'no, reset score to 0'.\n";
                         cin >> resetScore;
                      }
                     
                      //Y: Keep score
                      if(resetScore == 'Y' || resetScore == 'y')
                      {
                         cout << "\nScore was not reset.\n";
                         system("PAUSE");
                      }
                     
                      //N: Reset score
                      else if(resetScore == 'N' || resetScore == 'n')
                      {
                         game.resetScore();
                         cout << "\nScore was reset.\n"; 
                         system("PAUSE");
                      }
                     
                    //Q: Quit game
                     else if(menuGameSel == 'Q' || menuGameSel == 'q')
                     {
                        return 0;
                     }
                     
                   }//end elseif
                   
                   newGame = true;
                   system("cls");
             }//end else, continue loop
               
            }//end loop
         } //endif   
    }
   
   
   

    }//endwhile
   
   return 0;
}

Tapio Dmitriyevich

#8
I remember, at the age of 15 I wrote a labyrinth software for my Basic programmable Casio computer/calculator... I invented binary/Basic by myself without a manual. No Internet ;) Every point had 4 directions of course, and the state of "can go north/east/south/west" was set binary by the sum of 2^(0-3)... Was fun.
Old times, when "peek" and "poke" were the geeks tools ;)
On an Apricot F1 computer I wrote a "Wolfram Mathematica",,, erm well, a minor version. No parser, I had to enter the functions into the src code, but hey: the thing was able to visualize functions and could even zoom! Painting a complicated function like "Y=sin(2x)+1 made the program draw the sine wave in unbelievable 2 seconds! :D

Today I'm sad I lost my old programs....

greg