本文目录一览:
用C语言输出中国象棋棋盘的源代码!!急!急!急!
#include stdio.h
void main()
{int r=0;
int c=0;
int star_one=10;
for(r=0;r=star_one*9;r+=2)
{ for(c=0;c=star_one*8;c++)
{if((r%star_one==0 || c%star_one==0)c%2==0 (r=star_one*4 || r=star_one*4+star_one) || (r=star_one*4 r=star_one*4+star_one (c==0 || c==star_one*8)))
{printf("%c",'*');}
else
{printf("%c",' ');}
}
printf("\n");
}
}
急需用c语言写中国象棋的代码,只要红色方布局和走棋
接上面中国象棋代码:
if( check_turn == 12) //相的走法规范
{ if((x == check_x y == check_y))
{temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n"); 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("不合法的下法\n");Sleep(500); }
}
else {printf("不合法的下法\n"); Sleep(500); }
}
if( check_turn == 13) //士的走法规范
{ 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) == 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("不合法的下法\n"); Sleep(500); } }
if( check_turn == 14) //将的走法规范
{ 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) == 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("不合法的下法\n"); Sleep(500); } }
if( check_turn == 15) //炮的走法规范
{ 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 )
{ 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("不合法的下法\n"); 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("不合法的下法\n"); 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("不合法的下法\n"); 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("不合法的下法\n"); Sleep(500); } }
}
else { printf("不合法的下法\n");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("三思而后行\n"); printf("还是你的回合"); Sleep(500); }
else if( x == check_x - 2 y == check_y) check_main1(temp,temp1,turn,turn1,num,if_return,map);
else { printf("不合法的下法\n"); Sleep(500); }
}
else{ if((x == check_x y == check_y))
{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n"); 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("不合法的下法\n"); Sleep(500); } }
}
}
else { if( check_turn == 20) //车的走法规范 (帅方)
{ 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_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("不合法的下法\n"); 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("不合法的下法\n"); 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("不合法的下法\n");Sleep(500); break; } }
if( j = y) check_main2(temp,temp1,turn,turn1,num,if_return,map);
}
}
else { printf("不合法的下法\n"); Sleep(500); }
}
if( check_turn == 21) //马的走法规范
{ 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_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("不合法的下法\n");Sleep(500); } }
if( check_turn == 22) //相的走法规范
{ if((x == check_x y == check_y))
{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n");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("不合法的下法\n");Sleep(500); }
}
else { printf("不合法的下法\n");Sleep(500); } }
if( check_turn == 23) //士的走法规范
{ 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) == 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("不合法的下法\n");Sleep(500); } }
if( check_turn == 24) //将的走法规范
{ 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) == 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("不合法的下法\n");Sleep(500); } }
if( check_turn == 25) //炮的走法规范
{ 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 )
{ 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("不合法的下法\n");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("不合法的下法\n");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("不合法的下法\n");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("不合法的下法\n");Sleep(500); } }
}
else { printf("不合法的下法\n");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("三思而后行\n"); printf("还是你的回合"); Sleep(500); }
else if( x == check_x + 2 y == check_y) check_main2(temp,temp1,turn,turn1,num,if_return,map);
else { printf("不合法的下法\n");Sleep(500); } }
else{ if((x == check_x y == check_y))
{ temp = turn; temp1 = turn1; turn = 'O'; turn1 = 'N'; num--;
printf("三思而后行\n");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("不合法的下法\n");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("\n 重来,请按键.\n");
getch( );
}
return 0;
}
C语言课程设计 国际象棋棋盘
#include "stdio.h"
main()
{
int i,j;
for(i=0;i8;i++)
{
for(j=0;j8;j++)
if((i+j)%2==0)
printf("%c%c",219,219);
else
printf(" ");
printf("\n");
}