自製c語言象棋,C語言中國象棋

本文目錄一覽:

用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”);

}

原創文章,作者:NZMR,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/148692.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
NZMR的頭像NZMR
上一篇 2024-11-03 15:17
下一篇 2024-11-03 15:17

相關推薦

  • AES加密解密演算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密演算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES演算法,並對實現過程進…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演著非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29
  • OpenJudge答案1.6的C語言實現

    本文將從多個方面詳細闡述OpenJudge答案1.6在C語言中的實現方法,幫助初學者更好地學習和理解。 一、需求概述 OpenJudge答案1.6的要求是,輸入兩個整數a和b,輸出…

    編程 2025-04-29
  • Python按位運算符和C語言

    本文將從多個方面詳細闡述Python按位運算符和C語言的相關內容,並給出相應的代碼示例。 一、概述 Python是一種動態的、面向對象的編程語言,其按位運算符是用於按位操作的運算符…

    編程 2025-04-29
  • Python語言由荷蘭人為中心的全能編程開發工程師

    Python語言是一種高級語言,很多編程開發工程師都喜歡使用Python語言進行開發。Python語言的創始人是荷蘭人Guido van Rossum,他在1989年聖誕節期間開始…

    編程 2025-04-28
  • Python語言設計基礎第2版PDF

    Python語言設計基礎第2版PDF是一本介紹Python編程語言的經典教材。本篇文章將從多個方面對該教材進行詳細的闡述和介紹。 一、基礎知識 本教材中介紹了Python編程語言的…

    編程 2025-04-28
  • Python語言實現人名最多數統計

    本文將從幾個方面詳細介紹Python語言實現人名最多數統計的方法和應用。 一、Python實現人名最多數統計的基礎 1、首先,我們需要了解Python語言的一些基礎知識,如列表、字…

    編程 2025-04-28
  • Python作為中心語言,在編程中取代C語言的優勢和挑戰

    Python一直以其簡單易懂的語法和高效的編碼環境而著名。然而,它最近的發展趨勢表明Python的使用範圍已經從腳本語言擴展到了從Web應用到機器學習等廣泛的開發領域。與此同時,C…

    編程 2025-04-28
  • Python基礎語言

    Python作為一種高級編程語言擁有簡潔優雅的語法。在本文中,我們將從多個方面探究Python基礎語言的特點以及使用技巧。 一、數據類型 Python基礎數據類型包括整數、浮點數、…

    編程 2025-04-28

發表回復

登錄後才能評論