當前位置:首頁 » 編程語言 » 三步棋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;

}

熱點內容
ftpdos命令上傳 發布:2025-01-31 08:14:44 瀏覽:105
intenumjava 發布:2025-01-31 08:14:37 瀏覽:802
android3x 發布:2025-01-31 08:13:03 瀏覽:600
如何購買安卓版live2d 發布:2025-01-31 08:13:01 瀏覽:279
python交互輸入 發布:2025-01-31 08:12:53 瀏覽:427
requestdatapython 發布:2025-01-31 08:02:01 瀏覽:44
javades加密工具 發布:2025-01-31 07:54:04 瀏覽:244
電話如何配置ip 發布:2025-01-31 07:48:48 瀏覽:300
2021賓士e300l哪個配置性價比高 發布:2025-01-31 07:47:14 瀏覽:656
sqlserver2008光碟 發布:2025-01-31 07:32:13 瀏覽:578