当前位置:首页 > 代码 > 正文

象棋代码(象棋代码架构设计)

admin 发布:2022-12-19 15:54 112


本篇文章给大家谈谈象棋代码,以及象棋代码架构设计对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

中国象棋的源代码

中国象棋源代码blackleft(){ int x,y,n; if(blackcurpos.y0) { blackcurpos.y--; x=position[blacktemppos.x][blacktemppos.y].x; y=position[blacktemppos.x][blacktemppos.y].y; if(board[blacktemppos.x][blacktemppos.y]==0) drawbmp(x,y,boardfile[blacktemppos.x][blacktemppos.y]); else if(!(blacktemppos.x==blackoldpos.xblacktemppos.y==blackoldpos.yblackstate==MOVE)) { n=board[blacktemppos.x][blacktemppos.y]; drawbmp(x,y,chessfile[n]); } if(blacktemppos.x==blackoldpos.xblacktemppos.y==blackoldpos.yblackstate==MOVE) drawselecursor(blackoldpos); drawcursor(blackcurpos); blacktemppos.x=blackcurpos.x; blacktemppos.y=blackcurpos.y; }}blackright(){ int x,y,n; if(blackcurpos.y8) { blackcurpos.y++; x=position[blacktemppos.x][blacktemppos.y].x; y=position[blacktemppos.x][blacktemppos.y].y; if(board[blacktemppos.x][blacktemppos.y]==0) drawbmp(x,y,boardfile[blacktemppos.x][blacktemppos.y]); else if(!(blacktemppos.x==blackoldpos.xblacktemppos.y==blackoldpos.yblackstate==MOVE)) { n=board[blacktemppos.x][blacktemppos.y]; drawbmp(x,y,chessfile[n]); } if(blacktemppos.x==blackoldpos.xblacktemppos.y==blackoldpos.yblackstate==MOVE) drawselecursor(blackoldpos); drawcursor(blackcurpos); blacktemppos.x=blackcurpos.x; blacktemppos.y=blackcurpos.y; }}blackdo(){ int i,j,x,y,n; if(blackstate==SELECTblackcanselect()) { if(board[blackcurpos.x][blackcurpos.y]=BLACKboard[blackcurpos.x][blackcurpos.y]0) { blackstate=MOVE; drawselecursor(blackcurpos); blackoldpos.x=blackcurpos.x; blackoldpos.y=blackcurpos.y; } } else if(blackstate==MOVEblackcanmove()) { x=position[blackoldpos.x][blackoldpos.y].x; y=position[blackoldpos.x][blackoldpos.y].y; drawbmp(x,y,boardfile[blackoldpos.x][blackoldpos.y]); x=position[blackcurpos.x][blackcurpos.y].x; y=position[blackcurpos.x][blackcurpos.y].y; n=board[blackoldpos.x][blackoldpos.y]; drawbmp(x,y,chessfile[n]); if(board[blackcurpos.x][blackcurpos.y]==RED_JIANG) { winner=BLACK; finish=1; return; } board[blackcurpos.x][blackcurpos.y]=n; board[blackoldpos.x][blackoldpos.y]=0; for(i=0;i=2;i++) for(j=3;j=5;j++) if(board[i][j]==BLACK_JIANG) {x=i;y=j;} for(i=x+1,j=y,n=0;i=9;i++) { if(board[i][j]==RED_JIANGn==0) {winner=RED;finish=1;break;} else if(board[i][j]!=0) n++; } turn=RED; redstate=SELECT; drawcursor(redcurpos); drawbmp(30,438,"bmp\\rzq.wfb"); /*转交控制权给红方*/ } }blackundo(){ int x,y,n; if(blackstate==MOVE) { x=position[blackoldpos.x][blackoldpos.y].x; y=position[blackoldpos.x][blackoldpos.y].y; n=board[blackoldpos.x][blackoldpos.y]; drawbmp(x,y,chessfile[n]); blackoldpos.x=blackcurpos.x; blackoldpos.y=blackcurpos.y; drawcursor(blackcurpos); blackstate=SELECT; }}/*----------------------------------------------------*/start(){ drawcursor(blackcurpos); drawbmp(30,438,"bmp\\bzq.wfb"); while(!finish) { key=getkey(); switch(key){ case RED_UP: if(turn==RED) redup(); break; case RED_DOWN: if(turn==RED) reddown(); break; case RED_LEFT: if(turn==RED) redleft(); break; case RED_RIGHT: if(turn==RED) redright(); break; case RED_DO: if(turn==RED) reddo(); break; case RED_UNDO: if(turn==RED) redundo(); break; case BLACK_UP: if(turn==BLACK) blackup(); break; case BLACK_DOWN: if(turn==BLACK) blackdown(); break; case BLACK_LEFT: if(turn==BLACK) blackleft(); break; case BLACK_RIGHT: if(turn==BLACK) blackright(); break; case BLACK_DO: if(turn==BLACK) blackdo(); break; case BLACK_UNDO: if(turn==BLACK) blackundo(); break; case ESCAPE: finish=1;break; } }}main(){ init(); initpos(); initchessmap(); drawbmp(0,0,"bmp\\board.wfb"); initdrawchess(); /*初始化光标位置*/ redcurpos.x=redoldpos.x=redtemppos.x=9; redcurpos.y=redoldpos.y=redtemppos.y=8; blackcurpos.x=blackoldpos.x=blacktemppos.x=0; blackcurpos.y=blackoldpos.y=blacktemppos.y=0;/*开始*/ start(); if(winner==RED) drawbmp(200,200,"bmp\\redwin.wfb"); else if(winner==BLACK) drawbmp(200,200,"bmp\\blackwin.wfb"); else drawbmp(200,200,"bmp\\exit.wfb"); getch(); end();}

急需用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

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");

}

}

用VB语言编写代码 在象棋的的棋盘第一格放一颗麦粒,第二格放两颗麦粒,第三格放四颗麦粒,每?

Private Sub Command1_Click()

s = 1

t = 1

For i = 2 To 64

  t = t + t

  s = s + t

Next i

Print "64个格子全部放完麦子,"

Print "总共为"; s; "粒"

End Sub

国际象棋中 各个旗子的英文代号是什么?~ 怎么表示走的路线

王K,后Q,车R,象B,马N,兵P.国际象棋的棋盘从白棋的左车开始数为a1纵行为1至8,横行为A至H向坐标一样表示各个格子.而哪个棋子走到哪里或者吃子,只须在前面加上棋子的英文缩写.兵可以不加.如Nf3代表马走到f3格.另外O-O代表短易位,O-O-O代表长易位.将军后要加+.

象棋代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于象棋代码架构设计、象棋代码的信息别忘了在本站进行查找喔。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/11402.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载