#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 return 1; } return 0; } void put_chess(int n) //八皇后摆列方式逐个显示函数 { for(int l=0;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); } 免责声明:文档在线网(文档中国)中所有的文档资料均由文档在线网会员提供。文档在线网会对会员提供的文档资料进行筛选和编辑,但是并不声明或保证其内容的合法性、正确性或可靠性。该文档资料的版权属于提供者所有,有关版权的问题请直接与提供者联系。下载本文