third commit

master
24542778262@qq.com 7 years ago
parent cb55ac579f
commit f76bcbb707

@ -1,362 +0,0 @@
#include<stdio.h>
#include<stdlib.h>
int store[][3]={'_','_','_','_','_','_','_','_','_'},i,j,k,flag=1;
void print_map()
{
char boundary='|';
getchar();
system("cls");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%c%c",boundary,store[i][j]);
if(j==2)
{
putchar(boundary);
putchar('\n');
}
}
}
}
int judge_win(int f=0)
{
if(store[0][0]+store[0][1]+store[0][2]==3*'X'||store[1][0]+store[1][1]+store[1][2]==3*'X'
||store[2][0]+store[2][1]+store[2][2]==3*'X'||store[0][0]+store[1][1]+store[2][2]==3*'X'
||store[2][0]+store[1][1]+store[0][2]==3*'X'||store[0][0]+store[1][0]+store[2][0]==3*'X'
||store[0][1]+store[1][1]+store[2][1]==3*'X'||store[0][2]+store[1][2]+store[2][2]==3*'X')
return 1;
else if(store[0][0]+store[0][1]+store[0][2]==3*'O'||store[1][0]+store[1][1]+store[1][2]==3*'O'
||store[2][0]+store[2][1]+store[2][2]==3*'O'||store[0][0]+store[1][1]+store[2][2]==3*'O'
||store[2][0]+store[1][1]+store[0][2]==3*'O'||store[0][0]+store[1][0]+store[2][0]==3*'O'
||store[0][1]+store[1][1]+store[2][1]==3*'O'||store[0][2]+store[1][2]+store[2][2]==3*'O')
return -1;
return f;
}
void judge_final(int i)
{
if(i==0)
printf("平局");
else if(i==1)
printf("VICTORY");
else if(i==-1)
printf("FILE") ;
}
int number_mend(int x)
{
switch(x)
{
case 1:x=3;break;
case 3:x=1;break;
default:;
}
return x;
}
void Computer()
{
int sum,t=0,score[3][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
score[i][j]=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
t+=store[i][j];
if(t==2*'O'+'_')
sum=5;
else if(t=='O'+2*'_')
sum=3;
else if(t=='X'+2*'_')
sum=2;
else if(t==3*'_')
sum=1;
else if(t==2*'X'+'_')
sum=6;
else if(t=='X'+'O'+'_')
sum=4;
switch(sum)
{
case 1:
for(k=0;k<3;k++)
{
if(store[i][k]=='_')
score[i][k]+=1;
}
break;
case 2:
for(k=0;k<3;k++)
{
if(store[i][k]=='_')
score[i][k]+=10;
}
break;
case 3:
for(k=0;k<3;k++)
{
if(store[i][k]=='_')
score[i][k]+=50;
}
break;
case 4:
for(k=0;k<3;k++)
{
if(store[i][k]=='_')
score[i][k]+=200;
}
break;
case 5:
for(k=0;k<3;k++)
{
if(store[i][k]=='_')
score[i][k]+=500;
}
break;
case 6:
for(k=0;k<3;k++)
{
if(store[i][k]=='_')
score[i][k]+=1000;
}
break;
}
t=0;
}
for(j=0;j<3;j++)
{
for(i=0;i<3;i++)
t+=store[i][j];
if(t==2*'O'+'_')
sum=5;
else if(t=='O'+2*'_')
sum=3;
else if(t=='X'+2*'_')
sum=2;
else if(t==3*'_')
sum=1;
else if(t==2*'X'+'_')
sum=6;
else if(t=='X'+'O'+'_')
sum=4;
switch(sum)
{
case 1:
for(k=0;k<3;k++)
{
if(store[k][j]=='_')
score[k][j]+=1;
}
break;
case 2:
for(k=0;k<3;k++)
{
if(store[k][j]=='_')
score[k][j]+=10;
}
break;
case 3:
for(k=0;k<3;k++)
{
if(store[k][j]=='_')
score[k][j]+=50;
}
break;
case 4:
for(k=0;k<3;k++)
{
if(store[k][j]=='_')
score[k][j]+=200;
}
break;
case 5:
for(k=0;k<3;k++)
{
if(store[k][j]=='_')
score[k][j]+=500;
}
break;
case 6:
for(k=0;k<3;k++)
{
if(store[k][j]=='_')
score[k][j]+=1000;
}
break;
}
t=0;
}
t=0;
for(i=0;i<3;i++)
t+=store[i][i];
if(t==2*'O'+'_')
sum=5;
else if(t=='O'+2*'_')
sum=3;
else if(t=='X'+2*'_')
sum=2;
else if(t==3*'_')
sum=1;
else if(t==2*'X'+'_')
sum=6;
else if(t=='X'+'O'+'_')
sum=4;
switch(sum)
{
case 1:
for(k=0;k<3;k++)
{
if(store[k][k]=='_')
score[k][k]+=1;
}
break;
case 2:
for(k=0;k<3;k++)
{
if(store[k][k]=='_')
score[k][k]+=10;
}
break;
case 3:
for(k=0;k<3;k++)
{
if(store[k][k]=='_')
score[k][k]+=50;
}
break;
case 4:
for(k=0;k<3;k++)
{
if(store[k][k]=='_')
score[k][k]+=200;
}
break;
case 5:
for(k=0;k<3;k++)
{
if(store[k][k]=='_')
score[k][k]+=500;
}
break;
case 6:
for(k=0;k<3;k++)
{
if(store[k][k]=='_')
score[k][k]+=1000;
}
break;
}
t=0;
for(i=0;i<3;i++)
t+=store[i][2-i];
if(t==2*'O'+'_')
sum=5;
else if(t=='O'+2*'_')
sum=3;
else if(t=='X'+2*'_')
sum=2;
else if(t==3*'_')
sum=1;
else if(t==2*'X'+'_')
sum=6;
else if(t=='X'+'O'+'_')
sum=4;
switch(sum)
{
case 1:
for(k=0;k<3;k++)
{
if(store[k][2-k]=='_')
score[k][2-k]+=1;
}
break;
case 2:
for(k=0;k<3;k++)
{
if(store[k][2-k]=='_')
score[k][2-k]+=10;
}
break;
case 3:
for(k=0;k<3;k++)
{
if(store[k][2-k]=='_')
score[k][2-k]+=50;
}
break;
case 4:
for(k=0;k<3;k++)
{
if(store[k][2-k]=='_')
score[k][2-k]+=200;
}
break;
case 5:
for(k=0;k<3;k++)
{
if(store[k][2-k]=='_')
score[k][2-k]+=500;
}
break;
case 6:
for(k=0;k<3;k++)
{
if(store[k][2-k]=='_')
score[k][2-k]+=1000;
}
break;
}
int maxRow = 0, maxCol = 0;
for (i=0; i<3; i++)
for (j=0;j<3;j++)
{
if (score[i][j] > score[maxRow][maxCol])
{
maxRow = i;
maxCol = j;
}
}
store[maxRow][maxCol]='O';
print_map();
}
void scan_number()
{
int x,y;
printf("请输入要走的棋格行号和列号:");
scanf("%d%d",&x,&y);
printf("%d,%d",x,y) ;
x=number_mend(x);
while(x>3||x<=0||y>3||y<=0||store[x-1][y-1]!='_')
{
printf("非法输入,请重新输入\n");
getchar();
scanf("%d%d",&x,&y);
x=number_mend(x);
}
store[x-1][y-1]='X';
print_map();
}
int main()
{
int count,i;
printf("这是一个井字棋游戏!按回车选择下棋顺序\n");
getchar();
system("cls");
print_map();
for(count=0;count<10;count+=2)
{
i=judge_win();
if(judge_win())
break;
if(count==9)
{
i=0;
break;
}
scan_number();
Computer();
}
judge_final(i);
return 0;
}

@ -1,71 +0,0 @@
#include<stdio.h>
#include<stdlib.h>
int store[][3]={'_','_','_','_','_','_','_','_','_'},i,j,flag=1;
void print_map()
{
char boundary='|';
getchar();
system("cls");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%c%c",boundary,store[i][j]);
if(j==2)
{
putchar(boundary);
putchar('\n');
}
}
}
}
int number_mend(int x)
{
switch(x)
{
case 1:x=3;break;
case 3:x=1;break;
default:;
}
return x;
}
void scan_number()
{
int x,y;
printf("请输入要走的棋格行号和列号:");
scanf("%d%d",&x,&y);
printf("%d,%d",x,y) ;
x=number_mend(x);
while(x>3||x<=0||y>3||y<=0||store[x-1][y-1]!='_')
{
printf("非法输入,请重新输入\n");
getchar();
scanf("%d%d",&x,&y);
x=number_mend(x);
}
if(flag%2!=0)
{
store[x-1][y-1]='O';
print_map();
flag++;
}
else
{
store[x-1][y-1]='X';
print_map();
flag++;
}
}
int main()
{
int count;
printf("这是一个井字棋游戏!选择下棋顺序并回车即可进入游戏\n");
printf("是否先走Y/N\n");
print_map();
for(count=0;count<10;count++)
scan_number();
return 0;
}

Binary file not shown.

@ -1,14 +1,22 @@
#include<stdio.h>
#include<stdlib.h>
#include <windows.h>
#define col 3
#define row 3
int color(int c)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c);
return 0;
}
int store[][3]={'_','_','_','_','_','_','_','_','_'},i,j,k,flag=1;
void print_map()
void map()
{
char boundary='|';
system("cls");
for(i=0;i<3;i++)
for(i=0;i<col;i++)
{
for(j=0;j<3;j++)
for(j=0;j<row;j++)
{
printf("%c%c",boundary,store[i][j]);
if(j==2)
@ -20,7 +28,7 @@ void print_map()
}
}
}
int judge_win(int f=0)
int judge(int f=0)
{
if(store[0][0]+store[0][1]+store[0][2]==3*'X'||store[1][0]+store[1][1]+store[1][2]==3*'X'
||store[2][0]+store[2][1]+store[2][2]==3*'X'||store[0][0]+store[1][1]+store[2][2]==3*'X'
@ -34,16 +42,18 @@ int judge_win(int f=0)
return -1;
return f;
}
void judge_final(int i)
void final(int i)
{
system("cls");
map();
if(i==0)
printf("平局");
else if(i==1)
printf("VICTORY");
printf("你赢了");
else if(i==-1)
printf("FILE") ;
printf("很遗憾,你输了") ;
}
int number_mend(int x)
int mend(int x)
{
switch(x)
{
@ -57,25 +67,25 @@ void Computer()
{
int sum,t=0,score[3][3];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
for(i=0;i<col;i++)
for(j=0;j<row;j++)
score[i][j]=0;
for(i=0;i<3;i++)
for(i=0;i<col;i++)
{
for(j=0;j<3;j++)
for(j=0;j<row;j++)
t+=store[i][j];
if(t==2*'O'+'_')
sum=5;
else if(t=='O'+2*'_')
sum=3;
else if(t=='X'+2*'_')
sum=2;
sum=4;
else if(t==3*'_')
sum=1;
else if(t==2*'X'+'_')
sum=6;
else if(t=='X'+'O'+'_')
sum=4;
sum=2;
switch(sum)
{
case 1:
@ -103,7 +113,7 @@ void Computer()
for(k=0;k<3;k++)
{
if(store[i][k]=='_')
score[i][k]+=200;
score[i][k]=200;
}
break;
case 5:
@ -123,22 +133,22 @@ void Computer()
}
t=0;
}
for(j=0;j<3;j++)
for(j=0;j<row;j++)
{
for(i=0;i<3;i++)
for(i=0;i<col;i++)
t+=store[i][j];
if(t==2*'O'+'_')
sum=5;
else if(t=='O'+2*'_')
sum=3;
else if(t=='X'+2*'_')
sum=2;
sum=4;
else if(t==3*'_')
sum=1;
else if(t==2*'X'+'_')
sum=6;
else if(t=='X'+'O'+'_')
sum=4;
sum=2;
switch(sum)
{
case 1:
@ -187,20 +197,20 @@ void Computer()
t=0;
}
t=0;
for(i=0;i<3;i++)
for(i=0;i<col;i++)
t+=store[i][i];
if(t==2*'O'+'_')
sum=5;
else if(t=='O'+2*'_')
sum=3;
else if(t=='X'+2*'_')
sum=2;
sum=4;
else if(t==3*'_')
sum=1;
else if(t==2*'X'+'_')
sum=6;
else if(t=='X'+'O'+'_')
sum=4;
sum=2;
switch(sum)
{
case 1:
@ -247,20 +257,20 @@ void Computer()
break;
}
t=0;
for(i=0;i<3;i++)
for(i=0;i<col;i++)
t+=store[i][2-i];
if(t==2*'O'+'_')
sum=5;
else if(t=='O'+2*'_')
sum=3;
else if(t=='X'+2*'_')
sum=2;
sum=4;
else if(t==3*'_')
sum=1;
else if(t==2*'X'+'_')
sum=6;
else if(t=='X'+'O'+'_')
sum=4;
sum=2;
switch(sum)
{
case 1:
@ -307,8 +317,8 @@ void Computer()
break;
}
int maxRow = 0, maxCol = 0;
for (i=0; i<3; i++)
for (j=0;j<3;j++)
for (i=0; i<col; i++)
for (j=0;j<row;j++)
{
if (score[i][j] > score[maxRow][maxCol])
{
@ -317,56 +327,68 @@ void Computer()
}
}
store[maxRow][maxCol]='O';
print_map();
printf("电脑走的棋格行号和列号是:%d %d\n",maxRow+1,maxCol+1);
map();
maxRow=mend(maxRow+1);
printf("电脑走的棋格行号和列号是:%d %d\n",maxRow,maxCol+1);
}
void scan_number()
void scan()
{
int x,y;
printf("请输入要走的棋格行号和列号:");
scanf("%d%d",&x,&y);
printf("%d,%d",x,y) ;
x=number_mend(x);
x=mend(x);
while(x>3||x<=0||y>3||y<=0||store[x-1][y-1]!='_')
{
printf("非法输入,请重新输入\n");
if(x>3||x<=0||y>3||y<=0)
printf("非法输入输入数的范围为1到3请重新输入\n");
else if (store[x-1][y-1]!='_')
printf("该棋格已被占有,请重新输入\n");
getchar();
scanf("%d%d",&x,&y);
x=number_mend(x);
x=mend(x);
}
store[x-1][y-1]='X';
print_map();
map();
}
int main()
{
int count=0,i;
char ch,*p=&ch;
char ch;
color(10);
printf("\t这是一个井字棋游戏!\n在游戏之前请先阅读以下注意事项:\n");
printf("1.你可以选择下棋的先后顺序\n");
printf("2.您输入的第一个数是第二个是列且第一行在最下面。输入的正确形式为x空y\n");
printf("3.本程序还有许多不足,请多多包涵!爱你哦!!!!!\n") ;
printf("按回车即可进入\n");
printf("2.您输入的第一个数是竖直方向第二个是水平方向输入的正确形式为一个数y空一个数x\n");
printf("3.本程序还有许多不足,请多多包涵!\n") ;
printf("按回车即可进入游戏-_- =_= +_+\n");
getchar();
system("cls");
color(12);
printf("是否先下y/n");
scanf("%c",&ch);
print_map();
map();
if(ch=='N'||ch=='n')
goto lp;
for(count=0;count<10;count++)
{
i=judge_win();
if(judge_win())
i=judge();
if(judge())
break;
if(count==9)
{
{
color(0);
i=0;
break;
}
scan_number();
color(14);
printf("游戏状态UNLEND\n");
color(3);
scan();
lp: Computer();
count+=1;
}
judge_final(i);
color(4);
final(i);
return 0;
}

Binary file not shown.
Loading…
Cancel
Save