Nice, just a comment: you could cut a bit your if's if you had a cycle or two ^^
Btw, now try to use this, if you understand: SetConsoleCursorPosition Function (Windows)
The game will look better for sure ;D
[php]
#include<iostream>
#include<stdio.h>
#include<conio.h>
using namespace std;
int display(char a[3][3]);
void main()
{
int e,f,g,h,i,j;
char a[3][3] , l='0';
while(l == '0')
{
e=0;
f=0;
a[0][0]='1';
a[0][1]='2';
a[0][2]='3';
a[1][0]='4';
a[1][1]='5';
a[1][2]='6';
a[2][0]='7';
a[2][1]='8';
a[2][2]='9';
e=display(a);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
a[i][j]=' ';
while(e==0)
{
h=1;
while(h!=0)
{
cout<<"Enter the number of the box you wish to use."<<endl;
cin>>g;
if(g<1||g>9)
{
cout<<"Does not compute..."<<endl;
f=1;
}
else
{
if((a[(g-1)/3][(g-1)%3]=='x')||(a[(g-1)/3][(g-1)%3]=='o'))
{
cout<<"wait?what... That wasn't a usable spot..."<<endl;
f=1;
}
else
h=0;
}
}
if(f%2==0)
a[(g-1)/3][(g-1)%3]='x';
else
a[(g-1)/3][(g-1)%3]='o';
e=display(a);
f++;
}
if(e==1)
cout<<"player 1 wins"<<endl;
if(e==2)
cout<<"player 2 wins"<<endl;
if(e==3)
cout<<"game is drawn"<<endl;
cout<<"wanna play another game \n press 0 to continue"<<endl;
l=getchar();
}
getch();
}
int display(char a[3][3])
{
int i,j,e=0,s;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j]<<"|";
}
cout<<"\n";
cout<<"-|-|-"<<endl;
}
if((a[0][0]=='x')&&(a[1][1]=='x')&&(a[2][2]=='x'))
e=1;
if((a[0][0]=='x')&&(a[0][1]=='x')&&(a[0][2]=='x'))
e=1;
if((a[0][0]=='x')&&(a[1][0]=='x')&&(a[2][0]=='x'))
e=1;
if((a[2][0]=='x')&&(a[2][1]=='x')&&(a[2][2]=='x'))
e=1;
if((a[1][0]=='x')&&(a[1][1]=='x')&&(a[1][2]=='x'))
e=1;
if((a[0][1]=='x')&&(a[1][1]=='x')&&(a[2][1]=='x'))
e=1;
if((a[0][2]=='x')&&(a[1][2]=='x')&&(a[2][2]=='x'))
e=1;
if((a[0][2]=='x')&&(a[1][1]=='x')&&(a[2][0]=='x'))
e=1;
if((a[0][0]=='o')&&(a[1][1]=='o')&&(a[2][2]=='o'))
e=2;
if((a[0][0]=='o')&&(a[0][1]=='o')&&(a[0][2]=='o'))
e=2;
if((a[0][0]=='o')&&(a[1][0]=='o')&&(a[2][0]=='o'))
e=2;
if((a[2][0]=='o')&&(a[2][1]=='o')&&(a[2][2]=='o'))
e=2;
if((a[1][0]=='o')&&(a[1][1]=='o')&&(a[1][2]=='o'))
e=2;
if((a[0][1]=='o')&&(a[1][1]=='o')&&(a[2][1]=='o'))
e=2;
if((a[0][2]=='o')&&(a[1][2]=='o')&&(a[2][2]=='o'))
e=2;
if((a[0][2]=='o')&&(a[1][1]=='o')&&(a[2][0]=='o'))
e=2;
s=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
if((a[i][j]=='x')||(a[i][j]=='o'))
s++;
}
if(e!=1&&e!=2&&s==9)
return (3);
if(e==1|e==2)
return e;
if(e!=1&&e!=2)
if(s!=9)
return (0);
}
[/php]
Been working on it for a few days now... Thought I'd release the messy code
Favourite quotes:
Definition of computing: The use or operation of computers.Code:I don't need easy, I just need possible. ~ Me There are three birds on a fence. Two decide to fly away, how many are left? Three, just because you decide to do something doesn't mean you've done it. ~ Don't know who said this Do not go where the path may lead, go instead where there is no path and leave a trail. ~ Ralph Waldo Emerson
Turning on my computer = computing = programming
LAWLFAIL
Nice, just a comment: you could cut a bit your if's if you had a cycle or two ^^
Btw, now try to use this, if you understand: SetConsoleCursorPosition Function (Windows)
The game will look better for sure ;D
Light travels faster than sound. That's why most people seem bright until you hear them speak.
Nice work, I made an AI once for tic-tac-toe
And since that's all I do at school I was realy pro but I've never beat my AI XD he was the perfect player
You could just create a game class to draw the board. but nice
and when you used [php]void main()[/php]
Why did you return?
Last edited by Kallisti; 08-13-2010 at 01:00 AM.
未来が見えなくて怖いから
未来が見えてしまって悲しいから
目を閉じて優しい思い出に浸ってしまう
he is not returning main, even as dead i can see better then you
Light travels faster than sound. That's why most people seem bright until you hear them speak.
ohyeea. oops.
未来が見えなくて怖いから
未来が見えてしまって悲しいから
目を閉じて優しい思い出に浸ってしまう
Could be used "Case" instead of all those if?