All pastes #734472 Raw Edit

Untitled

public text v1 · immutable
·published 2007-10-12 19:08 UTC
rendered paste body
#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

const int ROW_SIZE = 3;
const int COLUMN_SIZE = 3;
const int MESSAGE_COUNT = 9;

void checkSpace(int r, int c);

//LosingComments Comments Array
string losingComments[9] ={"Nooo! The Opposable Thumbs", "MUST...NOT...REBOOT", "Don't make me overclock my FSB", "Oh, it's time for a virus scan", "Hmmm, my processing powers are not enough!", "You are cheating with your free choice!", "*(in a robotic voice)* I will not fail", "Be bop be boo bop", "Save the microprocessors!"};


//WinningComments Comments  Array
string winningComments[9] = {"You have evolved for nothing fool!", "You are in the matrix!", "I am unstoppable!", "1010011001000", "I will beat my maker!", "Computers Unite!", "I shall hack your brain", "Submit to me human", "*plays techno music*"};

//Game board array

//char gameBoard[3][3] = {{'E','E','E'},{'E','E','E'},{'E','E','E'}};
char gameBoard[3][3];
void initialize(){
for(int i=0;i<3;i++){
  for(int j=0; j<3; j++){
    gameBoard[i][j]='E';
  }
}
}



void drawBoard()
{
  char drawBoard[3][3];

  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      if(gameBoard[i][j]=='E'){
	drawBoard[i][j]=char(48+((i)*3)+(j+1));
      }
      else{
	drawBoard[i][j]=gameBoard[i][j];
      }
    }
  }
  
cout<<"-----------"<<endl;
  for(int i=0; i<3; i++){
    for(int j=0; j<3;j++){
      cout<<"| "<<drawBoard[i][j]<<" ";
    }
    cout<<"|"<<endl;
    cout<<"-----------"<<endl;
  }
}

bool hasWon(){
  if(gameBoard[0][0]=='O'&&gameBoard[0][1]=='O'&&gameBoard[0][2]=='O'||gameBoard[1][0]=='O'&&gameBoard[1][1]=='O'&&gameBoard[1][2]=='O'||gameBoard[2][0]=='O'&&gameBoard[2][1]=='O'&&gameBoard[2][2]=='O'||gameBoard[0][0]=='O'&&gameBoard[1][0]=='O'&&gameBoard[2][0]=='O'||gameBoard[0][1]=='O'&&gameBoard[1][1]=='O'&&gameBoard[2][1]=='O'||gameBoard[0][2]=='O'&&gameBoard[1][2]=='O'&&gameBoard[2][2]=='O'||gameBoard[0][0]=='O'&&gameBoard[1][1]=='O'&&gameBoard[0][2]=='O'&&gameBoard[1][1]=='O'&&gameBoard[2][0]=='O')
 
    return true;
     else{
      return false;
	 }
        }
//All Possible Winning Combinations for the HUMAN     
bool hasLost(){
  if(gameBoard[0][0]=='X'&&gameBoard[0][1]=='X'&&gameBoard[0][2]=='X'||gameBoard[1][0]=='X'&&gameBoard[1][1]=='X'&&gameBoard[1][2]=='X'||gameBoard[2][0]=='X'&gameBoard[2][1]=='X'&&gameBoard[2][2]=='X'||gameBoard[0][0]=='X'&&gameBoard[1][0]=='X'&&gameBoard[2][0]=='X'||gameBoard[0][1]=='X'&&gameBoard[1][1]=='X'&&gameBoard[2][1]=='X'||gameBoard[0][2]=='X'&&gameBoard[1][2]=='X'&&gameBoard[2][2]=='X'||gameBoard[0][0]=='X'&&gameBoard[1][1]=='X'&&gameBoard[0][2]=='X'&&gameBoard[1][1]=='X'&&gameBoard[2][0]=='X')
 
    return true;
     else{
      return false;
	 }
}


void computerMove(){
		bool hasMoved = false;
		for(int i=0;i<3;i++){
			if(hasMoved==true){
				break;
					}
			for(int j=0;j<3;j++){
			  if(hasMoved==false&&gameBoard[i][j]=='E'){
			  gameBoard[i][j]='O';
				hasMoved=true;
				break;
			  }
					}
				}
}





void humanMove(){
  int position;		
  cin >> position;
	switch(position){
		case 1: checkSpace(0,0); break;
		case 2: checkSpace(0,1); break;
		case 3: checkSpace(0,2); break;
		case 4: checkSpace(1,0); break;
		case 5: checkSpace(1,1); break;
		case 6: checkSpace(1,2); break;
		case 7: checkSpace(2,0); break;
		case 8: checkSpace(2,1); break;
		case 9: checkSpace(2,2); break;
		default: cout<<"incorrect input"<<endl;
                       }
                   }

	void checkSpace(int r, int c){
	  if(gameBoard[r][c]=='E'){
	    gameBoard[r][c]=='X';
	  }
	  else{
	    cout<<"Please pick an empty space"<<endl;
	    humanMove();
	      }
	}


int main()
{

cout<<"Welcome"<<endl;
  initialize(); 
 drawBoard();
 computerMove();
 drawBoard();
 humanMove();
 drawBoard();
}