commit f7eff2b4492d591a1e7264ca09bd0c7a35d2a9f1 Author: unknown <1454005058@qq.com> Date: Thu Jan 10 14:57:16 2019 +0800 last commit diff --git a/实验.cpp1.cpp b/实验.cpp1.cpp new file mode 100644 index 0000000..9fb7a2e --- /dev/null +++ b/实验.cpp1.cpp @@ -0,0 +1,190 @@ +#include +#include +#include +int X[]={'_','_','_','_','_','_','_','_','_'},shunt=1,f; +void map() +{ +int i,j; +system("cls"); +for(i=0;i<9;i++) +{ + if(i==2||i==5||i==8) + printf("%c\n",X[i]); + else + printf("%c|",X[i]); +} +} +int win(int f,int a[]) +{ + if(a[0]+a[1]+a[2]==3*'O'|| + a[3]+a[4]+a[5]==3*'O'||a[6]+a[7]+a[8]==3*'O'|| + a[0]+a[3]+a[6]==3*'O'||a[1]+a[4]+a[7]==3*'O'|| + a[2]+a[5]+a[8]==3*'O'||a[0]+a[4]+a[8]==3*'O'|| + a[2]+a[4]+a[6]==3*'O') + f=1; + else if(a[0]+a[1]+a[2]==3*'X'|| + a[3]+a[4]+a[5]==3*'X'||a[6]+a[7]+a[8]==3*'X'|| + a[0]+a[3]+a[6]==3*'X'||a[1]+a[4]+a[7]==3*'X'|| + a[2]+a[5]+a[8]==3*'X'||a[0]+a[4]+a[8]==3*'X'|| + a[2]+a[4]+a[6]==3*'X') + f=2; + else + f=0; + return f; +} +void shuru_number() +{ + int a, b, number; + scanf("%d",&number); + while(number<1||number>9||X[number-1]!='_') \ + { + printf("·Ç·¨ÊäÈ룬ÇëÖØÐÂÊäÈë\n"); + scanf("%d",&number); + map(); + } + if(shunt%2!=0) + { + a=number; + X[a-1]='O'; + map(); + shunt++; + } + else + { + b=number; + X[b-1]='X'; + map(); + shunt++; + } +} +int timex() +{ + int i,v; + time_t t; + srand((unsigned) time(&t)); + v=rand() % 10; + return v; + +} + + + +int computer() +{ + map(); + int nn; + int v,i; + printf("ÏÈÊÖorºóÊÖ\nÊäÈë1or2Ñ¡Ôñ\n"); + scanf("%d",&nn); + if(nn==1) + for(i=0;i<5;i++) + { + map(); + int a, b, number; + scanf("%d",&number); + while(number<1||number>9||X[number-1]!='_') + { + printf("·Ç·¨ÊäÈ룬ÇëÖØÐÂÊäÈë\n"); + scanf("%d",&number); + map(); + } + a=number; + X[a-1]='O'; + map(); + if(win(f,X)) + { + f=win(f,X); + break; + } + + if(i<4) + { + v=timex(); + while(v<1||v>9||X[v-1]!='_') + { + v=timex(); + map(); + } + X[v-1]='X'; + map(); + } + } + else + { + for(i=0;i<5;i++) + { + v=timex(); + while(v<1||v>9||X[v-1]!='_') + { + v=timex(); + map(); + } + X[v-1]='X'; + map(); + if(win(f,X)) + { + f=win(f,X); + break; + } + if(i<4) + { + map(); + int a, b, number; + scanf("%d",&number); + while(number<1||number>9||X[number-1]!='_') + { + printf("·Ç·¨ÊäÈ룬ÇëÖØÐÂÊäÈë\n"); + scanf("%d",&number); + map(); + } + a=number; + X[a-1]='O'; + map(); + } + if(win(f,X)) + { + f=win(f,X); + break; + } + } + } +return 0; + } +int main() +{ + + int i,n; + int q; + f=0; + printf("ÕâÊÇÒ»¸ö»áµôÍ··¢µÄ¾®×ÖÆåÓÎÏ·\n"); + printf("ÊäÈë¡®1or2¡¯Ñ¡Ôñ\n1.ÈË»ú¶ÔÕ½\n2.Íæ¼Ò¶ÔÕ½\n"); + scanf("%d",&q); + if(q==2) + { + map(); + printf("ÊäÈëÊý×Ö1~9£¬½øÐÐÏÂÆåŶ\n"); + for(i=0;i<9;i++) + { + shuru_number(); + if(win(f,X)) + { + f=win(f,X); + break; + } + } + } + else + { + + computer(); + + } + if(f==1) + printf("OʤÀû\n"); + else if(f==2) + printf("XʤÀû\n"); + else + printf("ƽ¾Ö\n"); + getchar(); + return 0; + } diff --git a/实验.cpp1.exe b/实验.cpp1.exe new file mode 100644 index 0000000..250b2a7 Binary files /dev/null and b/实验.cpp1.exe differ