INFO INSTITUTE OF ENGINEERING   WELCOMES  U ALL
EIGHT QUEENS PROBLEM
EIGHT-QUEENS PROBLEM Project Report submitted by V.J.Aiswaryadevi  (07BIT03), S.Dhivya    (07BIT15), M.Kumuthanandhini (07BIT23)
OBJECTIVE In partial fulfillment of the requirements for the award of degree of Bachelor of Engineering in Information Technology in Info Institute of Engineering
Under the guidance of  Lecturers,Department of Information Technology Department of Information Technology Info Institute of Engineering  Coimbatore -641101 BATCH 2007-2011
ACKNOWLEDGEMENT First and foremost we acknowledge the abundant grace and presence of our LORD GOD ALMIGHTY throughout the  project work and its successful completion. We thank our beloved founder late Shri . K.K.Veluchamy ,B.E .for their unceasing prayers for the student community
ACKNOWLEDGEMENT And we thank all our beloved and respectful Dharbari charitable trustees for their grate source of inspiration during the project ,encouragement in the project. We wish to thank our Information Technology (IT) department lecturers for their valuable guidance.We would like to thank all other staffs for their co-operation with us during our project.
ACKNOWLEDGEMENT Last but not least we cannot fail to acknowledge the support and encouragement provided by our parents,friends and the staffs of Department of Information Technology.
SYNOPSIS The project eight queens is a puzzle game, that deals with the simple alignment or placing of queens without interfacing each other diagonally,horizontally or vertically.It is also called as one of the Chess board games.
INDEX 1 INTRODUCTION Purpose Intended Audience & Reading Suggestions Project Scope Platform Overview
INDEX 2  PROJECT OVERVIEW Description of 8-Queens algorithm Operating environment Source code 22-70
INDEX 3 MODULE DESCRIPTION Block diagram Screen shots
CONCLUSION  Broad conclusion  Future Scope and Enhancement
INTRODUCTION 1.1 Purpose Eight queens  is the chess board puzzle game which gives enough entertainment. Besides being an amusing puzzle this problem is interesting because kids love it and it's a great teaching tool in the upper grades of Elementary School. It also provides great programming exercises.
1.2   Intended Audience and reading suggestions 1.2.1Intended users –  All players and developers 1.2.2 Description –  The rest of this document contains the technical study of what the project is actually about.It is a general view into the planned working of the system through sequence diagram and functional and non-functional requirements of the system.  1.2.3 Developer –  is aware of the system to be developed so  they could start their reading from system features and follow on.
1.3 Project Scope This project is to solve the queens puzzle with different solutions.Here user and system interaction is established. The dynamic reports are available for the players.If there is no solution,the project will display the message “there is no solution”.In chess board, a queen can move as far as she pleases, horizontally, vertically, or diagonally. A chess board has 8 rows and 8 columns. The standard 8 by 8 Queen's problem asks how to place 8 queens on an ordinary chess board so that none of them can hit any other in one move is the basic reveal that we get from this project.
1.3 Project Scope An obvious modification of the 8 by 8 problem is to consider an  N  by  N  "chess board" and ask if one can place  N  queens on such a board. It's pretty easy to see that this is impossible if  N  is 2 or 3, and it's reasonably straightforward to find solutions when  N  is 4, 5, 6, or 7.
1.4 Platform Overview  1.4.1 Model: The platform used here is Windows xp.This project is done using the C++ software in its Integrated Development environment(IDE).This project is platform dependent. It is developed using more graph concepts like combinatorial concepts.Simple concepts are used for developing this
2-PROJECT OVERVIEW 2.1 Description of Eight Queens  Product Features Using the Control Panel   Let's run through the rows of the Control Panel:  Row 1.   Naturally, the  Quit  button lets you quit the program. You can also exit by clicking again on the applet, by typing 'x', 'X', 'q', or 'Q' in the control window, or by quitting your browser. You can dismiss a single solution or the drawing window by typing 'x', 'X', 'q', or 'Q' in the relevant window.
Row 2.   The  red  textfield let's you change the value of  N  , the dimension of the chess board. You can decrease or increase  N  by clicking on the &quot;<&quot; Size&quot;>&quot; button from 4-8, respectively.  The  Display Menu  let's you determine the degree of animation on the drawing board. There are four levels, ordered by decreasing animation and increasing speed:  Place Queen  shows queens being moved, and has a ghost queen move from any queen that can hit the recently moved queen in the rightmost column.
2.3 Operating Environment Hardware requirements Processor : Intel Pentium processors,    AMD sempron etc., Memory :  512MB – 1GB RAM Hard disk  :  60-240GB hard disk(Even    more than this) Monitor :  Any compatible Keyboard :  Any compatible Software requirements Operating System :  Windows XP/Vista Platform  :  C++
Source Code Code : /* modified final*/ #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> #include<math.h> #include<process.h>
//Functions used void about_prog(); void gotorc ( int, int ) ; void mainmenu ( ) ; void drawbox ( int, int, int, int, int, int ) ; void writechar ( char, int, int, int, int ) ; void writestring ( char*, int, int, int, int, int = 0 ) ; void clrwin ( int=0, int=0, int=25, int=80, int=7, int=0 ) ; void rules ( ) ; void about ( ) ; void quit ( ) ; void back ( ) ;
void initmouse(void); void yesmouse(void); void nomouse(void); void mouse(void); void limmouse(int,int,int,int); void background(); void first_screen(); void loadprog(); void acceptsize(); void error_mesg();
int possible_results(); int  search_rowcol(); void doneby(); void fill_poly(int,int,int,int,int,int); void draw_chess_board(); void erase(); void drawcircle(); void acceptbymouse(); void acceptbykeyboard(); int placequeen(int,int,int); void diagonal_1_check(int,int,int,int); void diagonal_2_check(int,int,int,int); void column(int,int,int,int); void result();
// Global Variables int exit_p; int chess[50][50]; int placed_row,size,row,col,x,y,radiusx,radiusy,ro,co,text_x=1; int iRow,iCol,iStatus; long int total_no_of_nodes,temp; long int count_exceed; int  x_center = 320, y_center = 200, rad = 100,p[100],q[100]; long int count_num=0; union REGS i,o; char far *scr=(char far *) 0xB8000000L ; //screen address char ch, *menu[]= { &quot;  *** MENU ***  &quot;, &quot;  ^Instructions  &quot;, &quot;  ^Enter Size Of ChessBoard  &quot;, &quot;  ^Use Mouse To place Queen  &quot;, &quot;  ^USE Keyboard To Place Queen &quot;, &quot;  ^Possible Solutions  &quot;, &quot;  ^Exit  &quot; };
void about_prog() { clrwin ( 0, 0, 25, 80, 0, 3 ) ; drawbox ( 2, 2, 22, 75, 0, 8 ) ; writestring ( &quot;About Program&quot;, 30, 2, 14, 0 ) ; writestring ( &quot;* A Classic Combinatorial Problem Is  To Place N-Queens on N by N&quot;, 3, 4,  11, 0) ; writestring ( &quot;ChessBoard So That No Two  'Attack',that is,so that no two of them  &quot;, 5, 6, 11, 0 ) ;
writestring ( &quot;are on the same row,column or diagonal.&quot;, 5, 8, 11, 0 ) ; writestring ( &quot;* This Problem Is Solved By 'BackTracking',BackTracking  is  a&quot;, 3,10,11, 0 ) ; writestring ( &quot;Algorithmic Strategy.&quot;, 5, 12, 15, 0 ) ; writestring ( &quot;* In This Program You Have To Choose a Position On ChessBoard For&quot;, 3, 14, 12, 0 ) ; writestring ( &quot;a Queen Then The BackTracking Algorithm Places All N-1 Queens&quot;, 5, 16, 12, 0 ) ; writestring ( &quot;On Right Place Satisfing Above Conditions.&quot;, 5, 18,12,0 ) ; writestring ( &quot;* Number Of All Possible Solutions For Placed Positions Can Be Viewed.&quot;, 3, 18, 13, 0 ) ; writestring ( &quot;Press Any Key To Continue&quot;, 50, 21, 13, 0 ) ; getch(); }
void error_mesg() { int gd=DETECT,gm; initgraph(&gd,&gm,&quot;..\bgi&quot;); cleardevice(); background(); fill_poly(100,200,550,250,12,10); settextstyle(8, HORIZ_DIR, 3); setcolor(15); }
void loadprog() { int i; _setcursortype(_NOCURSOR); drawbox ( 10, 30, 13, 50, 2, 0 ) ; writestring ( &quot;Loading.... &quot;, 32, 11, 0, 2, 1 ) ; gotoxy(1,25); textcolor(CYAN); for(i=0;i<79;i++) {   cprintf(&quot;°&quot;);   delay(20); } }
void acceptsize() {   int i,j;   _setcursortype(_NOCURSOR);   clrwin ( 0, 0, 25, 80, 0, 1 ) ;   do   {   drawbox ( 10, 20, 14, 65, 2, 0 ) ;   writestring ( &quot;ENTER THE SIZE OF CHESSBOARD (4 TO 25): &quot;, 22, 12,0, 2, 1 ) ;   _setcursortype(_NORMALCURSOR);   gotorc ( 12,61) ;   scanf(&quot;%d&quot;,&size);   _setcursortype(_NOCURSOR);   }while(size<4 || size>26);
total_no_of_nodes=0;   for(j=0;j<size;j++)   { temp=1; for(i=0;i<=j;i++) { temp=temp*(size-i); } total_no_of_nodes=total_no_of_nodes+temp;   }   //total_no_of_nodes=temp;   for(i=0;i<size;i++)   { for(j=0;j<size;j++) { chess[i][j]=-1; }   }   radiusy=((479/size))/2-3;   radiusx=((479/size))/2-3; }
int possible_results() { int gd=DETECT,gm,i,j,ex; char buff[5]; initgraph(&gd,&gm,&quot;..\bgi&quot;); draw_chess_board(); setcolor(10); settextstyle(1,0,3); outtextxy(500,100,&quot;Solution&quot;); outtextxy(500,120,&quot;Number&quot;); sprintf(buff,&quot;%d&quot;,count_num+1); outtextxy(500,140,buff);
x=y=((getmaxy()/size)/2);   for(i=0;i<size;i++)   {   x=((getmaxy()/size)/2); for(j=0;j<size;j++) {   if(chess[i][j]==(i+50))   { setcolor(6); setfillstyle(9,6); fillellipse(x,y,radiusx,radiusy);   }   x=x+((getmaxy()/size)); } y=y+((getmaxy()/size)); }
ex=getch(); if(ex==0) ex=getch(); if(ex==27) { closegraph(); return 1; } closegraph(); return 0; }
void cal_positions(int *a,int index,int row,int ptr) { int i,j,b[50],k,placed,l,m,remove; if(exit_p==0) { if(index >= 1) { i=0; j=1; k=0; for(i=1;i<=size;i++) {   for(j=0;j<ptr;j++)   {   if(a[j]==i) break;   }
if(j==ptr) b[k++]=i; } i=j=0; while(i<index && exit_p==0) {   remove=0; if(chess[row][b[i]-1]==-1&& exit_p==0) { chess[row][b[i]-1]=(row+50); diagonal_1_check(row,b[i]-1,row,- 1); diagonal_2_check(row,b[i]-1,row,- 1); column(row,b[i]-1,row,-1); remove=1; a[ptr]=b[i]; cal_positions(a,index-   1,row+1,ptr+1); }
if(remove==1 && exit_p==0) { chess[row][b[i]-1]=-1; diagonal_1_check(row,b[i]-1,- 1,row); diagonal_2_check(row,b[i]-1,- 1,row); column(row,b[i]-1,-1,row); } i++; } } else { exit_p=possible_results(); count_num++; } } }
void  instructions( ) // RULES { clrwin ( 0, 0, 25, 80, 0, 3 ) ; drawbox ( 2, 2, 21, 75, 0, 8 ) ; writestring ( &quot;INSTRUCTIONS&quot;, 30, 2, 12, 0 ) ; writestring ( &quot;YOU CAN USE KEYBOARD OR MOUSE TO PLACE A  QUEEN&quot;, 5, 4,11, 0) ; writestring ( &quot;* USING KEYBOARD&quot;, 5, 6, 4, 0 ) ; writestring ( &quot; - USE ARROW KEYS TO GO UP,DOWN,LEFT,RIGHT.&quot;, 10, 8,  11,0 ) ; writestring ( &quot; - THEN PRESS ENTER TO PLACE A QUEEN&quot;, 10,10,11, 0 ) ; writestring ( &quot;~* USING MOUSE &quot;, 5, 12, 4, 0 ) ; writestring ( &quot;- FIRST LEFTCLICK ON BUTTON 'PLACED' WHICH IS AT  RIGHTTOP.&quot;, 10, 14, 11, 0 ) ; writestring ( &quot;- THEN SELECT A PLACE ON CHESSBOARD BY  RIGHTCLICK. &quot;, 10,16, 11, 0 ) ; writestring ( &quot;* THEN WAIT FOR FEW MINUTES&quot;, 5, 18, 13, 0 ) ; writestring ( &quot;Press Any Key To Continue&quot;, 50, 20, 13, 0 ) ; getch(); }
void writestring(char*str,int row,int col,int fore, int back, int del ) { //WRITES A STRING TO THE SCREN int x = 30 * del ;  // DEL = 1 IF THERE SHOULD BE A DELAY IN DISPLAY // 0 OTHER WISE.  IT IS SET TO ZERO BY DEFAULT while ( *str ) { // THE NEXT CHAR WILL BE DISPLAYED IN ATTRIBUTED MANNER if ( *str == '^' )  // HOT KEYS { str++ ; writechar (*str++, row++, col, 1, back ) ; delay ( x ) ; nosound ( ) ; delay ( x ) ; }
else if ( *str == 126 )  // HOT KEYS { str++; writechar(*str++, row++, col, 10, back ); delay ( x ) ; nosound ( ) ; delay ( x ) ; } else { writechar (*str++, row++, col, fore, back ) ; delay ( x ) ; nosound ( ) ; delay ( x ) ; } } nosound ( ) ; return ; }
void clrwin(int sr,int sc,int er,int ec,int fore, int back) { // CLEARS THE WINDOW WITH THE GIVEN  //FOREGROUND AND BACKGROUND COLOR i.h.ah=6; i.h.al=0; i.h.ch=sr; i.h.cl=sc; i.h.dh=er; i.h.dl=ec; i.h.bh=back*16+fore; int86(0x10,&i,&i); //clears the screen gotorc ( 0, 0 ) ; //moves the cursor to the appropriate position }
void gotorc ( int r, int c ) { // MOVES THE CURSOR TO THE //APPROPRIATE LOCATION REGS i, o ; i.h.ah = 2 ; i.h.bh = 0 ; i.h.dh = r ; i.h.dl = c ; int86 ( 16, &i, &o ) ; }
void drawbox ( int starty, int startx, int endy, int endx, int color, int shad ) { // FUNCTION TO DRAW THE BOX // JUST STEP THRU THE FUNCTION USING F7 KEY int i, j ; if ( starty > endy || startx > endx || color > 7 ) return ; for ( i = startx ; i < endx ; i ++ ) { for ( j = starty ; j < endy ; j ++ ) writechar ( ' ', i, j, 0, color ) ; writechar ( 219, i + 1, endy, shad, 0 ) ; } for ( i = endy ; i >= starty + 1 ; i -- ) { writechar ( 219, endx, i, shad, 0 ) ; writechar ( 219, endx + 1, i, shad, 0 ) ; } }
void writechar(char ch,int row,int col,int fore, int back) { * ( scr + col * 160 + row * 2 ) = ch ; * ( scr + col * 160 + row * 2 + 1 ) = back * 16 + fore ; return ; } void doneby() { int i,j,z,c; int gd=DETECT,gm; initgraph(&gd,&gm,&quot;..\bgi&quot;); x_center = 320, y_center = 200; rad=100; setcolor(13); line(40,70,590,70); setcolor(2); rectangle(50,340,590,420); setcolor(10);
settextstyle(5,0,5); outtextxy(55,345,“IT&quot;); settextstyle(4,0,3); for(i=1;i<=640;i++) { setcolor(9); line(i,20,i,20); line(i,30,i,30); delay(1); } for(j=10;j<=460;j++) { setcolor(9); line(610,j,610,j); line(620,j,620,j); delay(1); } for( z=640;z>=1;z--) { line(z,435,z,435); line(z,445,z,445); delay(1); } for( c=460;c>=10;c--) { setcolor(9); line(20,c,20,c); line(30,c,30,c); delay(1); }
for ( i = 0; i < 10; i++ ) {   p[i] =  x_center + rad *  cos(36*i*3.14159/180);   q[i] =  y_center + rad *  sin(36*i*3.14159/180); } for ( i = 0; i < 10; i++ ) { for ( j = 0; j < 10; j++ ) { setcolor(14); line(p[i],q[i],p[j],q[j]); delay(25); } } delay(500); closegraph(); error_mesg(); outtextxy(250,210, &quot;Thank You&quot;); gotoxy(50,24); printf( &quot;Press Any Key To Exit&quot;); getch(); }
void fill_poly(int x1,int y1,int x2,int y2,int color,int style) { int poly[8],i; poly[0] = x1; poly[1] = y1; poly[2] = x2; poly[3] = y1; poly[4] = x2; poly[5] = y2; poly[6] = x1; poly[7] = y2; setfillstyle(style,color); setcolor(color); fillpoly(4, poly); }
void background() { int gd=DETECT,gm; initgraph(&gd,&gm,&quot;..\bgi&quot;); fill_poly(0,20,getmaxx(),40,11,11); fill_poly(getmaxx()-40,0,getmaxx()-20,getmaxy(),11,11); fill_poly(0,getmaxy()-40,getmaxx(),getmaxy()-20,11,11); fill_poly(20,0,40,getmaxy(),11,11); } void first_screen() { int i,j,k; fill_poly(125,50,500,100,12,10); settextstyle(10, HORIZ_DIR, 3); setcolor(10);
outtextxy(135,50, &quot;N-Queen's Problem&quot;); fill_poly(125,300,500,350,12,10); settextstyle(7, HORIZ_DIR, 3); setcolor(11); outtextxy(135,300, &quot;N-Queen's Problem&quot;); fill_poly(50,50,100,350,12,10); settextstyle(8, 1, 3); setcolor(12); outtextxy(50,55, &quot;N-Queen's Problem&quot;); fill_poly(525,50,575,350,12,10); settextstyle(5, 1, 3); setcolor(13); outtextxy(525,50, &quot;N-Queen's Problem&quot;); gotoxy(50,25); printf(&quot;Press any key to continue&quot;); for ( i = 0; i < 10; i++ ) { p[i] =  x_center + rad *  cos(36*i*3.14159/180); q[i] =  y_center + rad *  sin(36*i*3.14159/180); } for ( i = 0; i < 10; i++ ) { for ( j = 0; j < 10; j++ ) { setcolor(14); line(p[i],q[i],p[j],q[j]); delay(50); } } getch(); }
void initmouse(void) { iRow = 0,iCol = 0,iStatus = 0; asm{ mov ax,0; int 0x33; } } void yesmouse(void) { asm{   mov ax,1;   int 0x33; } } void nomouse(void) { asm{   mov ax,2;   int 0x33; } }
void mouse(void) {   asm{   mov ax,3;   int 0x33;   mov iRow,dx;   mov iCol,cx;   mov iStatus,bx;   } } void limmouse(int iMinX,int iMinY,int iMaxX,int iMaxY) {   yesmouse();   asm{   mov ax,7   mov cx,iMinX   mov dx,iMaxX   int 0x33   }   asm{   mov ax,8   mov cx,iMinY   mov dx,iMaxY   int 0x33   } }
void draw_chess_board() {   int color1,color2,poly[8],i,j;   x=0;y=0;   color1=1;   color2=0;   for(i=0;i<size;i++)   { color1=color2; for(j=0;j<size;j++) {   if(color1==1)   color1=0;   else if(color1==0) color1=1;
setcolor(2);   rectangle(x,y,x+(getmaxy()/size),y+(getmaxy()/size));   poly[0] = x;   poly[1] = y;   poly[4] = x+(getmaxy()/size);   poly[5] = y+(getmaxy()/size);   poly[2] = x+(getmaxy()/size);   poly[3] = y;   poly[6] = x;   poly[7] = y+(getmaxy()/size);   setcolor(2);   if(color1!=0)   {   setfillstyle(1,color1);   fillpoly(4,poly);   x=x+getmaxy()/size;   }   else   { rectangle(x,y,x+getmaxy()/size,getmaxy()/size); x=x+getmaxy()/size;   } } if(color2==1)   color2=0; else if(color2==0) color2=1; x=0; y=y+getmaxy()/size;   } }
void result() {   int gd=DETECT,gm,count,i,j;   initgraph(&gd,&gm,&quot;..\bgi&quot;);   draw_chess_board();   settextstyle(3,0,4);   setcolor(5);   outtextxy(500,5,&quot;Solution&quot;);   outtextxy(500,50,&quot;Found&quot;);   setcolor(2);   rectangle(495,150,getmaxx(),479);   setcolor(15);   settextstyle(1,0,1);   outtextxy(500,200,&quot;This Queen Is&quot;);   outtextxy(500,220,&quot;Placed By User&quot;);   setcolor(4);   setfillstyle(10,4);   fillellipse(550,180,20,20);
setcolor(15);   outtextxy(500,300,&quot;These Queens&quot;);   outtextxy(500,320,&quot;Are Placed&quot;);   outtextxy(500,340,&quot;According to&quot;);   outtextxy(500,360,&quot;Queen Placed&quot;);   outtextxy(500,380,&quot;By User&quot;);   setcolor(6);   setfillstyle(9, 6);   fillellipse(550,280,20,20);   x=y=((getmaxy()/size)/2);   for(i=0;i<size;i++)   {   x=((getmaxy()/size)/2); for(j=0;j<size;j++) {   if(chess[i][j]==(i+50))   {   if(i==placed_row)   { setcolor(4); setfillstyle(10, 4);   }   else   { setcolor(6); setfillstyle(9, 6);   }   fillellipse(x,y,radiusx,radiusy);   }   x=x+((getmaxy()/size)); } y=y+((getmaxy()/size));   }   getch();   closegraph(); }
void erase() {   int pixel;   pixel=getpixel(x+radiusx+1,y);   setcolor(pixel);   setfillstyle(1,pixel);   fillellipse(x,y,radiusx,radiusy); } void drawcircle() {   setcolor(4);   setfillstyle(10,4);   fillellipse(x,y,radiusx,radiusy); } int search_rowcol() {   y=0;   for(ro=0;ro<size;ro++)   { x=0; for(co=0;co<size;co++) { if(x<iCol && iCol<(x+479/size) && y<iRow && iRow<(y+479/size)) { return 1; } x=x+(479/size);   }
y=y+(479/size);   }   return 0; } void acceptbymouse() { int prevx,prevy,break_flag,pressed,valid; int gd=DETECT,gm; initgraph(&gd,&gm,&quot;..\bgi&quot;); draw_chess_board(); initmouse(); limmouse(0,0,getmaxx()-50,getmaxy()); yesmouse(); fill_poly(495,15,605,45,11,1); fill_poly(500,20,600,40,5,1); setcolor(14); settextstyle(5,0,3); outtextxy(525,12,&quot;Place&quot;);   setcolor(15);   settextstyle(1,0,3);   outtextxy(500,100,&quot;To Place&quot;);   outtextxy(500,120,&quot;A  Queen&quot;);   outtextxy(500,140,&quot;LeftClick&quot;);   outtextxy(500,160,&quot;On Button&quot;);   outtextxy(500,180,&quot;'Placed' &quot;);
while(1) { mouse(); if(iStatus==1 && 500<=iCol &&iCol<=605 &&  15<=iRow &&iRow<=40) { nomouse(); fill_poly(495,15,605,50,0,1); break; }   }   prevx=0;prevy=0;   fill_poly(500,0,getmaxx(),getmaxy(),0,1);   setcolor(15);   settextstyle(1,0,3);   outtextxy(500,100,&quot;To Place&quot;);   outtextxy(500,120,&quot;A  Queen&quot;);   outtextxy(500,140,&quot;RightClick&quot;);   outtextxy(500,160,&quot;On Proper&quot;);   outtextxy(500,180,&quot;Place&quot;);
while(1)   { yesmouse(); mouse(); if(iStatus==2) {   break; } valid=search_rowcol(); if(valid==1) {   if(prevx<iCol && iCol<(prevx+479/size) && prevy<iRow && iRow<(prevy+479/size))   { nomouse(); setcolor(15); prevx=x;prevy=y; rectangle(x,y,x+(479/size),y+(479/size));   } else   { setcolor(2); rectangle(prevx,prevy,prevx+(479/size),prevy+(479/size)); nomouse(); setcolor(15); prevx=x;prevy=y; rectangle(x,y,x+(479/size),y+(479/size));   }   yesmouse(); }   }   nomouse();   x=x+(479/size)/2; y=y+(479/size)/2;   drawcircle();   placed_row=ro;   placequeen(ro,co,0);   delay(1000);   closegraph(); }
void acceptbykeyboard() {   int gd=DETECT,gm,c,i,j;   initgraph(&gd,&gm,&quot;..\bgi&quot;);   draw_chess_board();   x=(getmaxy()/size)/2;   y=(getmaxy()/size)/2;   i=0;j=0;   drawcircle();   do   {   c=getch();   if(c==0)   c=getch();   if(c==72 && y-(getmaxy()/size)>0)   {   erase();   y=y-(getmaxy()/size);   drawcircle();   i--;   }   else if(c==80 && y+(getmaxy()/size)<479) {   erase();   y=y+(getmaxy()/size);   drawcircle();   i++; } else if(c==75&& x-(getmaxy()/size)>0) {   erase();   x=x-(getmaxy()/size);   drawcircle();   j--; } else if(c==77 &&x+(getmaxy()/size)<479) {   erase();   x=x+(getmaxy()/size);   drawcircle();   j++; } if(c==13) {   drawcircle();   placed_row=i;   placequeen(i,j,0);   c=27; }   }while(c!=27);   closegraph(); }
  if(j1==size)   {   if(i-1!=placed_row)   {   i--;   row--;   }   else   {   i=i-2;   row=row-2;   }   for(j=0;j<size;j++)   {   if(chess[i][j]==(i+50))   break;   }   chess[i][j]=-1;   diagonal_1_check(i,j,-1,i);   diagonal_2_check(i,j,-1,i);   column(i,j,-1,i);   textcolor(0);   textbackground(0);   gotoxy(--text_x,25);   cprintf(&quot; &quot;);   break_up=placequeen(row,j+1,0); }   }   return 0; } int placequeen(int i,int j,int break_up) {   int j1;   if(break_up==0)   {   count_exceed++;   if(count_exceed>total_no_of_nodes)   { error_mesg(); outtextxy(110,210, &quot;Sorry,Solution Is Not Possible !!&quot;); gotoxy(50,24); printf( &quot;Press Any Key To Continue&quot;); getch(); closegraph(); return 1;   }   for(j1=j;j1<size;j1++)   {   if(chess[i][j1]==-1)   {   textcolor(3);   gotoxy(text_x++,25);   cprintf(&quot;°&quot;);   chess[i][j1]=(i+50);   diagonal_1_check(i,j1,i,-1);   diagonal_2_check(i,j1,i,-1);   column(i,j1,i,-1);   break;   }   }
void  diagonal_1_check(int i1,int j1,int val,int check) {   int i2,j2;   i2=i1;   j2=j1;   i2--;j2--;   while(i2>=0&&j2>=0)   {   if(check==chess[i2][j2])   chess[i2][j2]=val;   i2--;j2--;   }   i2=i1;   j2=j1;   i2++;j2++;   while(i2<size&&j2<size)   {   if(check==chess[i2][j2])   chess[i2][j2]=val;   i2++;j2++;   } }
void  diagonal_2_check(int i1,int j1,int val,int check) { int i2,i3,j2;   i2=i1;   j2=j1;   i2--;j2++;   while(i2>=0&&j2<size)   {   if(check==chess[i2][j2])   chess[i2][j2]=val;   i2--;j2++;   }   i2=i1;   j2=j1;   i2++;j2--;   while(i2<size&&j2>=0)   {   if(check==chess[i2][j2])   chess[i2][j2]=val;   i2++;j2--;   } }
void column(int i1,int j1,int val,int check) {   int j2;   for(j2=0;j2<size;j2++)   {   if(chess[i1][j2]==check)   { chess[i1][j2]=val;   }   }   for(j2=0;j2<size;j2++)   {   if(chess[j2][j1]==check)   { chess[j2][j1]=val;   }   } }
if(status==0) status=getch(); switch(status) { case 72:if(choice==1) choice=6; else choice--; break; case 80:if(choice==6) choice=1; else choice++; break; case 13:   if(choice==1) instructions();   else   if(choice==2)   { acceptsize();   } void main() { int i,j,choice,status,breakup,b[50]; background(); // first_screen(); closegraph(); loadprog(); about_prog(); size=-1; choice=1; do { clrwin ( 0, 0, 25, 80, 0, 1 ) ; drawbox ( 5, 20, 20, 55, 4, 0 ) ; _setcursortype(_NOCURSOR); for ( int i = 0 ; i <= 6 ; i ++ ) {   if ( choice == i )   writestring ( menu[i], 20, 7 + 2 * i, 0, 10 ) ;   else   writestring ( menu[i], 20, 7 + 2 * i, 10, 4 ) ; } status=getch();
else if(choice==6)   {   doneby();   exit(0);   else if(size==-1)   { error_mesg(); outtextxy(110,210, &quot;First Enter Size Of ChessBoard&quot;); gotoxy(50,24); printf( &quot;Press Any Key To Continue&quot;); getch(); closegraph();   }   else   if(choice==5)   { for(i=0;i<size;i++) { b[i]=0; } exit_p=0; cal_positions(b,size,0,0);   } if(status==0) status=getch(); switch(status) { case 72:if(choice==1) choice=6; else choice--; break; case 80:if(choice==6) choice=1; else choice++; break; case 13:   if(choice==1) instructions();   else   if(choice==2)   { acceptsize();   }
else if(choice==4||choice==3)   { if(choice==4)   acceptbykeyboard(); else if(choice==3)   acceptbymouse();   gotoxy(30,13);   textcolor(3);   textbackground(1);   printf(&quot;Placing Please Wait........&quot;);   row=0;   count_exceed=0;   breakup=0; while(row!=size &&breakup==0)   {   if(row==placed_row)   row++;   if(row==size)   break;   breakup=placequeen(row,0,0);   row++;   }   if(breakup==0)   {   for(i=text_x;i<79;i++)   {   textcolor(2);   cprintf(&quot;°&quot;);   delay(30);   }   result();   }
}   break; }   }while(1);   }
END OF THE SOURCE  CODE
FLOW CHART START SET BACKGROUND() LINK THE BGI GRAPHIC FILE WITH USER SCREEN A
READ SIZE OF CHESS BOARD A IF SIZE IS BETWEEN 4-8 PLACE-QUEEN () B YES EXIT(0) NO
DISPLAY INSTRUCTION TO PLACE B DISPLAY THE RESULT IF EXIT CLOSE GRAPH() YES C
C STOP EXIT(0)
SCREEN SHOT
CONCLUSION BROAD CONCLUSION Faster move,intelligent decisions in moving the queens are the promises of standardising on interests of the players to play this puzzle. Finally we conclude that our project will be satisfying the players in all the aspects.
Future Scope and Enhancement The application is much flexible and extensible and hence further enhancements if needed,can be developed to perform quick move and to implement all the features of the puzzle.The screen shots are shown above which reveals the entire performance of the project.Synchronizaton modules can be used to store the user’s play on the puzzles.
REFERENCES www.howstuffworks.com www.wikipedia.org www.google.com “ C++ Complete reference” by Schildt  C++ programs by Varalakshmi Keyhtmldos books online

ma project

  • 1.
    INFO INSTITUTE OFENGINEERING WELCOMES U ALL
  • 2.
  • 3.
    EIGHT-QUEENS PROBLEM ProjectReport submitted by V.J.Aiswaryadevi (07BIT03), S.Dhivya (07BIT15), M.Kumuthanandhini (07BIT23)
  • 4.
    OBJECTIVE In partialfulfillment of the requirements for the award of degree of Bachelor of Engineering in Information Technology in Info Institute of Engineering
  • 5.
    Under the guidanceof Lecturers,Department of Information Technology Department of Information Technology Info Institute of Engineering Coimbatore -641101 BATCH 2007-2011
  • 6.
    ACKNOWLEDGEMENT First andforemost we acknowledge the abundant grace and presence of our LORD GOD ALMIGHTY throughout the project work and its successful completion. We thank our beloved founder late Shri . K.K.Veluchamy ,B.E .for their unceasing prayers for the student community
  • 7.
    ACKNOWLEDGEMENT And wethank all our beloved and respectful Dharbari charitable trustees for their grate source of inspiration during the project ,encouragement in the project. We wish to thank our Information Technology (IT) department lecturers for their valuable guidance.We would like to thank all other staffs for their co-operation with us during our project.
  • 8.
    ACKNOWLEDGEMENT Last butnot least we cannot fail to acknowledge the support and encouragement provided by our parents,friends and the staffs of Department of Information Technology.
  • 9.
    SYNOPSIS The projecteight queens is a puzzle game, that deals with the simple alignment or placing of queens without interfacing each other diagonally,horizontally or vertically.It is also called as one of the Chess board games.
  • 10.
    INDEX 1 INTRODUCTIONPurpose Intended Audience & Reading Suggestions Project Scope Platform Overview
  • 11.
    INDEX 2 PROJECT OVERVIEW Description of 8-Queens algorithm Operating environment Source code 22-70
  • 12.
    INDEX 3 MODULEDESCRIPTION Block diagram Screen shots
  • 13.
    CONCLUSION Broadconclusion Future Scope and Enhancement
  • 14.
    INTRODUCTION 1.1 PurposeEight queens is the chess board puzzle game which gives enough entertainment. Besides being an amusing puzzle this problem is interesting because kids love it and it's a great teaching tool in the upper grades of Elementary School. It also provides great programming exercises.
  • 15.
    1.2 Intended Audience and reading suggestions 1.2.1Intended users – All players and developers 1.2.2 Description – The rest of this document contains the technical study of what the project is actually about.It is a general view into the planned working of the system through sequence diagram and functional and non-functional requirements of the system. 1.2.3 Developer – is aware of the system to be developed so they could start their reading from system features and follow on.
  • 16.
    1.3 Project ScopeThis project is to solve the queens puzzle with different solutions.Here user and system interaction is established. The dynamic reports are available for the players.If there is no solution,the project will display the message “there is no solution”.In chess board, a queen can move as far as she pleases, horizontally, vertically, or diagonally. A chess board has 8 rows and 8 columns. The standard 8 by 8 Queen's problem asks how to place 8 queens on an ordinary chess board so that none of them can hit any other in one move is the basic reveal that we get from this project.
  • 17.
    1.3 Project ScopeAn obvious modification of the 8 by 8 problem is to consider an N by N &quot;chess board&quot; and ask if one can place N queens on such a board. It's pretty easy to see that this is impossible if N is 2 or 3, and it's reasonably straightforward to find solutions when N is 4, 5, 6, or 7.
  • 18.
    1.4 Platform Overview 1.4.1 Model: The platform used here is Windows xp.This project is done using the C++ software in its Integrated Development environment(IDE).This project is platform dependent. It is developed using more graph concepts like combinatorial concepts.Simple concepts are used for developing this
  • 19.
    2-PROJECT OVERVIEW 2.1Description of Eight Queens Product Features Using the Control Panel Let's run through the rows of the Control Panel: Row 1. Naturally, the Quit button lets you quit the program. You can also exit by clicking again on the applet, by typing 'x', 'X', 'q', or 'Q' in the control window, or by quitting your browser. You can dismiss a single solution or the drawing window by typing 'x', 'X', 'q', or 'Q' in the relevant window.
  • 20.
    Row 2. The red textfield let's you change the value of N , the dimension of the chess board. You can decrease or increase N by clicking on the &quot;<&quot; Size&quot;>&quot; button from 4-8, respectively. The Display Menu let's you determine the degree of animation on the drawing board. There are four levels, ordered by decreasing animation and increasing speed: Place Queen shows queens being moved, and has a ghost queen move from any queen that can hit the recently moved queen in the rightmost column.
  • 21.
    2.3 Operating EnvironmentHardware requirements Processor : Intel Pentium processors, AMD sempron etc., Memory : 512MB – 1GB RAM Hard disk : 60-240GB hard disk(Even more than this) Monitor : Any compatible Keyboard : Any compatible Software requirements Operating System : Windows XP/Vista Platform : C++
  • 22.
    Source Code Code: /* modified final*/ #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> #include<math.h> #include<process.h>
  • 23.
    //Functions used voidabout_prog(); void gotorc ( int, int ) ; void mainmenu ( ) ; void drawbox ( int, int, int, int, int, int ) ; void writechar ( char, int, int, int, int ) ; void writestring ( char*, int, int, int, int, int = 0 ) ; void clrwin ( int=0, int=0, int=25, int=80, int=7, int=0 ) ; void rules ( ) ; void about ( ) ; void quit ( ) ; void back ( ) ;
  • 24.
    void initmouse(void); voidyesmouse(void); void nomouse(void); void mouse(void); void limmouse(int,int,int,int); void background(); void first_screen(); void loadprog(); void acceptsize(); void error_mesg();
  • 25.
    int possible_results(); int search_rowcol(); void doneby(); void fill_poly(int,int,int,int,int,int); void draw_chess_board(); void erase(); void drawcircle(); void acceptbymouse(); void acceptbykeyboard(); int placequeen(int,int,int); void diagonal_1_check(int,int,int,int); void diagonal_2_check(int,int,int,int); void column(int,int,int,int); void result();
  • 26.
    // Global Variablesint exit_p; int chess[50][50]; int placed_row,size,row,col,x,y,radiusx,radiusy,ro,co,text_x=1; int iRow,iCol,iStatus; long int total_no_of_nodes,temp; long int count_exceed; int x_center = 320, y_center = 200, rad = 100,p[100],q[100]; long int count_num=0; union REGS i,o; char far *scr=(char far *) 0xB8000000L ; //screen address char ch, *menu[]= { &quot; *** MENU *** &quot;, &quot; ^Instructions &quot;, &quot; ^Enter Size Of ChessBoard &quot;, &quot; ^Use Mouse To place Queen &quot;, &quot; ^USE Keyboard To Place Queen &quot;, &quot; ^Possible Solutions &quot;, &quot; ^Exit &quot; };
  • 27.
    void about_prog() {clrwin ( 0, 0, 25, 80, 0, 3 ) ; drawbox ( 2, 2, 22, 75, 0, 8 ) ; writestring ( &quot;About Program&quot;, 30, 2, 14, 0 ) ; writestring ( &quot;* A Classic Combinatorial Problem Is To Place N-Queens on N by N&quot;, 3, 4, 11, 0) ; writestring ( &quot;ChessBoard So That No Two 'Attack',that is,so that no two of them &quot;, 5, 6, 11, 0 ) ;
  • 28.
    writestring ( &quot;areon the same row,column or diagonal.&quot;, 5, 8, 11, 0 ) ; writestring ( &quot;* This Problem Is Solved By 'BackTracking',BackTracking is a&quot;, 3,10,11, 0 ) ; writestring ( &quot;Algorithmic Strategy.&quot;, 5, 12, 15, 0 ) ; writestring ( &quot;* In This Program You Have To Choose a Position On ChessBoard For&quot;, 3, 14, 12, 0 ) ; writestring ( &quot;a Queen Then The BackTracking Algorithm Places All N-1 Queens&quot;, 5, 16, 12, 0 ) ; writestring ( &quot;On Right Place Satisfing Above Conditions.&quot;, 5, 18,12,0 ) ; writestring ( &quot;* Number Of All Possible Solutions For Placed Positions Can Be Viewed.&quot;, 3, 18, 13, 0 ) ; writestring ( &quot;Press Any Key To Continue&quot;, 50, 21, 13, 0 ) ; getch(); }
  • 29.
    void error_mesg() {int gd=DETECT,gm; initgraph(&gd,&gm,&quot;..\bgi&quot;); cleardevice(); background(); fill_poly(100,200,550,250,12,10); settextstyle(8, HORIZ_DIR, 3); setcolor(15); }
  • 30.
    void loadprog() {int i; _setcursortype(_NOCURSOR); drawbox ( 10, 30, 13, 50, 2, 0 ) ; writestring ( &quot;Loading.... &quot;, 32, 11, 0, 2, 1 ) ; gotoxy(1,25); textcolor(CYAN); for(i=0;i<79;i++) { cprintf(&quot;°&quot;); delay(20); } }
  • 31.
    void acceptsize() { int i,j; _setcursortype(_NOCURSOR); clrwin ( 0, 0, 25, 80, 0, 1 ) ; do { drawbox ( 10, 20, 14, 65, 2, 0 ) ; writestring ( &quot;ENTER THE SIZE OF CHESSBOARD (4 TO 25): &quot;, 22, 12,0, 2, 1 ) ; _setcursortype(_NORMALCURSOR); gotorc ( 12,61) ; scanf(&quot;%d&quot;,&size); _setcursortype(_NOCURSOR); }while(size<4 || size>26);
  • 32.
    total_no_of_nodes=0; for(j=0;j<size;j++) { temp=1; for(i=0;i<=j;i++) { temp=temp*(size-i); } total_no_of_nodes=total_no_of_nodes+temp; } //total_no_of_nodes=temp; for(i=0;i<size;i++) { for(j=0;j<size;j++) { chess[i][j]=-1; } } radiusy=((479/size))/2-3; radiusx=((479/size))/2-3; }
  • 33.
    int possible_results() {int gd=DETECT,gm,i,j,ex; char buff[5]; initgraph(&gd,&gm,&quot;..\bgi&quot;); draw_chess_board(); setcolor(10); settextstyle(1,0,3); outtextxy(500,100,&quot;Solution&quot;); outtextxy(500,120,&quot;Number&quot;); sprintf(buff,&quot;%d&quot;,count_num+1); outtextxy(500,140,buff);
  • 34.
    x=y=((getmaxy()/size)/2); for(i=0;i<size;i++) { x=((getmaxy()/size)/2); for(j=0;j<size;j++) { if(chess[i][j]==(i+50)) { setcolor(6); setfillstyle(9,6); fillellipse(x,y,radiusx,radiusy); } x=x+((getmaxy()/size)); } y=y+((getmaxy()/size)); }
  • 35.
    ex=getch(); if(ex==0) ex=getch();if(ex==27) { closegraph(); return 1; } closegraph(); return 0; }
  • 36.
    void cal_positions(int *a,intindex,int row,int ptr) { int i,j,b[50],k,placed,l,m,remove; if(exit_p==0) { if(index >= 1) { i=0; j=1; k=0; for(i=1;i<=size;i++) { for(j=0;j<ptr;j++) { if(a[j]==i) break; }
  • 37.
    if(j==ptr) b[k++]=i; }i=j=0; while(i<index && exit_p==0) { remove=0; if(chess[row][b[i]-1]==-1&& exit_p==0) { chess[row][b[i]-1]=(row+50); diagonal_1_check(row,b[i]-1,row,- 1); diagonal_2_check(row,b[i]-1,row,- 1); column(row,b[i]-1,row,-1); remove=1; a[ptr]=b[i]; cal_positions(a,index- 1,row+1,ptr+1); }
  • 38.
    if(remove==1 && exit_p==0){ chess[row][b[i]-1]=-1; diagonal_1_check(row,b[i]-1,- 1,row); diagonal_2_check(row,b[i]-1,- 1,row); column(row,b[i]-1,-1,row); } i++; } } else { exit_p=possible_results(); count_num++; } } }
  • 39.
    void instructions() // RULES { clrwin ( 0, 0, 25, 80, 0, 3 ) ; drawbox ( 2, 2, 21, 75, 0, 8 ) ; writestring ( &quot;INSTRUCTIONS&quot;, 30, 2, 12, 0 ) ; writestring ( &quot;YOU CAN USE KEYBOARD OR MOUSE TO PLACE A QUEEN&quot;, 5, 4,11, 0) ; writestring ( &quot;* USING KEYBOARD&quot;, 5, 6, 4, 0 ) ; writestring ( &quot; - USE ARROW KEYS TO GO UP,DOWN,LEFT,RIGHT.&quot;, 10, 8, 11,0 ) ; writestring ( &quot; - THEN PRESS ENTER TO PLACE A QUEEN&quot;, 10,10,11, 0 ) ; writestring ( &quot;~* USING MOUSE &quot;, 5, 12, 4, 0 ) ; writestring ( &quot;- FIRST LEFTCLICK ON BUTTON 'PLACED' WHICH IS AT RIGHTTOP.&quot;, 10, 14, 11, 0 ) ; writestring ( &quot;- THEN SELECT A PLACE ON CHESSBOARD BY RIGHTCLICK. &quot;, 10,16, 11, 0 ) ; writestring ( &quot;* THEN WAIT FOR FEW MINUTES&quot;, 5, 18, 13, 0 ) ; writestring ( &quot;Press Any Key To Continue&quot;, 50, 20, 13, 0 ) ; getch(); }
  • 40.
    void writestring(char*str,int row,intcol,int fore, int back, int del ) { //WRITES A STRING TO THE SCREN int x = 30 * del ; // DEL = 1 IF THERE SHOULD BE A DELAY IN DISPLAY // 0 OTHER WISE. IT IS SET TO ZERO BY DEFAULT while ( *str ) { // THE NEXT CHAR WILL BE DISPLAYED IN ATTRIBUTED MANNER if ( *str == '^' ) // HOT KEYS { str++ ; writechar (*str++, row++, col, 1, back ) ; delay ( x ) ; nosound ( ) ; delay ( x ) ; }
  • 41.
    else if (*str == 126 ) // HOT KEYS { str++; writechar(*str++, row++, col, 10, back ); delay ( x ) ; nosound ( ) ; delay ( x ) ; } else { writechar (*str++, row++, col, fore, back ) ; delay ( x ) ; nosound ( ) ; delay ( x ) ; } } nosound ( ) ; return ; }
  • 42.
    void clrwin(int sr,intsc,int er,int ec,int fore, int back) { // CLEARS THE WINDOW WITH THE GIVEN //FOREGROUND AND BACKGROUND COLOR i.h.ah=6; i.h.al=0; i.h.ch=sr; i.h.cl=sc; i.h.dh=er; i.h.dl=ec; i.h.bh=back*16+fore; int86(0x10,&i,&i); //clears the screen gotorc ( 0, 0 ) ; //moves the cursor to the appropriate position }
  • 43.
    void gotorc (int r, int c ) { // MOVES THE CURSOR TO THE //APPROPRIATE LOCATION REGS i, o ; i.h.ah = 2 ; i.h.bh = 0 ; i.h.dh = r ; i.h.dl = c ; int86 ( 16, &i, &o ) ; }
  • 44.
    void drawbox (int starty, int startx, int endy, int endx, int color, int shad ) { // FUNCTION TO DRAW THE BOX // JUST STEP THRU THE FUNCTION USING F7 KEY int i, j ; if ( starty > endy || startx > endx || color > 7 ) return ; for ( i = startx ; i < endx ; i ++ ) { for ( j = starty ; j < endy ; j ++ ) writechar ( ' ', i, j, 0, color ) ; writechar ( 219, i + 1, endy, shad, 0 ) ; } for ( i = endy ; i >= starty + 1 ; i -- ) { writechar ( 219, endx, i, shad, 0 ) ; writechar ( 219, endx + 1, i, shad, 0 ) ; } }
  • 45.
    void writechar(char ch,introw,int col,int fore, int back) { * ( scr + col * 160 + row * 2 ) = ch ; * ( scr + col * 160 + row * 2 + 1 ) = back * 16 + fore ; return ; } void doneby() { int i,j,z,c; int gd=DETECT,gm; initgraph(&gd,&gm,&quot;..\bgi&quot;); x_center = 320, y_center = 200; rad=100; setcolor(13); line(40,70,590,70); setcolor(2); rectangle(50,340,590,420); setcolor(10);
  • 46.
    settextstyle(5,0,5); outtextxy(55,345,“IT&quot;); settextstyle(4,0,3);for(i=1;i<=640;i++) { setcolor(9); line(i,20,i,20); line(i,30,i,30); delay(1); } for(j=10;j<=460;j++) { setcolor(9); line(610,j,610,j); line(620,j,620,j); delay(1); } for( z=640;z>=1;z--) { line(z,435,z,435); line(z,445,z,445); delay(1); } for( c=460;c>=10;c--) { setcolor(9); line(20,c,20,c); line(30,c,30,c); delay(1); }
  • 47.
    for ( i= 0; i < 10; i++ ) { p[i] = x_center + rad * cos(36*i*3.14159/180); q[i] = y_center + rad * sin(36*i*3.14159/180); } for ( i = 0; i < 10; i++ ) { for ( j = 0; j < 10; j++ ) { setcolor(14); line(p[i],q[i],p[j],q[j]); delay(25); } } delay(500); closegraph(); error_mesg(); outtextxy(250,210, &quot;Thank You&quot;); gotoxy(50,24); printf( &quot;Press Any Key To Exit&quot;); getch(); }
  • 48.
    void fill_poly(int x1,inty1,int x2,int y2,int color,int style) { int poly[8],i; poly[0] = x1; poly[1] = y1; poly[2] = x2; poly[3] = y1; poly[4] = x2; poly[5] = y2; poly[6] = x1; poly[7] = y2; setfillstyle(style,color); setcolor(color); fillpoly(4, poly); }
  • 49.
    void background() {int gd=DETECT,gm; initgraph(&gd,&gm,&quot;..\bgi&quot;); fill_poly(0,20,getmaxx(),40,11,11); fill_poly(getmaxx()-40,0,getmaxx()-20,getmaxy(),11,11); fill_poly(0,getmaxy()-40,getmaxx(),getmaxy()-20,11,11); fill_poly(20,0,40,getmaxy(),11,11); } void first_screen() { int i,j,k; fill_poly(125,50,500,100,12,10); settextstyle(10, HORIZ_DIR, 3); setcolor(10);
  • 50.
    outtextxy(135,50, &quot;N-Queen's Problem&quot;);fill_poly(125,300,500,350,12,10); settextstyle(7, HORIZ_DIR, 3); setcolor(11); outtextxy(135,300, &quot;N-Queen's Problem&quot;); fill_poly(50,50,100,350,12,10); settextstyle(8, 1, 3); setcolor(12); outtextxy(50,55, &quot;N-Queen's Problem&quot;); fill_poly(525,50,575,350,12,10); settextstyle(5, 1, 3); setcolor(13); outtextxy(525,50, &quot;N-Queen's Problem&quot;); gotoxy(50,25); printf(&quot;Press any key to continue&quot;); for ( i = 0; i < 10; i++ ) { p[i] = x_center + rad * cos(36*i*3.14159/180); q[i] = y_center + rad * sin(36*i*3.14159/180); } for ( i = 0; i < 10; i++ ) { for ( j = 0; j < 10; j++ ) { setcolor(14); line(p[i],q[i],p[j],q[j]); delay(50); } } getch(); }
  • 51.
    void initmouse(void) {iRow = 0,iCol = 0,iStatus = 0; asm{ mov ax,0; int 0x33; } } void yesmouse(void) { asm{ mov ax,1; int 0x33; } } void nomouse(void) { asm{ mov ax,2; int 0x33; } }
  • 52.
    void mouse(void) { asm{ mov ax,3; int 0x33; mov iRow,dx; mov iCol,cx; mov iStatus,bx; } } void limmouse(int iMinX,int iMinY,int iMaxX,int iMaxY) { yesmouse(); asm{ mov ax,7 mov cx,iMinX mov dx,iMaxX int 0x33 } asm{ mov ax,8 mov cx,iMinY mov dx,iMaxY int 0x33 } }
  • 53.
    void draw_chess_board() { int color1,color2,poly[8],i,j; x=0;y=0; color1=1; color2=0; for(i=0;i<size;i++) { color1=color2; for(j=0;j<size;j++) { if(color1==1) color1=0; else if(color1==0) color1=1;
  • 54.
    setcolor(2); rectangle(x,y,x+(getmaxy()/size),y+(getmaxy()/size)); poly[0] = x; poly[1] = y; poly[4] = x+(getmaxy()/size); poly[5] = y+(getmaxy()/size); poly[2] = x+(getmaxy()/size); poly[3] = y; poly[6] = x; poly[7] = y+(getmaxy()/size); setcolor(2); if(color1!=0) { setfillstyle(1,color1); fillpoly(4,poly); x=x+getmaxy()/size; } else { rectangle(x,y,x+getmaxy()/size,getmaxy()/size); x=x+getmaxy()/size; } } if(color2==1) color2=0; else if(color2==0) color2=1; x=0; y=y+getmaxy()/size; } }
  • 55.
    void result() { int gd=DETECT,gm,count,i,j; initgraph(&gd,&gm,&quot;..\bgi&quot;); draw_chess_board(); settextstyle(3,0,4); setcolor(5); outtextxy(500,5,&quot;Solution&quot;); outtextxy(500,50,&quot;Found&quot;); setcolor(2); rectangle(495,150,getmaxx(),479); setcolor(15); settextstyle(1,0,1); outtextxy(500,200,&quot;This Queen Is&quot;); outtextxy(500,220,&quot;Placed By User&quot;); setcolor(4); setfillstyle(10,4); fillellipse(550,180,20,20);
  • 56.
    setcolor(15); outtextxy(500,300,&quot;These Queens&quot;); outtextxy(500,320,&quot;Are Placed&quot;); outtextxy(500,340,&quot;According to&quot;); outtextxy(500,360,&quot;Queen Placed&quot;); outtextxy(500,380,&quot;By User&quot;); setcolor(6); setfillstyle(9, 6); fillellipse(550,280,20,20); x=y=((getmaxy()/size)/2); for(i=0;i<size;i++) { x=((getmaxy()/size)/2); for(j=0;j<size;j++) { if(chess[i][j]==(i+50)) { if(i==placed_row) { setcolor(4); setfillstyle(10, 4); } else { setcolor(6); setfillstyle(9, 6); } fillellipse(x,y,radiusx,radiusy); } x=x+((getmaxy()/size)); } y=y+((getmaxy()/size)); } getch(); closegraph(); }
  • 57.
    void erase() { int pixel; pixel=getpixel(x+radiusx+1,y); setcolor(pixel); setfillstyle(1,pixel); fillellipse(x,y,radiusx,radiusy); } void drawcircle() { setcolor(4); setfillstyle(10,4); fillellipse(x,y,radiusx,radiusy); } int search_rowcol() { y=0; for(ro=0;ro<size;ro++) { x=0; for(co=0;co<size;co++) { if(x<iCol && iCol<(x+479/size) && y<iRow && iRow<(y+479/size)) { return 1; } x=x+(479/size); }
  • 58.
    y=y+(479/size); } return 0; } void acceptbymouse() { int prevx,prevy,break_flag,pressed,valid; int gd=DETECT,gm; initgraph(&gd,&gm,&quot;..\bgi&quot;); draw_chess_board(); initmouse(); limmouse(0,0,getmaxx()-50,getmaxy()); yesmouse(); fill_poly(495,15,605,45,11,1); fill_poly(500,20,600,40,5,1); setcolor(14); settextstyle(5,0,3); outtextxy(525,12,&quot;Place&quot;); setcolor(15); settextstyle(1,0,3); outtextxy(500,100,&quot;To Place&quot;); outtextxy(500,120,&quot;A Queen&quot;); outtextxy(500,140,&quot;LeftClick&quot;); outtextxy(500,160,&quot;On Button&quot;); outtextxy(500,180,&quot;'Placed' &quot;);
  • 59.
    while(1) { mouse();if(iStatus==1 && 500<=iCol &&iCol<=605 && 15<=iRow &&iRow<=40) { nomouse(); fill_poly(495,15,605,50,0,1); break; } } prevx=0;prevy=0; fill_poly(500,0,getmaxx(),getmaxy(),0,1); setcolor(15); settextstyle(1,0,3); outtextxy(500,100,&quot;To Place&quot;); outtextxy(500,120,&quot;A Queen&quot;); outtextxy(500,140,&quot;RightClick&quot;); outtextxy(500,160,&quot;On Proper&quot;); outtextxy(500,180,&quot;Place&quot;);
  • 60.
    while(1) { yesmouse(); mouse(); if(iStatus==2) { break; } valid=search_rowcol(); if(valid==1) { if(prevx<iCol && iCol<(prevx+479/size) && prevy<iRow && iRow<(prevy+479/size)) { nomouse(); setcolor(15); prevx=x;prevy=y; rectangle(x,y,x+(479/size),y+(479/size)); } else { setcolor(2); rectangle(prevx,prevy,prevx+(479/size),prevy+(479/size)); nomouse(); setcolor(15); prevx=x;prevy=y; rectangle(x,y,x+(479/size),y+(479/size)); } yesmouse(); } } nomouse(); x=x+(479/size)/2; y=y+(479/size)/2; drawcircle(); placed_row=ro; placequeen(ro,co,0); delay(1000); closegraph(); }
  • 61.
    void acceptbykeyboard() { int gd=DETECT,gm,c,i,j; initgraph(&gd,&gm,&quot;..\bgi&quot;); draw_chess_board(); x=(getmaxy()/size)/2; y=(getmaxy()/size)/2; i=0;j=0; drawcircle(); do { c=getch(); if(c==0) c=getch(); if(c==72 && y-(getmaxy()/size)>0) { erase(); y=y-(getmaxy()/size); drawcircle(); i--; } else if(c==80 && y+(getmaxy()/size)<479) { erase(); y=y+(getmaxy()/size); drawcircle(); i++; } else if(c==75&& x-(getmaxy()/size)>0) { erase(); x=x-(getmaxy()/size); drawcircle(); j--; } else if(c==77 &&x+(getmaxy()/size)<479) { erase(); x=x+(getmaxy()/size); drawcircle(); j++; } if(c==13) { drawcircle(); placed_row=i; placequeen(i,j,0); c=27; } }while(c!=27); closegraph(); }
  • 62.
    if(j1==size) { if(i-1!=placed_row) { i--; row--; } else { i=i-2; row=row-2; } for(j=0;j<size;j++) { if(chess[i][j]==(i+50)) break; } chess[i][j]=-1; diagonal_1_check(i,j,-1,i); diagonal_2_check(i,j,-1,i); column(i,j,-1,i); textcolor(0); textbackground(0); gotoxy(--text_x,25); cprintf(&quot; &quot;); break_up=placequeen(row,j+1,0); } } return 0; } int placequeen(int i,int j,int break_up) { int j1; if(break_up==0) { count_exceed++; if(count_exceed>total_no_of_nodes) { error_mesg(); outtextxy(110,210, &quot;Sorry,Solution Is Not Possible !!&quot;); gotoxy(50,24); printf( &quot;Press Any Key To Continue&quot;); getch(); closegraph(); return 1; } for(j1=j;j1<size;j1++) { if(chess[i][j1]==-1) { textcolor(3); gotoxy(text_x++,25); cprintf(&quot;°&quot;); chess[i][j1]=(i+50); diagonal_1_check(i,j1,i,-1); diagonal_2_check(i,j1,i,-1); column(i,j1,i,-1); break; } }
  • 63.
    void diagonal_1_check(inti1,int j1,int val,int check) { int i2,j2; i2=i1; j2=j1; i2--;j2--; while(i2>=0&&j2>=0) { if(check==chess[i2][j2]) chess[i2][j2]=val; i2--;j2--; } i2=i1; j2=j1; i2++;j2++; while(i2<size&&j2<size) { if(check==chess[i2][j2]) chess[i2][j2]=val; i2++;j2++; } }
  • 64.
    void diagonal_2_check(inti1,int j1,int val,int check) { int i2,i3,j2; i2=i1; j2=j1; i2--;j2++; while(i2>=0&&j2<size) { if(check==chess[i2][j2]) chess[i2][j2]=val; i2--;j2++; } i2=i1; j2=j1; i2++;j2--; while(i2<size&&j2>=0) { if(check==chess[i2][j2]) chess[i2][j2]=val; i2++;j2--; } }
  • 65.
    void column(int i1,intj1,int val,int check) { int j2; for(j2=0;j2<size;j2++) { if(chess[i1][j2]==check) { chess[i1][j2]=val; } } for(j2=0;j2<size;j2++) { if(chess[j2][j1]==check) { chess[j2][j1]=val; } } }
  • 66.
    if(status==0) status=getch(); switch(status){ case 72:if(choice==1) choice=6; else choice--; break; case 80:if(choice==6) choice=1; else choice++; break; case 13: if(choice==1) instructions(); else if(choice==2) { acceptsize(); } void main() { int i,j,choice,status,breakup,b[50]; background(); // first_screen(); closegraph(); loadprog(); about_prog(); size=-1; choice=1; do { clrwin ( 0, 0, 25, 80, 0, 1 ) ; drawbox ( 5, 20, 20, 55, 4, 0 ) ; _setcursortype(_NOCURSOR); for ( int i = 0 ; i <= 6 ; i ++ ) { if ( choice == i ) writestring ( menu[i], 20, 7 + 2 * i, 0, 10 ) ; else writestring ( menu[i], 20, 7 + 2 * i, 10, 4 ) ; } status=getch();
  • 67.
    else if(choice==6) { doneby(); exit(0); else if(size==-1) { error_mesg(); outtextxy(110,210, &quot;First Enter Size Of ChessBoard&quot;); gotoxy(50,24); printf( &quot;Press Any Key To Continue&quot;); getch(); closegraph(); } else if(choice==5) { for(i=0;i<size;i++) { b[i]=0; } exit_p=0; cal_positions(b,size,0,0); } if(status==0) status=getch(); switch(status) { case 72:if(choice==1) choice=6; else choice--; break; case 80:if(choice==6) choice=1; else choice++; break; case 13: if(choice==1) instructions(); else if(choice==2) { acceptsize(); }
  • 68.
    else if(choice==4||choice==3) { if(choice==4) acceptbykeyboard(); else if(choice==3) acceptbymouse(); gotoxy(30,13); textcolor(3); textbackground(1); printf(&quot;Placing Please Wait........&quot;); row=0; count_exceed=0; breakup=0; while(row!=size &&breakup==0) { if(row==placed_row) row++; if(row==size) break; breakup=placequeen(row,0,0); row++; } if(breakup==0) { for(i=text_x;i<79;i++) { textcolor(2); cprintf(&quot;°&quot;); delay(30); } result(); }
  • 69.
    } break; } }while(1); }
  • 70.
    END OF THESOURCE CODE
  • 71.
    FLOW CHART STARTSET BACKGROUND() LINK THE BGI GRAPHIC FILE WITH USER SCREEN A
  • 72.
    READ SIZE OFCHESS BOARD A IF SIZE IS BETWEEN 4-8 PLACE-QUEEN () B YES EXIT(0) NO
  • 73.
    DISPLAY INSTRUCTION TOPLACE B DISPLAY THE RESULT IF EXIT CLOSE GRAPH() YES C
  • 74.
  • 75.
  • 76.
    CONCLUSION BROAD CONCLUSIONFaster move,intelligent decisions in moving the queens are the promises of standardising on interests of the players to play this puzzle. Finally we conclude that our project will be satisfying the players in all the aspects.
  • 77.
    Future Scope andEnhancement The application is much flexible and extensible and hence further enhancements if needed,can be developed to perform quick move and to implement all the features of the puzzle.The screen shots are shown above which reveals the entire performance of the project.Synchronizaton modules can be used to store the user’s play on the puzzles.
  • 78.
    REFERENCES www.howstuffworks.com www.wikipedia.orgwww.google.com “ C++ Complete reference” by Schildt C++ programs by Varalakshmi Keyhtmldos books online