turbo C动态演示八皇后

发表于:2007-07-01来源:作者:点击数: 标签:
这是我数据结构课程设计的一部分,现拿出来与大家交流并希望能有人对其改进: #include #include #include #include #define MAX 8 int board[MAX]; void Drow() { int i; int Driver=VGA,Mode=VGAHI; initgraph(Mode,"d:\\TC3.0\\bgi"); setfillstyle(SOLID


   这是我数据结构课程设计的一部分,现拿出来与大家交流并希望能有人对其改进:

#include
#include
#include
#include
#define MAX 8
int board[MAX];

void Drow()
{
  int i;
  int Driver=VGA,Mode=VGAHI;
      initgraph(&Driver,&Mode,"d:\\TC3.0\\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,"CopyRight1.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;
     for(j=0;j    {
    //  printf("(%d,%d)",j,board[j]);
 DrowCircle(j,board[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) {
    show_result();
   }
   else put_chess(n+1);
  }
     }
}
void main()
{
   Drow();
   put_chess(0);
   return;
// clrscr();
}


原文转自:http://www.ltesting.net