當前位置:首頁 » 編程語言 » 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 14:42:31 瀏覽:169
hue編譯器 發布:2025-01-17 14:42:26 瀏覽:905
馬自達編程 發布:2025-01-17 14:21:41 瀏覽:492
android語音demo 發布:2025-01-17 14:19:25 瀏覽:700
點歌機怎麼選切換安卓系統 發布:2025-01-17 14:05:33 瀏覽:720
java壓縮與解壓縮 發布:2025-01-17 14:03:24 瀏覽:926
python代碼保護 發布:2025-01-17 14:02:22 瀏覽:324
王者榮耀電腦如何改戰區安卓 發布:2025-01-17 13:23:18 瀏覽:815
華為手機如何開啟說出密碼 發布:2025-01-17 13:23:12 瀏覽:102
伺服器在美國說明什麼 發布:2025-01-17 13:14:10 瀏覽:12