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

作者&投稿:殷试 (若有异议请与网页底部的电邮联系)
C语言 象棋的代码(主要是走棋子的部分)~

你好!!没有c语言的,只有窗体的象棋,还是网络版的执行文件,你试试看吧


你是想要图形界面吗?如果是那么重点不在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;

}



#include<stdio.h> #include<conio.h> #include<string.h> #include<stdlib.h> #include<windows.h>
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); }
} //其余代码在后续

棋盘如果没有界面,那种有线和框的,就用0放在每个位置,当作一个位置,玩家1如果放下子的话,就将0变成1,玩家2放下棋子,0变成2
复杂的界面,就去找MFC、QT吧

struct stu //定义位置记录结构体
{
int x;
int y;
}weizhi;
int player=1;
int Q[20][20]={0}; //定义数组以记录落子情况

void drawqipan() //绘制棋盘及数据初始化
{
int i,j;
system("cls"); //清除屏幕
for(i=0;i<20;i++)
{
for(j=0;j<20;j++)
{
Q[i][j]=0;
printf("十");
}
printf("\n");
}
weizhi.x=0;weizhi.y=0; //程序数据初始化
gotoxy(0,0);
}

什么时候要?》

急需用c语言写中国象棋的代码,只要红色方布局和走棋
答: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[...

急求一个C语言或C++编写的象棋小游戏的程序,有的请发到我邮箱:na1234567...
答:急求一个C语言或C++编写的象棋小游戏的程序,有的请发到我邮箱:na1234567899@163.com谢了Xiaofaneq | 二级 先弄明白数据的结构:MantisChessDef.h里的东西一定要先看一下, 否则会摸不到头脑的。还有棋盘坐标:象棋棋盘大小9x10,为了便于编程,规定棋盘每条边留有一个元素的边界。这样棋盘大小(包括...

用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...

8*8象棋,5皇后控制全局,C语言编程
答:include <iostream> include <cstdlib> using namespace std ;int iCount = 0 ;void pintf(int qp[8][8] ){ for ( int i = 0 ; i < 8 ; i ++){ for ( int j = 0 ; j < 8 ; j++){ if ( qp[i][j] > 6 )cout<< " 皇 " ;else cout<< " * " ;// cou...

C语言,象棋棋盘代码求分析
答:i循环内部实现具体输出每一行内容,循环最后是输出换行的printf语句 j的8次循环实现在当前行输出8个图形,每个图形是个汉字(显示是白色方块)或者两个空格(与汉字等宽并且显示黑色底色)当前位置输出汉字实心方块(ASCII码是连续的两个219)还是连续两个空格要根据i和j的和是否能被2整除的特点来决定:第1行...

求C语言程序,在中国象棋棋盘上,放置一个马,能够不重复走过棋盘的每一...
答:/ 问题描述:在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...

C语言 马走日不重复遍历中国象棋棋盘上每一个位置点
答:本着乐于助人以及自我锻炼的原则,帮楼主敲了敲代码,还有疑问的话请追问。include <stdio.h> include <memory.h> typedef struct { int x, y;}item;item move[4] = {{-2,1}, {-1,2}, {1,2}, {2,1}};int map[5][9], sx, sy;//判断是否在地图中,防止越界 int checkIn(int...

用C语言编程
答:char a,b,c,d,e;//车,马,炮,兵,卒 int bz = true;for(int i = 1000;i <= 9999 ;++i)//遍历两个4位数 { for(int j = 1000;j <= 9999;++j){ int val = i + j;//进行相加 char arw1[4],arw2[4],arw3[5] = {};//3个数组分别存储各位上的数 itoa(i,arw1,...

...在棋盘上的A点,有一个中国象棋的马,并约定马走的规则,从A点跳至B...
答:include<stdio.h>//棋盘尺寸#define X 4#define Y 8//B点坐标#define BX 0#define BY 8int pos[100];int idx = 0;int drt[4][2]={{2,1},{1,2},{-1,2},{-2,1}};bool expand(int x,int y ) {int i,xn,yn;if (x==BX && y==BY)return true;if (x<0||y<0||x...

编写一个C程序求解在8X8的象棋格子里指定“马”的初始位置,找出马走 ...
答:main(){ int i,j,x,y;for(i=0;i<8;i++){ for(j=0;j<8;j++){ x = i+2;y=j+1; if(x>=0&&x<8&&y>=0&&y<8)printf("%d %d\n",x,y);x = i+1;y=j+2; if(x>=0&&x<8&&y>=0&&y<8)printf("%d %d\n",x,y);x = i+2;y=j-1; if(x>=0&&x<8&&y...