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

c语言象棋

发布时间: 2022-11-27 08:03:38

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

#include #include #include #include #include
int x,y,i,j,k,p,q, num = 1, round; //象棋游戏的全局变量
int place_x1 = 0,place_y1 = 0,place_x2 = 0,place_y2 = 0;
int check_x,check_y,check_turn; //基本参数
char ch, turn = 'O',turn1 = 'N',temp,temp1;
char check_1[9][3] ={"车","马","象","士","将","炮","兵","+-"}; //取棋子时只判断前8合法
char check_2[9][3] ={"车","马","相","仕","帅","炮","卒","+-"}; //下棋时多一空位合法
char check[3];
void check_main1(char* temp,char* temp1,char* turn,char* turn1,int *num,int *if_return,char map[100][100])
{ //(象棋函数 判断 将方 下棋是否合法
check[0] = *temp; check[1] = *temp1; check[2] = '\0'; char a,b;
for ( i = 0; i < 8; i++)
{ if ( strcmp(check_2[i],check) == 0)
{ *temp = *turn; *temp1 = *turn1; *turn = 'O'; *turn1 = 'N';
if( i < 7){ printf(" 帅方的%s被吃\n",check_2[i]); Sleep(500); } *num = *num + 1;
for( k = 4; k <= 8; k = k + 2) //判断 帅 是否死亡
{ for(j = 15; j <= 23; j= j+ 4)
{ if (map[k][j] == check_2[4][0] && map[k][j+1] == check_2[4][1])
{ place_x2 = k; place_y2 = j; break; } }
if( j <= 23) break;
}
if( k == 10)
{printf(" 帅 被将死 将方获得胜利\n"); printf("按任意键返回菜单");
getch( ); *if_return = 1; return;
}
for( k = 18; k <= 22; k = k + 2) //判断 将 是否死亡
{for(j = 15; j <= 23; j= j+ 4)
{if(map[k][j] == check_1[4][0] && map[k][j+1] == check_1[4][1])
{place_x1 = k; place_y1 = j; break; } }
if( j <= 23) break;
}
if ( k == 24)
{printf(" 将 被将死 帅方获得胜利\n"); printf("按任意键返回菜单");
getch( ); *if_return = 1; return;
}
if ( place_y1 == place_y2)
{for( k = place_x2 + 2; k <= place_x1 - 2; k = k +2) {if(map[k][place_y1] != '+') break;}
if( k == place_x1)
{if(round == 1) printf(" 将方对将 帅方胜利");
else if( round == 2) printf(" 帅方对将 将方胜利");
printf("按任意键返回菜单"); getch( ); *if_return = 1; return;
}
}
break;
}
} // for ( i = 0; i < 8; i++)循环结束
if( i == 8) {printf("不合法的走法\n"); Sleep(500); }
}
void check_main2(char* temp,char* temp1,char* turn,char* turn1,int *num,int *if_return,char map[100][100])
{ //象棋函数 判断 帅方 下棋是否合法
check[0] = *temp; check[1] = *temp1; check[2] = '\0'; char a,b;
for ( i = 0; i < 8; i++)
{if ( strcmp(check_1[i],check) == 0)
{ *temp = *turn; *temp1 = *turn1; *turn = 'O'; *turn1 = 'N';
if( i < 7) {printf(" 将方的%s被吃",check_1[i]); Sleep(500); } *num = *num + 1;
for( k = 4; k <= 8; k = k + 2) //判断 帅 是否死亡
{for(j = 15; j <= 23; j= j+ 4)
{if(map[k][j] == check_2[4][0] && map[k][j+1] == check_2[4][1])
{place_x2 = k; place_y2 = j; break; } }
if( j <= 23) break;
}
if( k == 10)
{printf(" 帅 被将死 将方获得胜利\n");printf("按任意键返回菜单"); getch( );
*if_return = 1; return;
}
for( k = 18; k <= 22; k = k + 2) //判断 将 是否死亡
{for(j = 15; j <= 23; j= j+ 4)
{if(map[k][j] == check_1[4][0] && map[k][j+1] == check_1[4][1])
{place_x1 = k; place_y1 = j; break; } }
if( j <= 23) break;
}
if( k == 24)
{printf(" 将 被将死 帅方获得胜利\n");printf("按任意键返回菜单"); getch( );
*if_return = 1; return; }
if( place_y1 == place_y2)
{for( k=place_x2 + 2; k <= place_x1 - 2; k=k +2) {if(map[k][place_y1] != '+') break; }
if( k == place_x1)
{if(round==1)printf(" 将方对将 帅方胜利");else if(round==2)printf(" 帅方对将 将方胜利");
printf("按任意键返回菜单"); getch( ); *if_return = 1; return; }
}
break;
}
} // for ( i = 0; i < 8; i++)循环结束
if( i == 8) {printf("不合法的走法\n"); Sleep(500); }
}
void xiangqi( ) //象棋主程序
{ char map[100][100]= { "[[===================================]]",
"[| ①将 【象棋】 ②帅 |]",
"[[===================================]]",
"[[-----------------------------------]]",
"[[ 车—-马—-相—-仕—-帅—-仕—-相—-马—-车]]",
"[[ | | | | \\ | / | | | | ]]",
"[[ +-—-+-—-+-—-+-—-+-—-+-—-+-—-+-—-+-]]",
"[[ | | | | / | \\ | | | | ]]",
"[[ +-—-炮—-+-—-+-—-+-—-+-—-+-—-炮—-+-]]",
"[[ | | | | | | | | | ]]",
"[[ 卒—-+-—-卒—-+-—-卒—-+-—-卒—-+-—-卒]]",
"[[ | | | | | | | | | ]]",
"[[ +-—-+-—-+-—-+-—-+-—-+-—-+-—-+-—-+-]]",
"[[===================================]]",
"[[ +-—-+-—-+-—-+-—-+-—-+-—-+-—-+-—-+-]]",
"[[ | | | | | | | | | ]]",
"[[ 兵—-+-—-兵—-+-—-兵—-+-—-兵—-+-—-兵]]",
"[[ | | | | | | | | | ]]",
"[[ +-—-炮—-+-—-+-—-+-—-+-—-+-—-炮—-+-]]",
"[[ | | | | \\ | / | | | | ]]",
"[[ +-—-+-—-+-—-+-—-+-—-+-—-+-—-+-—-+-]]",
"[[ | | | | / | \\ | | | | ]]",
"[[ 车—-马—-象—-士—-将—-士—-象—-马—-车]]",
"[[-----------------------------------]]",
"[[===================================]]"};
int if_return = 0;
system("mode con cols=45 lines=32"); //迷你界面
system("color 70");
printf("[[==================================]]\n");
printf("[[ -------------------------------- ]]\n");
printf("[[ | | ]]\n");
printf("[[ | 【<>】 | ]]\n");
printf("[[ | | ]]\n");
printf("[[ |------------------------------| ]]\n");
printf("[[ | 控制wasd双方轮流控制指针下棋| ]]\n");
printf("[[ |------------------------------| ]]\n");
printf("[[ | 键盘输入大小写 ' M ' | ]]\n");
printf("[[ | 都视为确认下棋 | ]]\n");
printf("[[ |------------------------------| ]]\n");
printf("[[ | 为了方便区分棋子 | ]]\n");
printf("[[ | 后手方全设为繁体复杂字体 | ]]\n");
printf("[[ |------------------------------| ]]\n");
printf("[[ |------------------------------| ]]\n");
printf("[[ | 我已阅读规则,按任意键继续 | ]]\n");
printf("[[ |------------------------------| ]]\n");
printf("[[==================================]]\n");
getch( ); system("mode con cols=45 lines=32"); //迷你界面
system("color 70");
for ( i = 0; i < 27; i++){ puts(map[i]); Sleep(100); }
x = 6, y = 19; temp = map[x][y]; temp1 = map[x][y+1];
while(num)
{ if (num % 2 == 1 &&num / 2 % 2 == 0){ printf(" 现在是'将'的回合\n");round = 1; }
else if( num %2 == 1){ printf(" 现在轮到'帅'的回合了\n");round = 2; }
ch = getch( );
if ( ch == 's') //下移
{ if ( map[x+1][y]!= '-')
{map[x][y] =temp; map[x][y+1] = temp1; x = x + 2;
temp = map[x][y]; temp1 = map[x][y+1]; map[x][y] = turn; map[x][y+1] = turn1; }
}
else if ( ch == 'a') //左移
{ if (map[x][y-1]!=' ')
{map[x][y] =temp; map[x][y+1] = temp1; y = y - 4;
temp = map[x][y]; temp1 = map[x][y+1]; map[x][y] = turn; map[x][y+1] = turn1; }
}
else if ( ch == 'w') //上移
{ if ( map[x-1][y]!= '-')
{map[x][y] =temp; map[x][y+1] = temp1; x = x - 2; temp = map[x][y];
temp1 = map[x][y+1]; map[x][y] = turn; map[x][y+1] = turn1; }
}
else if ( ch == 'd') //右移
{ if (map[x][y+2]!=']')
{map[x][y] =temp; map[x][y+1] = temp1; y = y + 4; temp = map[x][y];
temp1 = map[x][y+1]; map[x][y] = turn; map[x][y+1] = turn1; }
}
else if( ch == 'm' || ch =='M') //M确认要移动的棋子,或确认要移到的目的地
{ if (num % 2 == 1 && temp != '+' && temp1 != '-') //取棋
{check[0] = temp; check[1] = temp1; check[2] = '\0';
if ( round == 1)
{ for ( i = 0; i < 7; i++) //将方
{ if ( strcmp(check_1[i],check) == 0)
{turn = temp; turn1 = temp1; temp = '+'; temp1 = '-';
check_x = x; check_y = y; check_turn = 10 + i; num++; break; }
}
if( i == 7){ printf("这不是你的棋子\n"); Sleep(500); }
}
else if( round == 2)
{for ( i = 0; i < 7; i++) //帅方
{ if( strcmp(check_2[i],check) == 0)
{turn = temp; turn1 = temp1; temp = '+'; temp1 = '-';
check_x = x; check_y = y; check_turn = 20 + i; num++; break; }
}
if( i == 7){ printf("这不是你的棋子\n"); Sleep(500); }
}
}
else if( num % 2 == 0) //放棋
{ char check_1[8][3] ={"车","马","象","士","将","炮","卒","+-"};
char check_2[8][3] ={"俥","马","相","仕","帅","軳","兵","+-"};
//中界 楚河上下坐标 12 15 往下2 往右4
if( check_turn < 20) //将方
{if( check_turn == 10) //车的走法规范
{ if((x == check_x && y == check_y))
{temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n"); 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("不合法的下法\n"); Sleep(500); break; } }
if( j >= x) check_main1(&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("不合法的下法\n"); Sleep(500); break; }
}
if( j <= x)check_main1(&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("不合法的下法\n"); Sleep(500); break; }
}
if( j >= y) check_main1(&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("不合法的下法\n"); Sleep(500); break; }
}
if( j <= y) check_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map);
}
}
else { printf("不合法的下法\n"); Sleep(500); }
}
if( check_turn == 11) //马的走法规范
{if((x == check_x && y == check_y))
{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n"); printf("还是你的回合"); Sleep(500); }
else if( (abs( x - check_x) == 2&& abs( y - check_y) == 8)&& map[check_x][(y+check_y)/2] =='+')
{check_main1(&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_main1(&temp,&temp1,&turn,&turn1,&num,&if_return,map); }
else { printf("不合法的下法\n");Sleep(500); }
} //其余代码在后续

② c语言 象棋 走法 表示

可以使用坐标(x,y)的增量表示
比如马有8种走法(-2,-1),(-2,+1),(-1,+2),(-1,-2),(+2,-1),(+2,+1),(+1,+2),(+1,-2),
象的4种走法(-2,-2),(-2,+2),(+2,-2),(+2,+2)

③ 如何用C语言程序输出国际象棋棋盘

#include"stdio.h"
#include<windows.h>
main()
{
int i,j;
SetConsoleOutputCP(437); //显示大于127的asc码
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
if((i+j)%2==0)
printf("%c%c",219,219);
else
printf(" ");
printf("\n");
}
}
如果你用的是Vc6的话,可以打个补丁了,
我也不知道为什么,上次查知道要加东西才能显示
需要用windows.h里面的东西,加一行调用api,可惜我只是记下来了,却看不懂

④ c语言国际象棋等比求解

c语言国际象棋等比求解解答如下:
/*象棋盘:"1"代表黑格,""代表白格*/
#includeintmain(){
for(inti=1;i<=8;i++)//控制行数:一共8行
for(intj=1;j<=8;j++)//控制列数:一共8列
if((i+j)%2==0)//当行数+列数为偶数时打印“1”printf("1");
elseprintf("");//当行数+列数为奇数时打印“”
printf(" ");
returno;
等比数列是指从第二项起,每一项与它的前一项的比值等于同一个常数的一种数列,常用G、P表示。这个常数叫做等比数列的公比,公比通常用字母q表示(q≠0),等比数列a1≠0。其中{an}中的每一项均不为0。注:q=1时,an为常数列。
棋盘为正方形,由64个黑白(深色与浅色)相间的格子组成;棋子分黑白(深色与浅色)两方共32枚,每方各16枚。虽然汉语称之为西洋棋或国际象棋,但是实际上它起源于亚洲,后由阿拉伯人传入欧洲,成为国际通行棋种,也是一项智力竞技运动,曾一度被列为奥林匹克运动会正式比赛项目。

⑤ c语言做象棋要下载什么啊

graphics.h库。用C语言做一个中国象棋游戏,其要点是怎么把抽象的规则变成形象、具体的代码,需要下载graphics.h库。C语言是一种计算机程序设计语言。既有高级语言的特点,又具有汇编语言的特点。

⑥ C语言输出国际象棋棋盘

ASCII码只有127个。128以后的是扩展ASCII码,一般在欧洲语言中表示一般特殊字母或符号,在中国用来把两个这样的码拼成一个汉字。
128-255是非打印字符。

VC++ 不能打印219;TC2.0才可以打印
你可以用
printf("%c%c", '\xA1', '\xF6'); 代替。也是黑格子,像:

int main()
{
int i,j;
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
if((i+j)%2==0)
printf("%c%c", '\xA1', '\xF6');
else
printf(" ");
printf("\n");
}
return 0;
}

⑦ 用C语言输出中国象棋棋盘的源代码!!急!急!急!

密码:yq12

⑧ 用C语言编写象棋盘

你得看你用的是什么显示库了,必须调用库函数来对下层图像进行处理,tuboC有图形库的。用划线的函数写国际象棋for(int
i
=
0;i<9;i++){
PAINTLINE();
for(int
j=0;
j<9;j++)
{
if((i%2!=0)&&(j%2==0))
{
把当前格子画成实心的。
}
PAINTLINE();
}}
大概方法就这么简单了,楼主可以下个TUBOC然后再找点画图的资料看看,调用两个函数就可以了。呵呵

⑨ 求C语言程序,在中国象棋棋盘上,放置一个马,能够不重复走过棋盘的每一个位置,输出九十个坐标

#include<stdio.h>
/*
问题描述:在n*m的棋盘上,马只能走日字。马从(x,y)出发,把棋盘的每一个点都走一遍,且只走一次,

找出所有路径。
*/
void find(int x,int y,int dep);
int check(int x,int y);
void output();

int n=5,m=4;
int fx[8]={1,2,2,1,-1,-2,-2,-1};
int fy[8]={2,1,-1,-2,-2,-1,1,2};
int a[5][4];
int dep,x,y,count;
int main()
{
int i,j;
dep=1;////记录递归深度,即走过的点的个数,当dep=n*m,找到一组解
count=0;

printf("Please input the original point:\n");
scanf("%d%d",&x,&y);

if(x<0 || x>4 || y<0 || y>3)
{
printf("wrong data!\n");
return 1;
}

for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
a[i][j]=0;
}
}

a[x][y]=1;

find(x,y,2);
if(count==0)
{
printf("NO solution!\n");
}
else
{
printf("Total count=%d\n",count);
}
return 0;
}

void find(int x,int y,int dep)
{
int i;
int xx,yy;
for(i=0;i<8;i++)//加上方向增量,形成新的坐标
{
xx=x+fx[i];
yy=y+fy[i];

if(check(xx,yy)==1)//判断坐标是否出界,或者已经走过
{
a[xx][yy]=dep;//走向新的坐标
if(dep==n*m)
{
output();
}
else
{
find(xx,yy,dep+1);//从新的坐标出发,递归下一层
}
a[xx][yy]=0;//回溯,恢复未走标志
}
}
}

int check(int x,int y)
{
int flag = 1;
if(x<0 || x>4 || y<0 || y>3)
{
flag = 0;
}
if(a[x][y]!=0)
{
flag=0;
}
return flag;
}

void output()
{
count++;
printf("\ncount=%d\n",count);

int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%4d",a[i][j]);
}
printf("\n");
}
}
//原始文件请参考:CSDN马的遍历问题

⑩ 急需用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-17 13:23:18 浏览:814
华为手机如何开启说出密码 发布:2025-01-17 13:23:12 浏览:101
服务器在美国说明什么 发布:2025-01-17 13:14:10 浏览:11
启辰t90有哪些配置 发布:2025-01-17 13:05:40 浏览:38
手机微博密码怎么改密码忘了怎么办 发布:2025-01-17 13:04:44 浏览:959
微笑云服务器 发布:2025-01-17 13:03:25 浏览:83
android顶部标题栏 发布:2025-01-17 13:02:28 浏览:692
androidjs传递参数 发布:2025-01-17 12:51:54 浏览:477
建筑大师辅助脚本 发布:2025-01-17 12:47:33 浏览:331
sql向上 发布:2025-01-17 12:43:57 浏览:275