با سلام
از دوستان مي خواستم در مورد الگوريتم بازي دوز در c++ راهنمايي كنند.
Printable View
با سلام
از دوستان مي خواستم در مورد الگوريتم بازي دوز در c++ راهنمايي كنند.
اين برنامه يكي از تمرين هاي كتاب قمي بود كه براي استاد نوشته بودم؛ قبلا.
براتون ميزارم ولي بهتره ازش براي نوشتن برنامه خودتون استفاده كنين نه كه...
کد:
کد:#include<iostream>
using namespace std;
#include<conio.h>
class tictactoe{
private:
int base[3][3];
int x,y,z1,z2,z;
public:
tictactoe(){
z=1 ;
z1=0;z2=0;
for(x=0;x<3;x++)
for(y=0;y<3;y++)
base[x][y]=0; }
int check();
int victory(int );
void face();
int set();
};
int tictactoe::set(){
int counter=0;
int x,y,m=10;
cout << "Entre number of place:\ n" ;
cout <<"palyer one";
gotoxy(45,8);
cout <<"player two\n\ n";
while(z!=5){
k:
cin >> x >> y;
if (base[x][y]==0) {
base[x][y]=1;
z1=0;z2=0;
check();
if(z==5) return 0;
}
else goto k;
p:
gotoxy(45,m++);
cin >> x >> y;
if (base[x][y]==0) {
base[x][y]=2;
z1=0;z2=0;
check();
if(z==5) return 0;
}
else goto p;
}
cout <<"\ n";
if (counter==4) {return 0;
}
}
int tictactoe::check(){
if(base[0][0]==1 && base[0][1]==1&& base[0][2]==1
||base[1][0]==1 && base[1][1]==1&& base[1][2]==1
||base[2][0]==1 && base[2][1]==1&& base[2][2]==1
||base[0][0]==1 && base[1][1]==1&& base[2][2]==1
||base[0][2]==1 && base[1][2]==1&& base[2][2]==1
||base[0][0]==1 && base[1][0]==1&& base[2][0]==1
||base[0][1]==1 && base[1][1]==1&& base[0][2]==1
||base[0][2]==1 && base[1][2]==1&& base[2][2]==1
||base[0][0]==1 && base[1][1]==1&& base[2][2]==1
||base[0][2]==1 && base[1][1]==1&& base[2][0]==1)
z1=3;
if(z1==3) {victory(1); return 0; }
if(base[0][0]==2 && base[0][1]==2&& base[0][2]==2
||base[1][0]==2 && base[1][1]==2&& base[1][2]==2
||base[2][0]==2 && base[2][1]==2&& base[2][2]==2
||base[0][0]==2 && base[1][1]==2&& base[2][2]==2
||base[0][2]==2 && base[1][2]==2&& base[2][2]==2
||base[0][0]==2 && base[1][0]==2&& base[2][0]==2
||base[0][1]==2 && base[1][1]==2&& base[0][2]==2
||base[0][2]==2 && base[1][2]==2&& base[2][2]==2
||base[0][0]==2 && base[1][1]==2&& base[2][2]==2
||base[0][2]==2 && base[1][1]==2&& base[2][0]==2)
z2=3;
if(z2==3){ victory(2); return 0;}
return 0;}
int tictactoe::victory(int x) {
cout << "player " << x << "are win...";
z=5;
return 0;
}
void tictactoe::face(){
int m=1;
for(x=0;x<3;x++){
for(y=0;y<3;y++){
cout <<x<<y<< "\ t";
}
cout << "\ n";
}
cout << "\n\n\ n";
}
int main(){
tictactoe doz;
doz.face();
doz.set();
_getch();
}