当前位置:首页 » 编程语言 » 三步棋c语言

三步棋c语言

发布时间: 2023-11-09 09:34:57

Ⅰ 如何学习c语言

学习方法是:

1、课前预习,课后复习,认真做课堂、课后的作业,理解理论知识。

2、记住语法规则。

3、加强逻辑思维。

4、多动手,通过练习上机了解它的运行过程。

5、实践—>理论—>再实践,刚开始学习C语言时,按示例练习,并推动理论的学习,然后再自己多思考,多上机实践。

拓展资料

C语言是一门通用计算机编程语言,广泛应用于底层开发。C语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。

尽管C语言提供了许多低级处理的功能,但仍然保持着良好跨平台的特性,以一个标准规格写出的C语言程序可在许多电脑平台上进行编译,甚至包含一些嵌入式处理器(单片机或称MCU)以及超级电脑等作业平台。

Ⅱ 用C语言. 编写一个文本界面的围棋打谱程序

这是一个简单的程序,会自动计算提子,但不会数目。其它的运行一次估计就差不多会用了。稍微写了点注释。

#include<stdio.h>
#include<stdlib.h>

char board[21][21];
char move[5][2]={{-1,0},{1,0},{0,-1},{0,1},{0,0}};

void initBoard();//初始化棋盘
void showBoard();//输出棋盘
char set(int x,int y,char color);//下子
void process(int xx,int yy);//计算提子

int main()
{
FILE * fptr=NULL;
char pufile[256]={0};
char op;
int s;
int x,y,r;
char color;
char win;
int cnt;

start:
s=8;
while(s!=1 && s!=2)
{
printf("选择模式:\n1---下棋\n2---看棋谱\n0---退出\n");
printf("下棋模式下,下子请输入s x y(x,y为位置),认输输入g,和棋输入h\n选择:");
scanf("%d",&s);
if(s==0) return 0;
//Egg1
if(s==10) printf("Programmer: swordlance :)\n");
//Egg1 end
}
getchar();
printf("输入棋谱路径:");
gets(pufile);

if(s==1) fptr=fopen(pufile,"w");
else fptr=fopen(pufile,"r");

if(!fptr)
{
printf("文件无法打开(创建)!\n");
system("PAUSE");
return -1;
}

initBoard();
cnt=0;
color='B';
while(op!='g')
{
system("CLS");
showBoard();
printf("(第%d手)",++cnt);
if(s==1)
{
printf("%c 方:",color);
scanf("%c",&op);
//printf("[%c]",op);
if(op=='s')
{
scanf("%d %d",&x,&y);
getchar();
if(set(x,y,color)!=0)
{
printf("该处不能落子!\n");
cnt--;
system("PAUSE");
}
else
{
process(x,y);
fprintf(fptr,"%d %d\n",x,y);
if(color=='B') color='W';
else color='B';
}
}
else if(op=='g')
{
printf("%c 方认输。\n",color);
if(color=='B') fprintf(fptr,"0 1\n");
else fprintf(fptr,"0 -1\n");
fflush(fptr);
fclose(fptr);
system("PAUSE");
goto start;
}
else if(op=='h')
{
printf("和棋。\n");
fprintf(fptr,"0 0\n");
fflush(fptr);
fclose(fptr);
system("PAUSE");
goto start;
}
else
{
printf("参数错误,下子请输入s x y(x,y为位置),认输输入 g,和棋输入h");
cnt--;
system("PAUSE");
}
}
else
{
fscanf(fptr,"%d %d",&x,&y);
if(x==0)
{
if(y>0) printf("W 方胜!\n");
else if(y<0) printf("B 方胜!\n");
else printf("和棋!\n");
system("PAUSE");
goto start;
}
else
{
printf("%c 方落子(%d,%d)\n",color,x,y);
set(x,y,color);
process(x,y);
if(color=='B') color='W';
else color='B';
}
system("PAUSE");
}
}

system("PAUSE");
return 0;
}

void initBoard()
{
int i,j;
board[0][0]='O';
for(i=1;i<=19;i++) board[0][i]='-';
board[0][20]='O';
for(i=1;i<=19;i++)
{
board[i][0]='|';
for(j=1;j<=19;j++) board[i][j]='+';
board[i][20]='|';
}
board[20][0]='O';
for(i=1;i<=19;i++) board[20][i]='-';
board[20][20]='O';
board[4][4]=board[4][10]=board[4][16]=
board[10][4]=board[10][10]=board[10][16]=
board[16][4]=board[16][10]=board[16][16]='*';
}

void showBoard()
{
int i,j;
for(i=0;i<=20;i++)
{
for(j=0;j<=20;j++)
{
printf("%c",board[i][j]);
}
printf("\n");
}
}

char set(int x,int y,char color)
{
if(board[x][y]=='W' || board[x][y]=='B') return -1;//不能落子
else board[x][y]=color;
return 0;
}

//计算提子
void process(int xx,int yy)
{
char his[21][21]={0};//记录算过的棋子以节约效率
char Q[400][2]={0};//某一片棋
int e;//Q的长度。
char mcolor;//这片棋的颜色
char ecolor;//另一种颜色
int QI=0;//气数
int i,j,k,l,m;
int x,y;

for(m=0;m<5;m++)
{
i=xx+move[m][0];//为了能够完成打劫,先算别人再算自己
j=yy+move[m][1];
if(his[i][j]==0 && (board[i][j]=='W' || board[i][j]=='B')) //该位置有子开始算气
{
QI=0;
his[i][j]=1;
mcolor=board[i][j];
ecolor=(board[i][j]=='W'?'B':'W');
//printf("m=%c e=%c\n",mcolor,ecolor);
Q[0][0]=i;
Q[0][1]=j;
e=1;
for(k=0;k<e;k++)
{
for(l=0;l<4;l++)
{
x=Q[k][0]+move[l][0];
y=Q[k][1]+move[l][1];
//printf("x=%d y=%d\n",x,y);
//system("PAUSE");
if(x>0 && y>0 && x<20 && y<20 && his[x][y]==0)
{
if(board[x][y]==mcolor)//己方,长气
{
Q[e][0]=x;
Q[e][1]=y;
e++;
his[x][y]=1;
}
else
{
if(board[x][y]=='+') QI++; //空地,加气,忽略重复计算
}
}
}
}
//printf("QI=%d\n",QI);
//system("PAUSE");
if(!QI)//死棋,提子
{
for(k=0;k<e;k++)
{
board[Q[k][0]][Q[k][1]]='+';
his[Q[k][0]][Q[k][1]]=0;
}
}
}
}
}

Ⅲ C语言编制黑白棋游戏:

我写的人机对战的:
#include <stdio.h>
#include <ctype.h>

#define SIZE 8

void display(char board[][SIZE]);
int valid_moves(char board[][SIZE],int moves[][SIZE],char player);
void make_move(char board[][SIZE],int row,int col,char player);
void computer_move(char board[][SIZE],int moves[][SIZE],char player);
int get_score(char board[][SIZE],char player);
int best_move(char board[][SIZE],int moves[][SIZE],char player);

void main()
{
char board[SIZE][SIZE]={0};
int moves[SIZE][SIZE]={0};
int row=0;
int col=0;
int no_of_games=0;
int no_of_moves=0;
int invalid_moves=0;
int comp_score=0;
int user_score=0;
char y=0;
char x=0;
char again=0;
int player=0;

printf("\nREVERSI\n\n");
printf("You can go first on the first game,then we will take truns.\n");
printf(" You will be white - (0)\n I will be black - (@).\n");
printf("Select a square for your move by typing a digit for the row\n"
"and a letter for the column with no spaces between.\n");
printf("\nGood luck! press Enter to start.\n");
scanf("%c",&again);

do
{
player=++no_of_games%2;
no_of_moves=4;

for(row=0;row<SIZE;row++)
for(col=0;col<SIZE;col++)
board[row][col]=' ';

board[SIZE/2-1][SIZE/2-1]=board[SIZE/2][SIZE/2]='0';
board[SIZE/2-1][SIZE/2]=board[SIZE/2][SIZE/2-1]='@';

do
{
display(board);
if(player++%2)
{
if(valid_moves(board,moves,'0'))
{
for(;;)
{
fflush(stdin);
printf("Please enter your move (row column): ");
scanf("%d%c",&x,&y);
y=tolower(y)-'a';
x--;
if(x>=0&&y>=0&&x<SIZE&&y<SIZE&&moves[x][y])
{
make_move(board,x,y,'0');
no_of_moves++;
break;
}
else
printf("Not a valid move,try again.\n");
}
}
else
if(++invalid_moves<2)
{
fflush(stdin);
printf("\nYou have to pass,press return");
scanf("%c",&again);
}
else
printf("\nNeither of us can go, so the game is over.\n");
}
else
{
if(valid_moves(board,moves,'@'))
{
invalid_moves=0;
computer_move(board,moves,'@');
no_of_moves++;
}
else
{
if(++invalid_moves<2)
printf("\nI have to pass, your go\n");
else
printf("\nNeither of us can go, so the game is over.\n");
}
}
}while(no_of_moves<SIZE*SIZE&&invalid_moves<2);

display(board);

comp_score=user_score=0;
for(row=0;row<SIZE;row++)
for(col=0;col<SIZE;col++)
{
comp_score+=board[row][col]=='@';
user_score+=board[row][col]=='0';
}
printf("The final score is:\n");
printf("Computer %d\n User %d\n\n",comp_score,user_score);

fflush(stdin);
printf("Do you want to play again (y/n): ");
scanf("%c",&again);
}while(tolower(again)=='y');

printf("\nGoodbye\n");
}

void display(char board[][SIZE])
{
int row=0;
int col=0;
char col_label='a';

printf("\n ");
for(col=0;col<SIZE;col++)
printf(" %c",col_label+col);
printf("\n");

for(row=0;row<SIZE;row++)
{
printf(" +");
for(col=0;col<SIZE;col++)
printf("---+");
printf("\n%2d|",row+1);

for(col=0;col<SIZE;col++)
printf(" %c |",board[row][col]);
printf("\n");
}

printf(" +");
for(col=0;col<SIZE;col++)
printf("---+");
printf("\n");
}

int valid_moves(char board[][SIZE],int moves[][SIZE],char player)
{
int rowdelta=0;
int coldelta=0;
int row=0;
int col=0;
int x=0;
int y=0;
int no_of_moves=0;

char opponent=(player=='0')?'@':'0';

for(row=0;row<SIZE;row++)
for(col=0;col<SIZE;col++)
moves[row][col]=0;

for(row=0;row<SIZE;row++)
for(col=0;col<SIZE;col++)
{
if(board[row][col]!=' ')
continue;
for(rowdelta=-1;rowdelta<=1;rowdelta++)
for(coldelta=-1;coldelta<=1;coldelta++)
{
if(row+rowdelta<0||row+rowdelta>=SIZE||
col+coldelta<0||col+coldelta>=SIZE||
(rowdelta==0&&coldelta==0))
continue;
if(board[row+rowdelta][col+coldelta]==opponent)
{
x=row+rowdelta;
y=col+coldelta;

for(;;)
{
x+=rowdelta;
y+=coldelta;

if(x<0||x>=SIZE||y<0||y>=SIZE)
break;

if(board[x][y]==' ')
break;
if(board[x][y]==player)
{
moves[row][col]=1;
no_of_moves++;
break;
}
}
}
}
}
return no_of_moves;
}

void make_move(char board[][SIZE],int row,int col,char player)
{
int rowdelta=0;
int coldelta=0;
int x=0;
int y=0;
char opponent=(player=='0')?'@':'0';

board[row][col]=player;

for(rowdelta=-1;rowdelta<=1;rowdelta++)
for(coldelta=-1;coldelta<=1;coldelta++)
{
if(row+rowdelta<0||row+rowdelta>=SIZE||
col+coldelta<0||col+coldelta>=SIZE||
(rowdelta==0&&coldelta==0))
continue;

if(board[row+rowdelta][col+coldelta]==opponent)
{
x=row+rowdelta;
y=col+coldelta;

for(;;)
{
x+=rowdelta;
y+=coldelta;

if(x<0||x>=SIZE||y<0||y>=SIZE)
break;
if(board[x][y]==' ')
break;
if(board[x][y]==player)
{
while(board[x-=rowdelta][y-=coldelta]==opponent)
board[x][y]=player;
break;
}
}
}
}
}

int get_score(char board[][SIZE],char player)
{
int score=0;
int row=0;
int col=0;
char opponent=player=='0'?'@':'0';

for(row=0;row<SIZE;row++)
for(col=0;col<SIZE;col++)
{
score-=board[row][col]==opponent;
score+=board[row][col]==player;
}
return score;
}

int best_move(char board[][SIZE],int moves[][SIZE],char player)
{
int row=0;
int col=0;
int i=0;
int j=0;

char opponent=player=='0'?'@':'0';

char new_board[SIZE][SIZE]={0};
int score=0;
int new_score=0;

for(row=0;row<SIZE;row++)
for(col=0;col<SIZE;col++)
{
if(!moves[row][col])
continue;

for(i=0;i<SIZE;i++)
for(j=0;j<SIZE;j++)
new_board[i][j]=board[i][j];

make_move(new_board,row,col,player);

new_score=get_score(new_board,player);

if(score<new_score)
score=new_score;
}
return score;
}

void computer_move(char board[][SIZE],int moves[][SIZE],char player)
{
int row=0;
int col=0;
int best_row=0;
int best_col=0;
int i=0;
int j=0;
int new_score=0;
int score=100;
char temp_board[SIZE][SIZE];
int temp_moves[SIZE][SIZE];
char opponent=player=='0'?'@':'0';

for(row=0;row<SIZE;row++)
for(col=0;col<SIZE;col++)
{
if(moves[row][col]==0)
continue;

for(i=0;i<SIZE;i++)
for(j=0;j<SIZE;j++)
temp_board[i][j]=board[i][j];

make_move(temp_board,row,col,player);
valid_moves(temp_board,temp_moves,opponent);
new_score=best_move(temp_board,temp_moves,opponent);

if(new_score<score)
{
score=new_score;
best_row=row;
best_col=col;
}
}
make_move(board,best_row,best_col,player);
}
我已经用英文说明了如何操作了......看不懂的我在这个说一下.
先按回车开始游戏,然后输入行号和列号就可以了...一局结束之后,
会提示是否再来一盘输入大写的Y继续大写的N结束程序!!!
我已经对操作说的很明确了!~~~~~你控制的是白棋(0),首先按回车开始游戏,然后输入行号(数字),列号(字符)就行了.......如果还是不行的话,那就是你更本不懂黑白棋的规则....

Ⅳ 急需用c语言写中国象棋的代码,只要红色方布局和走棋

接上面中国象棋代码:

if( check_turn == 12) //相的走法规范

{ if((x == check_x && y == check_y))

{temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;

printf("三思而后行 "); printf("还是你的回合"); Sleep(500);

}

else if( x >= 15 &&(abs(y - check_y) == 8 && abs(x - check_x) == 4))

{if((x == 22 && (y == 11 || y == 27))||(x == 18 &&

( y == 3 || y == 19 || y == 35)) ||(x == 14 && (y == 11|| y ==27)))

{ if( map[(x+check_x)/2][(y+check_y)/2] == '+') check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else {printf("棋子卡住,不可执行"); Sleep(500); } }

else {printf("不合法的下法 ");Sleep(500); }

}

else {printf("不合法的下法 "); Sleep(500); }

}

if( check_turn == 13) //士的走法规范

{ if((x == check_x && y == check_y))

{temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;

printf("三思而后行 "); printf("还是你的回合"); Sleep(500); }

else if( abs(x - check_x)== 2 && abs( y - check_y) == 4 &&((x==22 &&(y == 15

|| y == 23)) || ( x == 20 && y == 19) || ( x == 18 && ( y == 15 || y == 23)))) {check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map); }

else { printf("不合法的下法 "); Sleep(500); } }

if( check_turn == 14) //将的走法规范

{ if((x == check_x && y == check_y))

{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;

printf("三思而后行 "); printf("还是你的回合"); Sleep(500); }

else if( ((abs(x - check_x)== 2 && abs( y - check_y) == 0 )|| (abs(x - check_x)== 0

&&abs( y - check_y) == 4)) && x >= 18 && x <= 22 && y >= 15 && y <= 23 )

{ check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map); }

else { printf("不合法的下法 "); Sleep(500); } }

if( check_turn == 15) //炮的走法规范

{ if((x == check_x && y == check_y))

{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;

printf("三思而后行 "); printf("还是你的回合"); Sleep(500); }

else if( y == check_y )

{ int check_pao = 0;

if( x > check_x)

{ for(j = check_x + 2; j<= x ;j = j+ 2)

{ if(map[j][y] == '+' ); else check_pao++;}

if(check_pao == 1&& temp == '+') // 直线行走但不可吃棋子 check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else if( check_pao == 2 && temp != '+') //跳跃吃棋 check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else { printf("不合法的下法 "); Sleep(500); } }

else { for(j = check_x - 2; j>= x;j = j - 2)

{ if(map[j][y] == '+' ); else { check_pao++;} }

if(check_pao == 1&& temp == '+') //直线行走但不可吃棋子 check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else if( check_pao == 2 && temp != '+') //跳跃吃棋 check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else { printf("不合法的下法 "); Sleep(500); } }

}

else if( x == check_x )

{ int check_pao = 0;

if( y > check_y)

{ for(j = check_y + 4; j<= y ;j = j+4)

{ if(map[x][j] == '+' ); else check_pao++;}

if(check_pao == 1&& temp == '+') //直线行走但不可吃棋子 check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else if( check_pao == 2 && temp != '+') //跳跃吃棋 check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else { printf("不合法的下法 "); Sleep(500); } }

else {for(j = check_y - 4; j>= y;j = j - 4)

{if(map[x][j] == '+' ); else check_pao++;}

if(check_pao == 1&& temp == '+') //直线行走但不可吃棋子 check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else if( check_pao == 2 && temp != '+') //跳跃吃棋 check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else { printf("不合法的下法 "); Sleep(500); } }

}

else { printf("不合法的下法 ");Sleep(500); }

}

if( check_turn == 16) //卒的走法规范

{ if ( x >= 14)

{ if((x == check_x && y == check_y))

{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;

printf("三思而后行 "); printf("还是你的回合"); Sleep(500); }

else if( x == check_x - 2 && y == check_y) check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else { printf("不合法的下法 "); Sleep(500); }

}

else{ if((x == check_x && y == check_y))

{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;

printf("三思而后行 "); printf("还是你的回合"); Sleep(500); }

else if((x - check_x == 0 && abs(y-check_y) ==4) ||( x - check_x == -2

&& abs(y-check_y) == 0)) check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else { printf("不合法的下法 "); Sleep(500); } }

}

}

else { if( check_turn == 20) //车的走法规范 (帅方)

{ if((x == check_x && y == check_y))

{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;

printf("三思而后行 "); printf("还是你的回合"); Sleep(500); }

else if( y == check_y )

{ if( x > check_x)

{ for(j = check_x + 2; j < x;j = j + 2)

{ if(map[j][y] == '+'); else {printf("不合法的下法 "); Sleep(500); break; } }

if( j >= x) check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

}

if( x < check_x)

{ for(j = check_x - 2; j > x;j = j - 2)

{ if(map[j][y] == '+'); else { printf("不合法的下法 "); Sleep(500); break; } }

if( j <= x) check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

}

}

else if( x == check_x )

{ if( y > check_y)

{ for(j = check_y + 4; j < y;j = j + 4)

{ if(map[x][j] == '+'); else { printf("不合法的下法 "); Sleep(500); break; } }

if( j >= y) check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

}

if( y < check_y)

{ for(j = check_y - 4; j > y;j = j - 4)

{ if(map[x][j] == '+'); else { printf("不合法的下法 ");Sleep(500); break; } }

if( j <= y) check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

}

}

else { printf("不合法的下法 "); Sleep(500); }

}

if( check_turn == 21) //马的走法规范

{ if((x == check_x && y == check_y))

{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;

printf("三思而后行 ");printf("还是你的回合"); Sleep(500); }

else if( (abs( x - check_x) == 2&& abs( y - check_y) == 8)&&

map[check_x][(y+check_y)/2] =='+')

{ check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map); }

else if( (abs( x - check_x) == 4&& abs( y - check_y) == 4)&&

map[(x + check_x)/2][check_y] == '+' )

{ check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map); }

else { printf("不合法的下法 ");Sleep(500); } }

if( check_turn == 22) //相的走法规范

{ if((x == check_x && y == check_y))

{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;

printf("三思而后行 ");printf("还是你的回合"); Sleep(500); }

else if( x <= 12 && (abs(y - check_y) == 8 && abs(x - check_x) == 4))

{ if((x == 4 && (y == 11 || y == 27))||(x == 8 && ( y == 3 || y == 19 || y == 35))

||(x == 12 && (y == 11|| y ==27)))

{ if( map[(x+check_x)/2][(y+check_y)/2] == '+') check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else { printf("棋子卡住,不可执行");Sleep(500); } }

else {printf("不合法的下法 ");Sleep(500); }

}

else { printf("不合法的下法 ");Sleep(500); } }

if( check_turn == 23) //士的走法规范

{ if((x == check_x && y == check_y))

{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;

printf("三思而后行 ");printf("还是你的回合"); Sleep(500); }

else if( abs(x - check_x)== 2 && abs( y - check_y) == 4 &&((x==4 &&

(y == 15 || y == 23)) || ( x == 6 && y == 19) || ( x == 8 && ( y == 15 || y == 23))))

{ check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map); }

else { printf("不合法的下法 ");Sleep(500); } }

if( check_turn == 24) //将的走法规范

{ if((x == check_x && y == check_y))

{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;

printf("三思而后行 ");printf("还是你的回合"); Sleep(500); }

else if( ((abs(x - check_x)== 2 && abs( y - check_y) == 0 )|| (abs(x - check_x)== 0 &&abs( y - check_y) == 4)) && x >= 4 && x <= 8 && y >= 15 && y <= 23 )

{ check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map); }

else {printf("不合法的下法 ");Sleep(500); } }

if( check_turn == 25) //炮的走法规范

{ if((x == check_x && y == check_y))

{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;

printf("三思而后行 ");printf("还是你的回合"); Sleep(500); }

else if( y == check_y )

{ int check_pao = 0;

if( x > check_x)

{ for(j = check_x + 2; j<= x ;j = j+ 2)

{ if(map[j][y] == '+' ); else check_pao++;}

if(check_pao == 1&& temp == '+') //直线行走但不可吃棋子 check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else if( check_pao == 2 && temp != '+') //跳跃吃棋 check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else { printf("不合法的下法 ");Sleep(500); } }

else { for(j = check_x - 2; j>= x;j = j - 2)

{ if(map[j][y] == '+' ); else { check_pao++;} }

if(check_pao == 1&& temp== '+') //直线行走但不可吃棋子 check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else if( check_pao == 2 && temp != '+') //跳跃吃棋 check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else { printf("不合法的下法 ");Sleep(500); } }

}

else if( x == check_x )

{ int check_pao = 0;

if( y > check_y)

{ for(j = check_y + 4; j<= y ;j = j+4)

{ if(map[x][j] == '+' ); else check_pao++;}

if(check_pao == 1&& temp == '+') //直线行走但不可吃棋 check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else if( check_pao == 2 && temp != '+') //跳跃吃棋 check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else { printf("不合法的下法 ");Sleep(500); } }

else { for(j = check_y - 4 ; j>= y;j = j - 4)

{ if(map[x][j] == '+' ); else check_pao++;}

if(check_pao ==1&& temp == '+') //直线行走但不可吃棋子 check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else if( check_pao == 2&& temp != '+') //跳跃吃棋 check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else { printf("不合法的下法 ");Sleep(500); } }

}

else { printf("不合法的下法 ");Sleep(500); }

}

if( check_turn == 26) //卒的走法规范

{ if( x <= 12)

{ if((x == check_x && y == check_y))

{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;

printf("三思而后行 "); printf("还是你的回合"); Sleep(500); }

else if( x == check_x + 2 && y == check_y) check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else { printf("不合法的下法 ");Sleep(500); } }

else{ if((x == check_x && y == check_y))

{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;

printf("三思而后行 ");printf("还是你的回合"); Sleep(500); }

else if((x - check_x == 0 && abs(y-check_y) ==4) ||( x - check_x == 2

&& abs(y-check_y) == 0)) check_main2(&temp,&temp1,&turn,&turn1,&num,&if_return,map);

else { printf("不合法的下法 ");Sleep(500); } }

}

}

}

}

system("cls");

if( if_return) return;

for(i = 0; i < 27; i++)puts(map[i]);

}

Sleep(5000);

}

int main( )

{ while(1)

{ xiangqi( );

printf(" 重来,请按键. ");

getch( );

}

return 0;

}

热点内容
创建数据库并设置编码 发布:2025-01-31 11:11:52 浏览:781
搭建数据中心需要的服务器配置 发布:2025-01-31 11:11:44 浏览:590
c语言小数点后四舍五入 发布:2025-01-31 11:10:10 浏览:496
httpslinux 发布:2025-01-31 11:10:09 浏览:828
java4 发布:2025-01-31 11:08:42 浏览:355
什么是密码屏蔽 发布:2025-01-31 11:05:13 浏览:216
一个算法的效率可分为 发布:2025-01-31 11:05:12 浏览:639
win7用户名密码是什么 发布:2025-01-31 10:57:38 浏览:394
网址端口访问 发布:2025-01-31 10:49:30 浏览:512
javaweb代码 发布:2025-01-31 10:37:54 浏览:259