//*********************************************************************************
//Program name: Tic Tac Toe by Diep Ho
//**********************************************************************************
//Input:4 dimension Array,numeric data
//Output:3 or 4 array units in a row loaded by the same data
//*****************************************************************************************
//Description:
//This program will draw a tic-tac-toe BOARD,64 boxes x 4 cubes,four dimensions: Cube,plane,
//row, and column using four dimension array Bo[CU][z][y][x], CU=z=y=x=4.
//The players suppose to choose Cube, mark the boxes using inputs as Plane, Row, and Column.
//The programe will convert the inputs into coordinates z,y,x of the boxes.
//The boxes are marked as O or X or Y or Z by player 1, 2 , 3 or 4.
//The game will be stopped anytime or there is a winner who marks 4 boxes in a row in the
//same cube. Before playing again, the players should clear the previous play datas.
//**********************************************************************************
#include<iostream.h> //preprocessor
//**********************************************************************************
// function prototype
//**********************************************************************************
void MainMenu(int Dimension,char Bo[4][4][4][4]);
void PlayingGame(int Dimension,char Bo[4][4][4][4],int numP,int player,int CU,int P,int R,int C);
void DisPlay2Player(int player);
void DisPlay3Player(int player);
void DisPlay4Player(int player);
void BullsEye(char Bo[4][4][4][4],int player,int CU,int z,int y,int x);
int BlankBox(char Bo[4][4][4][4], int CU,int z,int y,int x);
void printWelcome(int Dimension,char Bo[4][4][4][4],int mode);
int changeVue(int mode);
int changeCUBE(int CB);
void printHowToPlay(int Dimension);
char winnerGame(int Dimension,char Bo[4][4][4][4],int CB,int CU);
char winnerGame1(char Bo[4][4][4][4]);
char winnerGame2(char Bo[4][4][4][4],int CB,int CU);
void playing_modeC(int CB);
void playing_mode(int mode);
void playing_mode0(int mode);
void playing_mode1(int mode);
void playing_mode2(int mode);
char menu(int Dimension,char ShowMenu);
void DisPlayPlayer(int numP,int player);
void BeginP(int Dimension,int mode,int CB,char Bo[4][4][4][4]);
void DisplayError();
void ResultMess(int Dimension,char Bo[4][4][4][4],int numP,int player);
void DisplayWinner(int Dimension,char Bo[4][4][4][4]);
char clearData(char Bo[4][4][4][4],int CU);
void purgeData();
int convertCBCU(int CB,int CU);
int PlayerTakeTurn(int numP,int player);
void diagram3(char Bo[4][4][4][4],int P,int R,int C);
void diagram4(char Bo[4][4][4][4],int CB,int CU,int P,int R,int C);
//**********************************************************************************
// datatype, input
//**********************************************************************************
const int TRUE=1;
const int FALSE=0;
int Dimension,mode,numP,player,CB, CU,P,R,C,z,y,x;
char ShowMenu;
char Bo[4][4][4][4];
//**********************************************************************************
// Main Function
//**********************************************************************************
void main ()
{ //start main function
while(TRUE) //start while
{
clearData(Bo,CU); //load array with blank
char choose; //local variable
cout<<"----------------WELCOME TO MULTI-DIMENSION TIC TAC TOE------------------";
cout<<" By Diep Ho\n";
cout<<"\n\n\n\n\n\n\n";
cout<<"\t\t\t\tPlease choose: \n"; //message
cout<<"\t\t\t\t--------------\n";
cout<<"\t\t\t\tA. 3 dimensions\n"; //message
cout<<"\t\t\t\tB. 4 dimensions\n"; //message
cout<<"\t\t\t\tC. Exit\n"; //message
cout<<"\t\t\t\t";
cin>>choose; //read input
if((choose == 'A') || (choose == 'a'))
{ //start if
MainMenu(1,Bo); //3 dimension game
break;
} //end if
if((choose == 'B') || (choose == 'b'))
{ //start if
MainMenu(2,Bo); //4 dimension game
break;
} //end if
if ((choose =='C') || (choose =='c'))
{
break;
}
else
{
cout<<"\n\n\n\n\n\n\n\n";
cout<<"\t\t\t\tWrong input!"<<endl;
cout<<"\t\t\t\tPlease re-enter: \n\n\n";
continue;
}
} //end while
} //end main function
void MainMenu(int Dimension,char Bo[4][4][4][4])
{
do //start do-while loop
{
printWelcome( Dimension,Bo,mode); //welcome message
ShowMenu = menu(Dimension,ShowMenu); //main menu
switch(ShowMenu) //switch the input
{ //start switch
case 'A':
case 'a':
numP=2; //number of players
PlayingGame(Dimension,Bo,numP,player,CU,P,R,C); //function call
break;
case 'B':
case 'b':
numP=3; //number of players
PlayingGame(Dimension,Bo,numP,player,CU,P,R,C); //3 player game
break;
case 'C':
case 'c':
numP=4; //number of players
PlayingGame(Dimension,Bo,numP,player,CU,P,R,C); //4 player game
break;
case 'D':
case 'd':
mode=changeVue(mode); //change Vue
break;
case 'E':
case 'e':
if(Dimension==1)
{
continue; //input has no effect on 3
}else //dimension game
{
CB=changeCUBE(CB); //change CUBE
}
break;
case 'F':
case 'f':
clearData(Bo,CU); //clear previous data
break; //on the CUBE that showed
//on the screen
} //end switch
}while(ShowMenu != 'Q' && ShowMenu != 'q'); //condition to end the game
//end do-while loop
cout<<"\n\n\n\n\n\n\n\n\n\n";
cout<<"\t\t THANK YOU FOR PLAYING TIC TAC TOE";//SEND OUT THANKS MESSAGE
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n";
} //end main function
//**********************************************************************************
//
// Function Definition
//
//**********************************************************************************
//function will display the first part
void printWelcome(int Dimension,char Bo[4][4][4][4],int mode)
{ //of the first window
cout<<"--------------------WELCOME TO "; //print welcome
if(Dimension==1)
cout<<"THREE"; //either 3 or 4 dimension
else
cout<<"FOUR ";cout<<"-DIMENSION TIC TAC TOE----------------------";
cout<<" By Diep Ho\n";
if(Dimension==1){
diagram3(Bo,P,R,C);cout<<"\n"; //show 3 dimendion diagram
}else{
diagram4(Bo,CB,CU,P,R,C); //show 4 dimension diagram
}
cout<<"--------------------------------------------------------------------------------";
if(Dimension==1){
cout<<"\t\t";
}else{
cout<<"\t\t\t";
playing_modeC(CB); //show different Cube
}
cout<<"\t\t ";
playing_mode(mode); //show different vues
cout<<"--------------------------------------------------------------------------------";
cout<<"-------------------------------------MENU---------------------------------------";
} //end function
char menu(int Dimension,char ShowMenu) //display main menu
{
cout<<"\t\tA. 2 Players"; //2 player game
cout<<"\t\t D. Change VUE"; //changing Vue
cout<<"\n\t\tB. 3 Players"; //3 player game
cout<<"\t\t E. ";if(Dimension==1)
cout<<"You are in XYZ SYSTEM";
else
cout<<"Change CUBE";
cout<<"\n\t\tC. 4 Players"; //4 player game
cout<<"\t\t F. ";if(Dimension==1)
cout<<"Clear data";
else
cout<<"Clear data (in each CUBE)";
cout<<"\n\t\tQ. Quit"; //quit the program
cout<<"\t\t\t (Before you play again)"; //it won't run if not clear data
cout<<"\n\t\t\tPlease select :"; //message
cin>>ShowMenu; //read inputs
cout<<"\n\n";
return (ShowMenu); //return to main function
} //end function
int changeCUBE(int CB) //rotate 4 modes of the CUBE
{
if(CB==0)
CB=1;
else
if(CB==1)
CB=2;
else //CB from 0 to 3
if(CB==2) //there are 4 CUBE that match
CB=3; //4 CB modes
else
CB=0;
return (CB); //return to call function
} //end function
int changeVue(int mode) //function definition
{ //change VUE by changing mode
if (mode==0)
mode=1;
else
if (mode == 1)
mode=2; //there are 3 XY vue, XZ vue
else //ZY vue that match with
mode=0; //with each mode
return(mode); //return to function call
} //end function
//function definition 2 player game
void PlayingGame(int Dimension,char Bo[4][4][4][4],int numP,int player,int CU,int P,int R,int C)
{
player=1; //player 1 starts first
while(!winnerGame(Dimension,Bo,CB,CU)) //start while loop, the game continues unless
{ //there is a winner
BeginP(Dimension,mode,CB,Bo); //print out the first diagram ready to play
DisPlayPlayer(numP,player); //display which player is ON
if(Dimension==1)
{
cin>>P>>R>>C;
while((!cin.good()) || (P > 2) || (P < -3) || (R > 2) || (R < -3) || (C > 2) || (C < -3))
{
cout<<"\t\t\tWRONG INPUT!!! Please re-enter: ";
purgeData(); //clear the junk data
cin>>P>>R>>C; //read inputs
} //endwhile
}else
{
cin>>P>>R>>C; //read inputs
while((!cin.good()) || (P > 3) || (P < -3) || (R > 3) || (R < -3) || (C > 3) || (C < -3))
{
cout<<"\t\t\tWRONG INPUT!!! Please re-enter: ";
purgeData(); //clear the junk data
cin>>P>>R>>C; //read inputs
} //endwhile
} //endif
if(P == -1) break;
if(P == -2){ //condition //start if
mode=changeVue(mode); //change VUE during playing //using input of the player ON
continue; //continue loop
} //end if
if(P == -3){ //conditiion
if(Dimension ==1)
{
continue; //this input has no effect on 3 dimension game
}else
{
CB=changeCUBE(CB); //rotate the CUBE from CUBE 0 to CUBE 3
continue;
} //during playing, continue loop
} //endif
if (mode==1){ //convert Plane,Row,Column depend on VUE //into coordinates z,y,x //start if
z=C;y=R;x=P; //VUE = XY Plane
}else{ //convert Plane,Row,Column depend on VUE
if(mode==2){ //into coordinates z,y,x //start if
z=R;y=P;x=C; //VUE = XZ Plane
}else{
z=P;y=R;x=C; //VUE = ZY Plane
} //end if
} //end if
CU=convertCBCU(CB,CU); //function call;
if(BlankBox(Bo,CU,z,y,x)) //if the box is empty
{ //star if
BullsEye(Bo,player,CU,z,y,x);//the box will be marked
}else{
DisplayError(); //display error
continue; //if the box is not empty
} //end if
player = PlayerTakeTurn(numP,player);//players take turn to play
} //end while
ResultMess(Dimension,Bo,numP,player); //send out result message
} //end PlayingGame function
void BeginP(int Dimension,int mode,int CB,char Bo[4][4][4][4])//function definition
{
cout<<"\n\n\n\n\n\n\n"; //scroll of the screen to make it clear
printHowToPlay(Dimension);//display the message how to play
cout<<"\n--------------------------------------------------------------------------------";
if(Dimension == 1){
cout<<"\t";
}else{
cout<<"\t\t ";playing_modeC(CB); //show CUBE that is on
}
cout<<"\t\t\t";
playing_mode(mode); //show Vue that is on
cout<<"--------------------------------------------------------------------------------";
if(Dimension==1)
diagram3(Bo,P,R,C); //function call will display tic tac toe diagram
else
diagram4(Bo,CB,CU,P,R,C);
cout<<"\n\n--------------------------------------------------------------------------------";
cout<<"\n";
} //end function definition
void diagram3(char Bo[4][4][4][4],int P,int R,int C)
{
cout<<"\n\n"; //print row name and plane name
cout<<"\t ";playing_mode1(mode);cout<<"\t\t\t (";playing_mode0(mode);cout<<" Plane)\n";
cout<<"\t | "<<" Plane 0\t Plane 1\t Plane 2";
cout<<"\n\t | -------------\t "<<"------------- "<<"-------------\n";
for (P=2;P>=0;P--) //change Row, smaller row at the bottom
{
cout<<"\t Row|"<<P<<""; //mark the row #
for(R=0;R<3;R++) //change plane or column
{
for(C=0;C<3;C++) //change plane or column
{
if(mode==1)
cout<<" | "<<Bo[0][C][P][R]; //side VUE
else
if(mode==2)
cout<<" | "<<Bo[0][P][R][C]; //top VUE
else
cout<<" | "<<Bo[0][R][P][C]; //front VUE
}
cout<<" |"<<" "; //print end mark of a plane
}
cout<<"\n\t | -------------\t "<<"------------- "<<"-------------\n";
}
cout<<"\t | 0 1 2 0 1 2 0 1 2 <== Column";
cout<<"\n\t |------------------------------------------------------- ";
playing_mode2(mode);cout<<"\n"; //print Column name
}
void diagram4(char Bo[4][4][4][4],int CB,int CU,int P,int R,int C)
{
CU= convertCBCU( CB, CU);//match int CU with CUBE #
cout<<"\n"; //print row name print plane name
cout<<" ";playing_mode1(mode);cout<<"\t\t\t\t (";playing_mode0(mode);cout<<" Plane)\n";
cout<<" | "<<" Plane 0\t Plane 1\t Plane 2\t Plane 3";
cout<<"\n | ------------- "<<"------------- "<<"------------- "<<"-------------\n";
for (P=3;P>=0;P--) //change row, smaller row at the bottom
{
cout<<" Row|"<<P<<"";//print row number
for(R=0;R<4;R++) //change plane or column
{
for(C=0;C<4;C++) //change column or plane
{
if(mode==1)
cout<<" |"<<Bo[CU][C][P][R]; //side VUE
else
if(mode==2)
cout<<" |"<<Bo[CU][P][R][C];//top VUE
else
cout<<" |"<<Bo[CU][R][P][C];//front VUE
}
cout<<" | "; //print the end side of a plane
}
cout<<"\n | ------------- "<<"------------- "<<"------------- "<<"-------------\n";
}
cout<<" | 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 <= Column";
cout<<"\n |-------------------------------------------------------------------------";
playing_mode2(mode);cout<<"\n"; //print column name
}
void printHowToPlay(int Dimension) //function definition send out how to play message
{
cout<<"\n\n\n";
cout<<" Enter Plane#(space)Row#(space)Column# to play"
<<" (as shown on the diagram)"<<endl; //display how to play
cout<<"\tEnter -1-1-1 to stop playing - " //display how to stop
<<"Enter -2-2-2 to change VUE "; //display how to change VUE
if(Dimension==1)
cout<<"\n\t\t\t";
else
cout<<"\n\tEnter -3-3-3 to change CUBE - "; //display how to change CUBE
cout<<"Hit ";
if(Dimension==1)
cout<<"3";
else
cout<<"4";cout<<" boxes in a row to WIN"; //display how to win
if(Dimension==1)
cout<<"\n";
} //end function
void DisPlayPlayer(int numP,int player) //function definition that
{ //display the player ON
if(numP==2) //during playing depend on
DisPlay2Player(player); //how many players in the game
else //2 players take turn
if(numP==3)
DisPlay3Player(player); //3 players take turns
else
DisPlay4Player(player); //4 players take turns
} //end function
void DisplayError() //function definition will
{ //dislay the error message
char dummy; //if a player tried to mark
//on a box that already marked
cin.get(dummy); //stop the message
cout<<"\t "; //display error message
cout<<"ERROR!!!THAT BOX IS OCCUPIED!!!";//message
cout<<" Hit Enter to coninue";
cin.get(dummy); //stop the message so we can see
} //end function
void DisPlay2Player(int player) //function definition
{ //display the player's turns(2)
if(player==1)
cout<<"Player 1 ON "; //print Player 1
else
cout<<"\t\t\t\t\t\t\t"<<"Player 2 ON ";//print Player 2
} //end function
void DisPlay3Player(int player) //function definition
{ //display the player's turns(3)
if(player==1){ //start if
cout<<"Player 1 ON "; //print Player 1
player=2;
}else{
if(player==2){ //start if
cout<<"\t\t\t\t"<<"Player 2 ON "; //print Player 2
player=3;
}else{
cout<<"\t\t\t\t\t\t\t"<<"Player 3 ON ";//print Player 3
player=1;
} //end if
} //end if
} //end function
void DisPlay4Player(int player) //function definition
{ //display the player's turns(4)
if(player==1) //start if
cout<<"Player 1 ON "; //print Player 1
else
if(player==2)
cout<<"\t\t\t"<<"Player 2 ON "; //print Player 2
else
if(player == 3)
cout<<"\t\t\t\t\t"<<"Player 3 ON "; //print Player 3
else
cout<<"\t\t\t\t\t\t\t "<<"Player 4 ON "; //print Player 4
} //end function
void purgeData() //function definition
{
cin.clear(); //clears any error codes
cin.ignore(64,'\n'); //purges the wrong input
} //end function
int BlankBox(char Bo[4][4][4][4],int CU,int z,int y,int x)//function definition will
{
//check if the box is blank
if( Bo[CU][z][y][x] == ' ')return TRUE; //if box is empty
return FALSE;
} //end function
//function definition will
//mark the box
void BullsEye(char Bo[4][4][4][4],int player,int CU, int z,int y,int x)
{
if(player==1)
Bo[CU][z][y][x]=79; //send an O
else
if(player==2)
Bo[CU][z][y][x]=88; //send an X
else
if(player==3)
Bo[CU][z][y][x]=89; //send a Y
else
Bo[CU][z][y][x]=90; //send a Z
}
int PlayerTakeTurn(int numP,int player)
{
if(numP==2) //switch the players
{ //start if
if(player==1) //player 1 plays first
player=2; //player 2 second
else //2 player game
player=1;
} //end if
if(numP==3) //switch the players
{ //start if
if(player==1) //player 1 plays first
player=2; //player 2 second
else
if(player==2) //3 player game
player=3; //player 3 third
else
player=1; //player 1 again
} //end if
if(numP==4) //switch the players,4 player game,
{ //start if
if(player==1) //player 1 plays first
player=2; //player 2 plays second
else
if(player==2)
player=3; //player 3 plays third
else
if(player==3)
player=4; //player 4 plays fourth
else
player=1; //player 1 plays again
} //end if
return player;
}
void playing_modeC(int CB) //display CUBE number on the screen
{
if(CB==0)
cout<<"CUBE 0"; //default
else
if(CB==1) //players may choose CUBE to play
cout<<"CUBE 1";
else //but only win with the points
if(CB==2) //within 1 cube
cout<<"CUBE 2";
else //players also may watch the points
cout<<"CUBE 3"; //on the others cube
}
void playing_mode(int mode ) //function definition will change
{ //display depend on which mode(Vue)
if (mode==1){ //start if
cout<<"Side VUE = ZY Plane"; //display mode
}else{
if(mode==2){ //start if
cout<<"Top VUE = XZ Plane"; //display mode
}else{
cout<<"Front VUE = XY Plane";//display mode
} //end if
} //end if
cout<<"\n";
} //end function
void playing_mode0(int mode) //function definition will change
{ //plane coordinates at the diagram
if (mode==1){ //start if
cout<<"X"; //coordinates of ZY plane
}else{
if(mode==2){ //start if
cout<<"Y"; //coordinates of XZ plane
}else{
cout<<"Z"; //coordinates of XY plane
} //end if
} //end if
} //function
void playing_mode1(int mode) //function definition will change
{ //ROW coordinates at the diagram
if (mode==1){ //start if
cout<<"Y"; //on the ZY plane
}else{
if(mode==2){ //start if
cout<<"Z"; //on the XZ plane
}else{
cout<<"Y"; //on the XY plane
} //end if
} //end if
} //end function
void playing_mode2(int mode) //function definition will change
{ //COLUMN coordinates at the diagram
if (mode==1){ //start if
cout<<"Z"; //on ZY plane
}else{
if(mode==2){ //start if
cout<<"X"; //on XZ plane
}else{
cout<<"X"; //on XY plane
} //end if
} //end if
} //end function
//Function definition
//If 3 or 4 consecutive squares have the same marks of 1 player
//That player is the winner and the game stops.
char winnerGame(int Dimension,char Bo[4][4][4][4],int CB,int CU)
{
if(Dimension==1)
return winnerGame1(Bo); //return 3 dimension game result
else
return winnerGame2(Bo,CB,CU); //return 4 dimension game result
}
char winnerGame1(char Bo[4][4][4][4]) // O (79 ), X (88), Y (89), Z (90)
{
for(P=0;P<3;P++)
{
for (R=0;R<3;R++)
{
for (C=0;C<3;C++)
{
if( //3 consecutive boxes loaded with an 'O'
((Bo[0][0][R][C]==79) && (Bo[0][1][R][C]==79) && (Bo[0][2][R][C]==79))
|| ((Bo[0][P][0][C]==79) && (Bo[0][P][1][C]==79) && (Bo[0][P][2][C]==79))
|| ((Bo[0][P][R][0]==79) && (Bo[0][P][R][1]==79) && (Bo[0][P][R][2]==79))
|| ((Bo[0][P][0][0]==79) && (Bo[0][P][1][1]==79) && (Bo[0][P][2][2]==79))//xy Plane
|| ((Bo[0][P][0][2]==79) && (Bo[0][P][1][1]==79) && (Bo[0][P][2][0]==79))//xy Plane
|| ((Bo[0][0][0][P]==79) && (Bo[0][1][1][P]==79) && (Bo[0][2][2][P]==79))//zy
|| ((Bo[0][2][0][P]==79) && (Bo[0][1][1][P]==79) && (Bo[0][0][2][P]==79))//zy
|| ((Bo[0][0][P][0]==79) && (Bo[0][1][P][1]==79) && (Bo[0][2][P][2]==79))//xz
|| ((Bo[0][0][P][2]==79) && (Bo[0][1][P][1]==79) && (Bo[0][2][P][0]==79))//xz
//3 consecutive boxes loaded with an 'X'
|| ((Bo[0][0][R][C]==88) && (Bo[0][1][R][C]==88) && (Bo[0][2][R][C]==88))
|| ((Bo[0][P][0][C]==88) && (Bo[0][P][1][C]==88) && (Bo[0][P][2][C]==88))
|| ((Bo[0][P][R][0]==88) && (Bo[0][P][R][1]==88) && (Bo[0][P][R][2]==88))
|| ((Bo[0][P][0][0]==88) && (Bo[0][P][1][1]==88) && (Bo[0][P][2][2]==88))//xy
|| ((Bo[0][P][0][2]==88) && (Bo[0][P][1][1]==88) && (Bo[0][P][2][0]==88))//xy
|| ((Bo[0][0][0][P]==88) && (Bo[0][1][1][P]==88) && (Bo[0][2][2][P]==88))//zy
|| ((Bo[0][2][0][P]==88) && (Bo[0][1][1][P]==88) && (Bo[0][0][2][P]==88))//zy
|| ((Bo[0][0][P][0]==88) && (Bo[0][1][P][1]==88) && (Bo[0][2][P][2]==88))//xz
|| ((Bo[0][0][P][2]==88) && (Bo[0][1][P][1]==88) && (Bo[0][2][P][0]==88))//xz
//3 consecutive boxes loaded with an 'Y'
|| ((Bo[0][0][R][C]==89) && (Bo[0][1][R][C]==89) && (Bo[0][2][R][C]==89))
|| ((Bo[0][P][0][C]==89) && (Bo[0][P][1][C]==89) && (Bo[0][P][2][C]==89))
|| ((Bo[0][P][R][0]==89) && (Bo[0][P][R][1]==89) && (Bo[0][P][R][2]==89))
|| ((Bo[0][P][0][0]==89) && (Bo[0][P][1][1]==89) && (Bo[0][P][2][2]==89))//xy
|| ((Bo[0][P][0][2]==89) && (Bo[0][P][1][1]==89) && (Bo[0][P][2][0]==89))//xy
|| ((Bo[0][0][0][P]==89) && (Bo[0][1][1][P]==89) && (Bo[0][2][2][P]==89))//zy
|| ((Bo[0][2][0][P]==89) && (Bo[0][1][1][P]==89) && (Bo[0][0][2][P]==89))//zy
|| ((Bo[0][0][P][0]==89) && (Bo[0][1][P][1]==89) && (Bo[0][2][P][2]==89))//xz
|| ((Bo[0][0][P][2]==89) && (Bo[0][1][P][1]==89) && (Bo[0][2][P][0]==89))//xz
//3 consecutive boxes loaded with an 'Z'
|| ((Bo[0][0][R][C]==90) && (Bo[0][1][R][C]==90) && (Bo[0][2][R][C]==90))
|| ((Bo[0][P][0][C]==90) && (Bo[0][P][1][C]==90) && (Bo[0][P][2][C]==90))
|| ((Bo[0][P][R][0]==90) && (Bo[0][P][R][1]==90) && (Bo[0][P][R][2]==90))
|| ((Bo[0][P][0][0]==90) && (Bo[0][P][1][1]==90) && (Bo[0][P][2][2]==90))//xy
|| ((Bo[0][P][0][2]==90) && (Bo[0][P][1][1]==90) && (Bo[0][P][2][0]==90))//xy
|| ((Bo[0][0][0][P]==90) && (Bo[0][1][1][P]==90) && (Bo[0][2][2][P]==90))//zy
|| ((Bo[0][2][0][P]==90) && (Bo[0][1][1][P]==90) && (Bo[0][0][2][P]==90))//zy
|| ((Bo[0][0][P][0]==90) && (Bo[0][1][P][1]==90) && (Bo[0][2][P][2]==90))//xz
|| ((Bo[0][0][P][2]==90) && (Bo[0][1][P][1]==90) && (Bo[0][2][P][0]==90)))//xz)
return 1;
} //end for
} //end for
} //end for
return 0; //return: no winner yet
} //end function
char winnerGame2(char Bo[4][4][4][4],int CB,int CU) // O (79 ), X (88), Y (89), Z (90)
{
CU=convertCBCU(CB,CU);
for(P=0;P<4;P++) //load Plane values
{
for (R=0;R<4;R++) //load Row values
{
for (C=0;C<4;C++) //load Column values
{
if( //4 consecutive boxes loaded with an 'O'
((Bo[CU][0][R][C]==79) && (Bo[CU][1][R][C]==79) && (Bo[CU][2][R][C]==79)&& (Bo[CU][3][R][C]==79))
|| ((Bo[CU][P][0][C]==79) && (Bo[CU][P][1][C]==79) && (Bo[CU][P][2][C]==79)&& (Bo[CU][P][3][C]==79))
|| ((Bo[CU][P][R][0]==79) && (Bo[CU][P][R][1]==79) && (Bo[CU][P][R][2]==79)&& (Bo[CU][P][R][3]==79))
|| ((Bo[CU][P][0][0]==79) && (Bo[CU][P][1][1]==79) && (Bo[CU][P][2][2]==79)&& (Bo[CU][P][3][3]==79))//xy Plane
|| ((Bo[CU][P][0][3]==79) && (Bo[CU][P][1][2]==79) && (Bo[CU][P][2][1]==79)&& (Bo[CU][P][3][0]==79))//xy Plane
|| ((Bo[CU][0][0][P]==79) && (Bo[CU][1][1][P]==79) && (Bo[CU][2][2][P]==79)&& (Bo[CU][3][3][P]==79))//zy
|| ((Bo[CU][3][0][P]==79) && (Bo[CU][2][1][P]==79) && (Bo[CU][1][2][P]==79)&& (Bo[CU][0][3][P]==79))//zy
|| ((Bo[CU][0][P][0]==79) && (Bo[CU][1][P][1]==79) && (Bo[CU][2][P][2]==79)&& (Bo[CU][3][P][3]==79))//xz
|| ((Bo[CU][0][P][3]==79) && (Bo[CU][1][P][2]==79) && (Bo[CU][2][P][1]==79)&& (Bo[CU][3][P][0]==79))//xz
//4 consecutive boxes loaded with an 'X'
|| ((Bo[CU][0][R][C]==88) && (Bo[CU][1][R][C]==88) && (Bo[CU][2][R][C]==88)&& (Bo[CU][3][R][C]==88))
|| ((Bo[CU][P][0][C]==88) && (Bo[CU][P][1][C]==88) && (Bo[CU][P][2][C]==88)&& (Bo[CU][P][3][C]==88))
|| ((Bo[CU][P][R][0]==88) && (Bo[CU][P][R][1]==88) && (Bo[CU][P][R][2]==88)&& (Bo[CU][P][R][3]==88))
|| ((Bo[CU][P][0][0]==88) && (Bo[CU][P][1][1]==88) && (Bo[CU][P][2][2]==88)&& (Bo[CU][P][3][3]==88))//xy Plane
|| ((Bo[CU][P][0][3]==88) && (Bo[CU][P][1][2]==88) && (Bo[CU][P][2][1]==88)&& (Bo[CU][P][3][0]==88))//xy Plane
|| ((Bo[CU][0][0][P]==88) && (Bo[CU][1][1][P]==88) && (Bo[CU][2][2][P]==88)&& (Bo[CU][3][3][P]==88))//zy
|| ((Bo[CU][3][0][P]==88) && (Bo[CU][2][1][P]==88) && (Bo[CU][1][2][P]==88)&& (Bo[CU][0][3][P]==88))//zy
|| ((Bo[CU][0][P][0]==88) && (Bo[CU][1][P][1]==88) && (Bo[CU][2][P][2]==88)&& (Bo[CU][3][P][3]==88))//xz
|| ((Bo[CU][0][P][3]==88) && (Bo[CU][1][P][2]==88) && (Bo[CU][2][P][1]==88)&& (Bo[CU][3][P][0]==88))//xz
//4 consecutive boxes loaded with a 'Y'
|| ((Bo[CU][0][R][C]==89) && (Bo[CU][1][R][C]==89) && (Bo[CU][2][R][C]==89)&& (Bo[CU][3][R][C]==89))
|| ((Bo[CU][P][0][C]==89) && (Bo[CU][P][1][C]==89) && (Bo[CU][P][2][C]==89)&& (Bo[CU][P][3][C]==89))
|| ((Bo[CU][P][R][0]==89) && (Bo[CU][P][R][1]==89) && (Bo[CU][P][R][2]==89)&& (Bo[CU][P][R][3]==89))
|| ((Bo[CU][P][0][0]==89) && (Bo[CU][P][1][1]==89) && (Bo[CU][P][2][2]==89)&& (Bo[CU][P][3][3]==89))//xy Plane
|| ((Bo[CU][P][0][3]==89) && (Bo[CU][P][1][2]==89) && (Bo[CU][P][2][1]==89)&& (Bo[CU][P][3][0]==89))//xy Plane
|| ((Bo[CU][0][0][P]==89) && (Bo[CU][1][1][P]==89) && (Bo[CU][2][2][P]==89)&& (Bo[CU][3][3][P]==89))//zy
|| ((Bo[CU][3][0][P]==89) && (Bo[CU][2][1][P]==89) && (Bo[CU][1][2][P]==89)&& (Bo[CU][0][3][P]==89))//zy
|| ((Bo[CU][0][P][0]==89) && (Bo[CU][1][P][1]==89) && (Bo[CU][2][P][2]==89)&& (Bo[CU][3][P][3]==89))//xz
|| ((Bo[CU][0][P][3]==89) && (Bo[CU][1][P][2]==89) && (Bo[CU][2][P][1]==89)&& (Bo[CU][3][P][0]==89))//xz
//4 consecutive boxes loaded with a 'Z'
|| ((Bo[CU][0][R][C]==90) && (Bo[CU][1][R][C]==90) && (Bo[CU][2][R][C]==90)&& (Bo[CU][3][R][C]==90))
|| ((Bo[CU][P][0][C]==90) && (Bo[CU][P][1][C]==90) && (Bo[CU][P][2][C]==90)&& (Bo[CU][P][3][C]==90))
|| ((Bo[CU][P][R][0]==90) && (Bo[CU][P][R][1]==90) && (Bo[CU][P][R][2]==90)&& (Bo[CU][P][R][3]==90))
|| ((Bo[CU][P][0][0]==90) && (Bo[CU][P][1][1]==90) && (Bo[CU][P][2][2]==90)&& (Bo[CU][P][3][3]==90))//xy Plane
|| ((Bo[CU][P][0][3]==90) && (Bo[CU][P][1][2]==90) && (Bo[CU][P][2][1]==90)&& (Bo[CU][P][3][0]==90))//xy Plane
|| ((Bo[CU][0][0][P]==90) && (Bo[CU][1][1][P]==90) && (Bo[CU][2][2][P]==90)&& (Bo[CU][3][3][P]==90))//zy
|| ((Bo[CU][3][0][P]==90) && (Bo[CU][2][1][P]==90) && (Bo[CU][1][2][P]==90)&& (Bo[CU][0][3][P]==90))//zy
|| ((Bo[CU][0][P][0]==90) && (Bo[CU][1][P][1]==90) && (Bo[CU][2][P][2]==90)&& (Bo[CU][3][P][3]==90))//xz
|| ((Bo[CU][0][P][3]==90) && (Bo[CU][1][P][2]==90) && (Bo[CU][2][P][1]==90)&& (Bo[CU][3][P][0]==90)))//xz
return 1; //return to function call
} //end for
} //end for
} //end for
return 0; //return to function call
} //end of function definition
void ResultMess(int Dimension,char Bo[4][4][4][4],int numP,int player) //function definition
{
char dummy; //used to stop message on the screen
if(winnerGame(Dimension,Bo,CB,CU))
{ //start if
cin.get(dummy); //stop the message
cout<<"\n\n\n";
if(numP==2) //if 2 player game
{ //start if
if(player==1) //display the player who win the game
cout<<"\t\t Player 2 "; //print Player 2
else
cout<<"\t\t Player 1 "; //print Player 1
} //end if
if(numP==3) //if 3 player game
{ //start if
if(player==1)
cout<<"\t\t Player 3 "; //print player 3
else
if(player==2)
cout<<"\t\t Player 1 "; //print player 1
else
cout<<"\t\t Player 2 "; //print player 1
} //end if
if(numP==4) //if 4 player game
{ //start if
if(player==1)
cout<<"\t\t Player 4"; //print player 4
else
if(player==2)
cout<<"\t\t Player 1"; //print player 1
else
if(player==3)
cout<<"\t\t Player 2";//print player 2
else
cout<<"\t\t Player 3";//print player 3
}
DisplayWinner(Dimension,Bo); //cheer the winner
}else
{
cout<<"\n\n\n\n\n\n\n\n\n\n"; //scroll off the screen
cin.get(dummy); //hold sceen
cout<<endl;
cout<<"\t\t\t THERE IS NO WINNER"<<endl;//message
cout<<"\t\t Hit enter to come back to the main menu";
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n";
cin.get(dummy); //hold screen
} //end if
} //end function
void DisplayWinner(int Dimension,char Bo[4][4][4][4])//function definition
{ //display congratulation the winner
char dummy; //used to stop the message
//from scrolling off the screen
cout<<" is THE WINNER!!!"; //display the winner
cout<<"CONGRATULATION"<<endl; //message
if(Dimension==1)
diagram3(Bo,P,R,C); //show 3 dimension diagram
else
diagram4(Bo,CB,CU,P,R,C); //show 4 dimension diagram
//display the message
cout<<"\t\t\t Hit enter to come back to the main menu";
cout<<"\n\n\n\n\n\n\n\n"; //scroll of the window
cin.get(dummy);
} //end function
//function definition will reload
char clearData(char Bo[4][4][4][4],int CU) // all the boxes to blank
{
for(CU=0;CU<4;CU++) //start for
{
for(z=0;z<4;z++)
{
for(y=0;y<4;y++)
{
for(x=0;x<4;x++)
{
Bo[CU][z][y][x]=' '; //set all array units to blank
}
}
}
} //end for
return 1; //return to function call
} //end function
int convertCBCU(int CB,int CU) //function definition
{
if(CB==0) //match the values of CU
CU=0; //with the CB mode
else //start if
if(CB==1) //start if
CU=1;
else //CU has 4 values
if(CB==2) //from 0 to 3
CU=2; //match with CB from 0 to 3
else
CU=3;
return CU; //return to function call
} //end function
0 comments:
Post a Comment