视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
数据结构课程设计(C++)_八皇后动态演示原代码
2025-09-29 00:01:06 责编:小OO
文档
//运行环境TC3.0

#include //调用数学函数库

#include //调用标准输入输出函数库

#include

#include //调用图形函数库

#include

#define MAX 8                               //定义棋盘格数(特别是横轴方向上)

int board[MAX];                             //纵轴方向格数

void Drow()                                //画棋盘

{

  int i;

  int Driver=VGA,Mode=VGAHI;                 //初始化显示器

      initgraph(&Driver,&Mode,"d:\\\c\\\\bgi");

      setfillstyle(SOLID_FILL,BLUE);         //棋盘底色模式

      bar(5,15,600,500);                     //棋盘外框(二维)   

      setcolor(YELLOW);                      //棋盘边框颜色

for(i=0;i<=9;i++)

      {

     line(10,20+50*i,460,20+50*i);       //画行     

      }

for(i=0;i<=9;i++)

      {

     line(10+50*i,20,10+50*i,470);        //画列 

      }

      line(460,20,560,20);

      line(10,470,560,470);

      line(560,470,560,20);

      setcolor(RED);

      outtextxy(465,30,"WuShangjie");         //版权注释

      outtextxy(465,45,"Eight Queue");

      outtextxy(465,60,"CopyRight2.0");

      outtextxy(415,440,"Start");             //屏幕输出文本 坐标标记

       outtextxy(385,440,"0");

       outtextxy(335,440,"1");

       outtextxy(285,440,"2");

       outtextxy(235,440,"3");

       outtextxy(185,440,"4");

       outtextxy(135,440,"5");

       outtextxy(85,440,"6");

       outtextxy(35,440,"7");

     outtextxy(415,455,"Point");

       outtextxy(435,390,"0");

       outtextxy(435,340,"1");

       outtextxy(435,290,"2");

       outtextxy(435,240,"3");

       outtextxy(435,190,"4");

       outtextxy(435,140,"5");

       outtextxy(435,90,"6");

       outtextxy(435,40,"7");

}

void DrowCircle(int i,int j)                            //话棋子

{

  char text[80];

  setfillstyle(SOLID_FILL,YELLOW);

  setcolor(YELLOW);

  circle(385-50*i,395-50*j,15);

  floodfill(385-50*i,395-50*j,YELLOW);                   //圆内颜色填充

  setcolor(RED);

  sprintf(text,"%d,%d",i,j);                             //棋子上坐标标记

  outtextxy(385-50*i-14,395-50*j,text);

}

void GiveDrowIn(int i,int j)                            //过去显示棋子清除

{

  setfillstyle(SOLID_FILL,BLUE);                        //将填充颜色设置与底色相同

  setcolor(BLUE);                                       //将画笔颜色设置与底色相同

  circle(385-50*i,395-50*j,15);

  floodfill(385-50*i,395-50*j,BLUE);                   //一定区域内填充

  outtextxy(385-50*i-14,395-50*j,"                   ");

}

void show_result()                                //调度相关算法求出所有结果

{

     int j=0;

while(j       {

    DrowCircle(j,board[j]);

    getch();

    j++;

       }

    getch();

for(j=0;j       {

    GiveDrowIn(j,board[j]);                           //释放上回显示棋子区域

       }

    getch();

}

int check_cross(int n)                                      //判断棋子是否冲突函数

{

    int k;

for(k=0;k       if(board[k]==board[n]||(n-k)==abs(board[k]-board[n]))     //是否同行,是否同对角线

       return 1;

       }

       return 0;

}

void put_chess(int n)                                        //八皇后摆列方式逐个显示函数

{

for(int l=0;l         board[n]=l;

     if(!check_cross(n)){

      if(n==MAX-1) {

             getch();

             show_result();

            }

      else put_chess(n+1);

     }

     }

}

void main()                                             //主函数

{

  Drow();                                               

  put_chess(0);

//to the end of the program

  getch();

  exit(1);

}

免责声明:文档在线网(文档中国)中所有的文档资料均由文档在线网会员提供。文档在线网会对会员提供的文档资料进行筛选和编辑,但是并不声明或保证其内容的合法性、正确性或可靠性。该文档资料的版权属于提供者所有,有关版权的问题请直接与提供者联系。下载本文

显示全文
专题