自制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/n/148692.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
NZMRNZMR
上一篇 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

发表回复

登录后才能评论