#include <cstdlib>
#include <iostream>
using namespace std;
int printboard(char array[],char alph,int x=0,int y=0)
{
for(alph='a';array[x]!=false;){
if(array[x]!=alph)
{
alph++;
}
if(array[x]==alph)
{
x++;
}
};
for(y=x,x=0;x!=y;x++){
cout<<""<<array[x]<<" ";
if(x==2||x==5)
{
cout<<"\n \n";
}
};
cout<<"\n";
return x;
}
//Tic Tac Toe?
int main()
{
char array[]="123456789";
int x=0;
int y=0;
int c=0;
char alph;
char player1='x';
char player2='o';
int quest;
int round=1;
int turn=0;
do{
retry:
c = printboard(array,alph,x,y);
cout<<"\nPlayer "<<round<<". Turn "<<turn<<"/"<<c<<". Enter(1-9): ";
cin>>quest;
quest--;
if(quest<=-1||quest>=9)
{
cout<<"\nInvalid input\n\n";goto retry;
}
turn++;
if(array[quest]=='x'||array[quest]=='o')
{
cout<<"\nInvalid Maneuver. Location occupied by "<<array[quest]<<"\n\n";turn--;
goto retry;
}
cout<<"\n";
if(round==1)
{
array[quest]=player1;
}
if(round==2)
{
array[quest]=player2;
}
round++;
if(round>=3)
{
round=1;
}
}while(quest>-1&&quest<9&&(array[quest]=='x'||array[quest]=='o'));
cout<<"\n\n";
system("PAUSE");
return EXIT_SUCCESS;
}
This is my way of coding tic tac toe. As you can see, it is missing a win condition.
I could just add a if statement for every win condition, but then i would not learn anything.
Is it possible for anyone to give me some advices on how to make a win condition, without having to write a if statement for every possible win?
Edit: I have started using hungarian notation. Unfortunately that was after i made this code, so i appologize if it's useless to read.