ma project

0 views
1,276 views

Published on

Published in: Business, Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
0
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
22
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

ma project

  1. 1. INFO INSTITUTE OF ENGINEERING WELCOMES U ALL
  2. 2. EIGHT QUEENS PROBLEM
  3. 3. EIGHT-QUEENS PROBLEM <ul><li>Project Report submitted by </li></ul><ul><li>V.J.Aiswaryadevi (07BIT03), </li></ul><ul><li>S.Dhivya (07BIT15), </li></ul><ul><li>M.Kumuthanandhini (07BIT23) </li></ul>
  4. 4. <ul><li>OBJECTIVE </li></ul><ul><li>In partial fulfillment of the requirements for the award of degree of Bachelor of Engineering in Information Technology in Info Institute of Engineering </li></ul>
  5. 5. <ul><li>Under the guidance of </li></ul><ul><li>Lecturers,Department of Information Technology </li></ul><ul><li>Department of Information Technology </li></ul><ul><li>Info Institute of Engineering </li></ul><ul><li>Coimbatore -641101 </li></ul><ul><li>BATCH 2007-2011 </li></ul>
  6. 6. ACKNOWLEDGEMENT <ul><li>First and foremost we acknowledge the abundant grace and presence of our LORD GOD ALMIGHTY throughout the project work and its successful completion. </li></ul><ul><li>We thank our beloved founder late Shri . K.K.Veluchamy ,B.E .for their unceasing prayers for the student community </li></ul>
  7. 7. ACKNOWLEDGEMENT <ul><li>And we thank all our beloved and respectful Dharbari charitable trustees for their grate source of inspiration during the project ,encouragement in the project. </li></ul><ul><li>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. </li></ul>
  8. 8. ACKNOWLEDGEMENT <ul><li>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. </li></ul>
  9. 9. SYNOPSIS <ul><li>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. </li></ul>
  10. 10. INDEX <ul><li>1 INTRODUCTION </li></ul><ul><li>Purpose </li></ul><ul><li>Intended Audience & Reading Suggestions </li></ul><ul><li>Project Scope </li></ul><ul><li>Platform Overview </li></ul>
  11. 11. INDEX <ul><li>2 PROJECT OVERVIEW </li></ul><ul><li>Description of 8-Queens algorithm </li></ul><ul><li>Operating environment </li></ul><ul><li>Source code 22-70 </li></ul>
  12. 12. INDEX <ul><li>3 MODULE DESCRIPTION </li></ul><ul><li>Block diagram </li></ul><ul><li>Screen shots </li></ul>
  13. 13. CONCLUSION <ul><li>Broad conclusion </li></ul><ul><li>Future Scope and Enhancement </li></ul>
  14. 14. INTRODUCTION <ul><li>1.1 Purpose </li></ul><ul><li>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. </li></ul>
  15. 15. <ul><li>1.2 Intended Audience and reading suggestions </li></ul><ul><li>1.2.1Intended users – All players and developers </li></ul><ul><li>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. </li></ul><ul><li>1.2.3 Developer – is aware of the system to be developed so they could start their reading from system features and follow on. </li></ul>
  16. 16. <ul><li>1.3 Project Scope </li></ul><ul><li>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. </li></ul>
  17. 17. <ul><li>1.3 Project Scope </li></ul><ul><li>An 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. </li></ul>
  18. 18. <ul><li>1.4 Platform Overview </li></ul><ul><li>1.4.1 Model: </li></ul><ul><li>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 </li></ul>
  19. 19. 2-PROJECT OVERVIEW <ul><li>2.1 Description of Eight Queens </li></ul><ul><li>Product Features </li></ul><ul><li>Using the Control Panel </li></ul><ul><li>Let's run through the rows of the Control Panel: </li></ul><ul><li>Row 1. </li></ul><ul><ul><li>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. </li></ul></ul>
  20. 20. <ul><li>Row 2. </li></ul><ul><ul><li>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. </li></ul></ul><ul><ul><li>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: </li></ul></ul><ul><ul><ul><li>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. </li></ul></ul></ul>
  21. 21. <ul><li>2.3 Operating Environment </li></ul><ul><li>Hardware requirements </li></ul><ul><li>Processor : Intel Pentium processors, AMD sempron etc., </li></ul><ul><li>Memory : 512MB – 1GB RAM </li></ul><ul><li>Hard disk : 60-240GB hard disk(Even more than this) </li></ul><ul><li>Monitor : Any compatible </li></ul><ul><li>Keyboard : Any compatible </li></ul><ul><li>Software requirements </li></ul><ul><li>Operating System : Windows XP/Vista </li></ul><ul><li>Platform : C++ </li></ul>
  22. 22. Source Code <ul><li>Code : </li></ul><ul><li>/* modified final*/ </li></ul><ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>#include<graphics.h> </li></ul><ul><li>#include<dos.h> </li></ul><ul><li>#include<math.h> </li></ul><ul><li>#include<process.h> </li></ul>
  23. 23. <ul><li>//Functions used </li></ul><ul><li>void about_prog(); </li></ul><ul><li>void gotorc ( int, int ) ; </li></ul><ul><li>void mainmenu ( ) ; </li></ul><ul><li>void drawbox ( int, int, int, int, int, int ) ; </li></ul><ul><li>void writechar ( char, int, int, int, int ) ; </li></ul><ul><li>void writestring ( char*, int, int, int, int, int = 0 ) ; </li></ul><ul><li>void clrwin ( int=0, int=0, int=25, int=80, int=7, int=0 ) ; </li></ul><ul><li>void rules ( ) ; </li></ul><ul><li>void about ( ) ; </li></ul><ul><li>void quit ( ) ; </li></ul><ul><li>void back ( ) ; </li></ul>
  24. 24. <ul><li>void initmouse(void); </li></ul><ul><li>void yesmouse(void); </li></ul><ul><li>void nomouse(void); </li></ul><ul><li>void mouse(void); </li></ul><ul><li>void limmouse(int,int,int,int); </li></ul><ul><li>void background(); </li></ul><ul><li>void first_screen(); </li></ul><ul><li>void loadprog(); </li></ul><ul><li>void acceptsize(); </li></ul><ul><li>void error_mesg(); </li></ul>
  25. 25. <ul><li>int possible_results(); </li></ul><ul><li>int search_rowcol(); </li></ul><ul><li>void doneby(); </li></ul><ul><li>void fill_poly(int,int,int,int,int,int); </li></ul><ul><li>void draw_chess_board(); </li></ul><ul><li>void erase(); </li></ul><ul><li>void drawcircle(); </li></ul><ul><li>void acceptbymouse(); </li></ul><ul><li>void acceptbykeyboard(); </li></ul><ul><li>int placequeen(int,int,int); </li></ul><ul><li>void diagonal_1_check(int,int,int,int); </li></ul><ul><li>void diagonal_2_check(int,int,int,int); </li></ul><ul><li>void column(int,int,int,int); </li></ul><ul><li>void result(); </li></ul>
  26. 26. <ul><li>// Global Variables </li></ul><ul><li>int exit_p; </li></ul><ul><li>int chess[50][50]; </li></ul><ul><li>int placed_row,size,row,col,x,y,radiusx,radiusy,ro,co,text_x=1; </li></ul><ul><li>int iRow,iCol,iStatus; </li></ul><ul><li>long int total_no_of_nodes,temp; </li></ul><ul><li>long int count_exceed; </li></ul><ul><li>int x_center = 320, y_center = 200, rad = 100,p[100],q[100]; </li></ul><ul><li>long int count_num=0; </li></ul><ul><li>union REGS i,o; </li></ul><ul><li>char far *scr=(char far *) 0xB8000000L ; //screen address </li></ul><ul><li>char ch, *menu[]= </li></ul><ul><li>{ </li></ul><ul><li>&quot; *** MENU *** &quot;, </li></ul><ul><li>&quot; ^Instructions &quot;, </li></ul><ul><li>&quot; ^Enter Size Of ChessBoard &quot;, </li></ul><ul><li>&quot; ^Use Mouse To place Queen &quot;, </li></ul><ul><li>&quot; ^USE Keyboard To Place Queen &quot;, </li></ul><ul><li>&quot; ^Possible Solutions &quot;, </li></ul><ul><li>&quot; ^Exit &quot; </li></ul><ul><li>}; </li></ul>
  27. 27. <ul><li>void about_prog() </li></ul><ul><li>{ </li></ul><ul><li>clrwin ( 0, 0, 25, 80, 0, 3 ) ; </li></ul><ul><li>drawbox ( 2, 2, 22, 75, 0, 8 ) ; </li></ul><ul><li>writestring ( &quot;About Program&quot;, 30, 2, 14, 0 ) ; </li></ul><ul><li>writestring ( &quot;* A Classic Combinatorial Problem Is To Place N-Queens on N by N&quot;, 3, 4, 11, 0) ; </li></ul><ul><li>writestring ( &quot;ChessBoard So That No Two 'Attack',that is,so that no two of them &quot;, 5, 6, 11, 0 ) ; </li></ul>
  28. 28. <ul><li>writestring ( &quot;are on the same row,column or diagonal.&quot;, 5, 8, 11, 0 ) ; </li></ul><ul><li>writestring ( &quot;* This Problem Is Solved By 'BackTracking',BackTracking is a&quot;, 3,10,11, 0 ) ; </li></ul><ul><li>writestring ( &quot;Algorithmic Strategy.&quot;, 5, 12, 15, 0 ) ; </li></ul><ul><li>writestring ( &quot;* In This Program You Have To Choose a Position On </li></ul><ul><li>ChessBoard For&quot;, 3, 14, 12, 0 ) ; </li></ul><ul><li>writestring ( &quot;a Queen Then The BackTracking Algorithm Places All N-1 </li></ul><ul><li>Queens&quot;, 5, 16, 12, 0 ) ; </li></ul><ul><li>writestring ( &quot;On Right Place Satisfing Above Conditions.&quot;, 5, 18,12,0 ) ; </li></ul><ul><li>writestring ( &quot;* Number Of All Possible Solutions For Placed Positions </li></ul><ul><li>Can Be Viewed.&quot;, 3, 18, 13, 0 ) ; </li></ul><ul><li>writestring ( &quot;Press Any Key To Continue&quot;, 50, 21, 13, 0 ) ; </li></ul><ul><li>getch(); </li></ul><ul><li>} </li></ul>
  29. 29. <ul><li>void error_mesg() </li></ul><ul><li>{ </li></ul><ul><li>int gd=DETECT,gm; </li></ul><ul><li>initgraph(&gd,&gm,&quot;..gi&quot;); </li></ul><ul><li>cleardevice(); </li></ul><ul><li>background(); </li></ul><ul><li>fill_poly(100,200,550,250,12,10); </li></ul><ul><li>settextstyle(8, HORIZ_DIR, 3); </li></ul><ul><li>setcolor(15); </li></ul><ul><li>} </li></ul>
  30. 30. <ul><li>void loadprog() </li></ul><ul><li>{ </li></ul><ul><li>int i; </li></ul><ul><li>_setcursortype(_NOCURSOR); </li></ul><ul><li>drawbox ( 10, 30, 13, 50, 2, 0 ) ; </li></ul><ul><li>writestring ( &quot;Loading.... &quot;, 32, 11, 0, 2, 1 ) ; </li></ul><ul><li>gotoxy(1,25); </li></ul><ul><li>textcolor(CYAN); </li></ul><ul><li>for(i=0;i<79;i++) </li></ul><ul><li>{ </li></ul><ul><li> cprintf(&quot;°&quot;); </li></ul><ul><li> delay(20); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  31. 31. <ul><li>void acceptsize() </li></ul><ul><li>{ </li></ul><ul><li> int i,j; </li></ul><ul><li> _setcursortype(_NOCURSOR); </li></ul><ul><li> clrwin ( 0, 0, 25, 80, 0, 1 ) ; </li></ul><ul><li> do </li></ul><ul><li> { </li></ul><ul><li> drawbox ( 10, 20, 14, 65, 2, 0 ) ; </li></ul><ul><li> writestring ( &quot;ENTER THE SIZE OF CHESSBOARD (4 TO 25): &quot;, 22, 12,0, 2, 1 ) ; </li></ul><ul><li> _setcursortype(_NORMALCURSOR); </li></ul><ul><li> gotorc ( 12,61) ; </li></ul><ul><li> scanf(&quot;%d&quot;,&size); </li></ul><ul><li> _setcursortype(_NOCURSOR); </li></ul><ul><li> }while(size<4 || size>26); </li></ul>
  32. 32. <ul><li>total_no_of_nodes=0; </li></ul><ul><li> for(j=0;j<size;j++) </li></ul><ul><li> { </li></ul><ul><li>temp=1; </li></ul><ul><li>for(i=0;i<=j;i++) </li></ul><ul><li>{ </li></ul><ul><li>temp=temp*(size-i); </li></ul><ul><li>} </li></ul><ul><li>total_no_of_nodes=total_no_of_nodes+temp; </li></ul><ul><li> } </li></ul><ul><li> //total_no_of_nodes=temp; </li></ul><ul><li> for(i=0;i<size;i++) </li></ul><ul><li> { </li></ul><ul><li>for(j=0;j<size;j++) </li></ul><ul><li>{ </li></ul><ul><li>chess[i][j]=-1; </li></ul><ul><li>} </li></ul><ul><li> } </li></ul><ul><li> radiusy=((479/size))/2-3; </li></ul><ul><li> radiusx=((479/size))/2-3; </li></ul><ul><li>} </li></ul>
  33. 33. <ul><li>int possible_results() </li></ul><ul><li>{ </li></ul><ul><li>int gd=DETECT,gm,i,j,ex; </li></ul><ul><li>char buff[5]; </li></ul><ul><li>initgraph(&gd,&gm,&quot;..gi&quot;); </li></ul><ul><li>draw_chess_board(); </li></ul><ul><li>setcolor(10); </li></ul><ul><li>settextstyle(1,0,3); </li></ul><ul><li>outtextxy(500,100,&quot;Solution&quot;); </li></ul><ul><li>outtextxy(500,120,&quot;Number&quot;); </li></ul><ul><li>sprintf(buff,&quot;%d&quot;,count_num+1); </li></ul><ul><li>outtextxy(500,140,buff); </li></ul>
  34. 34. <ul><li>x=y=((getmaxy()/size)/2); </li></ul><ul><li> for(i=0;i<size;i++) </li></ul><ul><li> { </li></ul><ul><li> x=((getmaxy()/size)/2); </li></ul><ul><li>for(j=0;j<size;j++) </li></ul><ul><li>{ </li></ul><ul><li> if(chess[i][j]==(i+50)) </li></ul><ul><li> { </li></ul><ul><li>setcolor(6); </li></ul><ul><li>setfillstyle(9,6); </li></ul><ul><li>fillellipse(x,y,radiusx,radiusy); </li></ul><ul><li> } </li></ul><ul><li> x=x+((getmaxy()/size)); } </li></ul><ul><li>y=y+((getmaxy()/size)); </li></ul><ul><li>} </li></ul>
  35. 35. <ul><li>ex=getch(); </li></ul><ul><li>if(ex==0) </li></ul><ul><li>ex=getch(); </li></ul><ul><li>if(ex==27) </li></ul><ul><li>{ </li></ul><ul><li>closegraph(); </li></ul><ul><li>return 1; </li></ul><ul><li>} </li></ul><ul><li>closegraph(); </li></ul><ul><li>return 0; </li></ul><ul><li>} </li></ul>
  36. 36. <ul><li>void cal_positions(int *a,int index,int row,int ptr) </li></ul><ul><li>{ </li></ul><ul><li>int i,j,b[50],k,placed,l,m,remove; </li></ul><ul><li>if(exit_p==0) </li></ul><ul><li>{ </li></ul><ul><li>if(index >= 1) </li></ul><ul><li>{ </li></ul><ul><li>i=0; </li></ul><ul><li>j=1; </li></ul><ul><li>k=0; </li></ul><ul><li>for(i=1;i<=size;i++) </li></ul><ul><li>{ </li></ul><ul><li> for(j=0;j<ptr;j++) </li></ul><ul><li> { </li></ul><ul><li> if(a[j]==i) </li></ul><ul><li>break; </li></ul><ul><li> } </li></ul>
  37. 37. <ul><li>if(j==ptr) </li></ul><ul><li>b[k++]=i; </li></ul><ul><li>} </li></ul><ul><li>i=j=0; </li></ul><ul><li>while(i<index && exit_p==0) </li></ul><ul><li>{ </li></ul><ul><li> remove=0; </li></ul><ul><li>if(chess[row][b[i]-1]==-1&& exit_p==0) </li></ul><ul><li>{ </li></ul><ul><li>chess[row][b[i]-1]=(row+50); </li></ul><ul><li>diagonal_1_check(row,b[i]-1,row,- 1); </li></ul><ul><li>diagonal_2_check(row,b[i]-1,row,- 1); </li></ul><ul><li>column(row,b[i]-1,row,-1); </li></ul><ul><li>remove=1; </li></ul><ul><li>a[ptr]=b[i]; </li></ul><ul><li>cal_positions(a,index- 1,row+1,ptr+1); </li></ul><ul><li>} </li></ul>
  38. 38. <ul><li>if(remove==1 && exit_p==0) </li></ul><ul><li>{ </li></ul><ul><li>chess[row][b[i]-1]=-1; </li></ul><ul><li>diagonal_1_check(row,b[i]-1,- 1,row); </li></ul><ul><li>diagonal_2_check(row,b[i]-1,- 1,row); </li></ul><ul><li>column(row,b[i]-1,-1,row); </li></ul><ul><li>} </li></ul><ul><li>i++; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>else </li></ul><ul><li>{ </li></ul><ul><li>exit_p=possible_results(); </li></ul><ul><li>count_num++; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  39. 39. <ul><li>void instructions( ) // RULES </li></ul><ul><li>{ </li></ul><ul><li>clrwin ( 0, 0, 25, 80, 0, 3 ) ; </li></ul><ul><li>drawbox ( 2, 2, 21, 75, 0, 8 ) ; </li></ul><ul><li>writestring ( &quot;INSTRUCTIONS&quot;, 30, 2, 12, 0 ) ; </li></ul><ul><li>writestring ( &quot;YOU CAN USE KEYBOARD OR MOUSE TO PLACE A QUEEN&quot;, 5, 4,11, 0) ; </li></ul><ul><li>writestring ( &quot;* USING KEYBOARD&quot;, 5, 6, 4, 0 ) ; </li></ul><ul><li>writestring ( &quot; - USE ARROW KEYS TO GO UP,DOWN,LEFT,RIGHT.&quot;, 10, 8, </li></ul><ul><li>11,0 ) ; </li></ul><ul><li>writestring ( &quot; - THEN PRESS ENTER TO PLACE A QUEEN&quot;, 10,10,11, 0 ) ; </li></ul><ul><li>writestring ( &quot;~* USING MOUSE &quot;, 5, 12, 4, 0 ) ; </li></ul><ul><li>writestring ( &quot;- FIRST LEFTCLICK ON BUTTON 'PLACED' WHICH IS AT RIGHTTOP.&quot;, 10, 14, 11, 0 ) ; </li></ul><ul><li>writestring ( &quot;- THEN SELECT A PLACE ON CHESSBOARD BY RIGHTCLICK. &quot;, 10,16, 11, 0 ) ; </li></ul><ul><li>writestring ( &quot;* THEN WAIT FOR FEW MINUTES&quot;, 5, 18, 13, 0 ) ; </li></ul><ul><li>writestring ( &quot;Press Any Key To Continue&quot;, 50, 20, 13, 0 ) ; </li></ul><ul><li>getch(); </li></ul><ul><li>} </li></ul>
  40. 40. <ul><li>void writestring(char*str,int row,int col,int fore, int back, int del ) </li></ul><ul><li>{ </li></ul><ul><li>//WRITES A STRING TO THE SCREN </li></ul><ul><li>int x = 30 * del ; // DEL = 1 IF THERE SHOULD BE A DELAY IN DISPLAY </li></ul><ul><li>// 0 OTHER WISE. IT IS SET TO ZERO BY DEFAULT </li></ul><ul><li>while ( *str ) </li></ul><ul><li>{ </li></ul><ul><li>// THE NEXT CHAR WILL BE DISPLAYED IN ATTRIBUTED MANNER </li></ul><ul><li>if ( *str == '^' ) // HOT KEYS </li></ul><ul><li>{ </li></ul><ul><li>str++ ; </li></ul><ul><li>writechar (*str++, row++, col, 1, back ) ; </li></ul><ul><li>delay ( x ) ; </li></ul><ul><li>nosound ( ) ; </li></ul><ul><li>delay ( x ) ; </li></ul><ul><li>} </li></ul>
  41. 41. <ul><li>else if ( *str == 126 ) // HOT KEYS </li></ul><ul><li>{ </li></ul><ul><li>str++; </li></ul><ul><li>writechar(*str++, row++, col, 10, back ); </li></ul><ul><li>delay ( x ) ; </li></ul><ul><li>nosound ( ) ; </li></ul><ul><li>delay ( x ) ; </li></ul><ul><li>} </li></ul><ul><li>else </li></ul><ul><li>{ </li></ul><ul><li>writechar (*str++, row++, col, fore, back ) ; </li></ul><ul><li>delay ( x ) ; </li></ul><ul><li>nosound ( ) ; </li></ul><ul><li>delay ( x ) ; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>nosound ( ) ; </li></ul><ul><li>return ; </li></ul><ul><li>} </li></ul>
  42. 42. <ul><li>void clrwin(int sr,int sc,int er,int ec,int fore, int back) </li></ul><ul><li>{ </li></ul><ul><li>// CLEARS THE WINDOW WITH THE GIVEN //FOREGROUND AND BACKGROUND COLOR </li></ul><ul><li>i.h.ah=6; </li></ul><ul><li>i.h.al=0; </li></ul><ul><li>i.h.ch=sr; </li></ul><ul><li>i.h.cl=sc; </li></ul><ul><li>i.h.dh=er; </li></ul><ul><li>i.h.dl=ec; </li></ul><ul><li>i.h.bh=back*16+fore; </li></ul><ul><li>int86(0x10,&i,&i); //clears the screen </li></ul><ul><li>gotorc ( 0, 0 ) ; //moves the cursor to the appropriate position </li></ul><ul><li>} </li></ul>
  43. 43. <ul><li>void gotorc ( int r, int c ) </li></ul><ul><li>{ </li></ul><ul><li>// MOVES THE CURSOR TO THE //APPROPRIATE LOCATION </li></ul><ul><li>REGS i, o ; </li></ul><ul><li>i.h.ah = 2 ; </li></ul><ul><li>i.h.bh = 0 ; </li></ul><ul><li>i.h.dh = r ; </li></ul><ul><li>i.h.dl = c ; </li></ul><ul><li>int86 ( 16, &i, &o ) ; </li></ul><ul><li>} </li></ul>
  44. 44. <ul><li>void drawbox ( int starty, int startx, int endy, int endx, int color, int shad ) </li></ul><ul><li>{ </li></ul><ul><li>// FUNCTION TO DRAW THE BOX </li></ul><ul><li>// JUST STEP THRU THE FUNCTION USING F7 KEY </li></ul><ul><li>int i, j ; </li></ul><ul><li>if ( starty > endy || startx > endx || color > 7 ) </li></ul><ul><li>return ; </li></ul><ul><li>for ( i = startx ; i < endx ; i ++ ) </li></ul><ul><li>{ </li></ul><ul><li>for ( j = starty ; j < endy ; j ++ ) </li></ul><ul><li>writechar ( ' ', i, j, 0, color ) ; </li></ul><ul><li>writechar ( 219, i + 1, endy, shad, 0 ) ; </li></ul><ul><li>} </li></ul><ul><li>for ( i = endy ; i >= starty + 1 ; i -- ) </li></ul><ul><li>{ </li></ul><ul><li>writechar ( 219, endx, i, shad, 0 ) ; </li></ul><ul><li>writechar ( 219, endx + 1, i, shad, 0 ) ; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  45. 45. <ul><li>void writechar(char ch,int row,int col,int fore, int back) </li></ul><ul><li>{ </li></ul><ul><li>* ( scr + col * 160 + row * 2 ) = ch ; </li></ul><ul><li>* ( scr + col * 160 + row * 2 + 1 ) = back * 16 + fore ; </li></ul><ul><li>return ; </li></ul><ul><li>} </li></ul><ul><li>void doneby() </li></ul><ul><li>{ </li></ul><ul><li>int i,j,z,c; </li></ul><ul><li>int gd=DETECT,gm; </li></ul><ul><li>initgraph(&gd,&gm,&quot;..gi&quot;); </li></ul><ul><li>x_center = 320, y_center = 200; </li></ul><ul><li>rad=100; </li></ul><ul><li>setcolor(13); </li></ul><ul><li>line(40,70,590,70); </li></ul><ul><li>setcolor(2); </li></ul><ul><li>rectangle(50,340,590,420); </li></ul><ul><li>setcolor(10); </li></ul>
  46. 46. <ul><li>settextstyle(5,0,5); </li></ul><ul><li>outtextxy(55,345,“IT&quot;); </li></ul><ul><li>settextstyle(4,0,3); </li></ul><ul><li>for(i=1;i<=640;i++) </li></ul><ul><li>{ </li></ul><ul><li>setcolor(9); </li></ul><ul><li>line(i,20,i,20); </li></ul><ul><li>line(i,30,i,30); </li></ul><ul><li>delay(1); </li></ul><ul><li>} </li></ul><ul><li>for(j=10;j<=460;j++) </li></ul><ul><li>{ </li></ul><ul><li>setcolor(9); </li></ul><ul><li>line(610,j,610,j); </li></ul><ul><li>line(620,j,620,j); </li></ul><ul><li>delay(1); </li></ul><ul><li>} </li></ul><ul><li>for( z=640;z>=1;z--) { </li></ul><ul><li>line(z,435,z,435); </li></ul><ul><li>line(z,445,z,445); </li></ul><ul><li>delay(1); </li></ul><ul><li>} </li></ul><ul><li>for( c=460;c>=10;c--) </li></ul><ul><li>{ </li></ul><ul><li>setcolor(9); </li></ul><ul><li>line(20,c,20,c); </li></ul><ul><li>line(30,c,30,c); </li></ul><ul><li>delay(1); </li></ul><ul><li>} </li></ul>
  47. 47. <ul><li>for ( i = 0; i < 10; i++ ) </li></ul><ul><li>{ </li></ul><ul><li> p[i] = x_center + rad * cos(36*i*3.14159/180); </li></ul><ul><li> q[i] = y_center + rad * sin(36*i*3.14159/180); </li></ul><ul><li>} </li></ul><ul><li>for ( i = 0; i < 10; i++ ) </li></ul><ul><li>{ </li></ul><ul><li>for ( j = 0; j < 10; j++ ) </li></ul><ul><li>{ </li></ul><ul><li>setcolor(14); </li></ul><ul><li>line(p[i],q[i],p[j],q[j]); </li></ul><ul><li>delay(25); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>delay(500); </li></ul><ul><li>closegraph(); </li></ul><ul><li>error_mesg(); </li></ul><ul><li>outtextxy(250,210, &quot;Thank You&quot;); </li></ul><ul><li>gotoxy(50,24); </li></ul><ul><li>printf( &quot;Press Any Key To Exit&quot;); </li></ul><ul><li>getch(); </li></ul><ul><li>} </li></ul>
  48. 48. <ul><li>void fill_poly(int x1,int y1,int x2,int y2,int color,int style) </li></ul><ul><li>{ </li></ul><ul><li>int poly[8],i; </li></ul><ul><li>poly[0] = x1; </li></ul><ul><li>poly[1] = y1; </li></ul><ul><li>poly[2] = x2; </li></ul><ul><li>poly[3] = y1; </li></ul><ul><li>poly[4] = x2; </li></ul><ul><li>poly[5] = y2; </li></ul><ul><li>poly[6] = x1; </li></ul><ul><li>poly[7] = y2; </li></ul><ul><li>setfillstyle(style,color); </li></ul><ul><li>setcolor(color); </li></ul><ul><li>fillpoly(4, poly); </li></ul><ul><li>} </li></ul>
  49. 49. <ul><li>void background() </li></ul><ul><li>{ </li></ul><ul><li>int gd=DETECT,gm; </li></ul><ul><li>initgraph(&gd,&gm,&quot;..gi&quot;); </li></ul><ul><li>fill_poly(0,20,getmaxx(),40,11,11); </li></ul><ul><li>fill_poly(getmaxx()-40,0,getmaxx()-20,getmaxy(),11,11); </li></ul><ul><li>fill_poly(0,getmaxy()-40,getmaxx(),getmaxy()-20,11,11); </li></ul><ul><li>fill_poly(20,0,40,getmaxy(),11,11); </li></ul><ul><li>} </li></ul><ul><li>void first_screen() </li></ul><ul><li>{ </li></ul><ul><li>int i,j,k; </li></ul><ul><li>fill_poly(125,50,500,100,12,10); </li></ul><ul><li>settextstyle(10, HORIZ_DIR, 3); </li></ul><ul><li>setcolor(10); </li></ul>
  50. 50. <ul><li>outtextxy(135,50, &quot;N-Queen's Problem&quot;); </li></ul><ul><li>fill_poly(125,300,500,350,12,10); </li></ul><ul><li>settextstyle(7, HORIZ_DIR, 3); </li></ul><ul><li>setcolor(11); </li></ul><ul><li>outtextxy(135,300, &quot;N-Queen's Problem&quot;); </li></ul><ul><li>fill_poly(50,50,100,350,12,10); </li></ul><ul><li>settextstyle(8, 1, 3); </li></ul><ul><li>setcolor(12); </li></ul><ul><li>outtextxy(50,55, &quot;N-Queen's Problem&quot;); </li></ul><ul><li>fill_poly(525,50,575,350,12,10); </li></ul><ul><li>settextstyle(5, 1, 3); </li></ul><ul><li>setcolor(13); </li></ul><ul><li>outtextxy(525,50, &quot;N-Queen's Problem&quot;); </li></ul><ul><li>gotoxy(50,25); </li></ul><ul><li>printf(&quot;Press any key to continue&quot;); </li></ul><ul><li>for ( i = 0; i < 10; i++ ) </li></ul><ul><li>{ </li></ul><ul><li>p[i] = x_center + rad * cos(36*i*3.14159/180); </li></ul><ul><li>q[i] = y_center + rad * sin(36*i*3.14159/180); </li></ul><ul><li>} </li></ul><ul><li>for ( i = 0; i < 10; i++ ) </li></ul><ul><li>{ </li></ul><ul><li>for ( j = 0; j < 10; j++ ) </li></ul><ul><li>{ </li></ul><ul><li>setcolor(14); </li></ul><ul><li>line(p[i],q[i],p[j],q[j]); </li></ul><ul><li>delay(50); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>getch(); } </li></ul>
  51. 51. <ul><li>void initmouse(void) </li></ul><ul><li>{ </li></ul><ul><li>iRow = 0,iCol = 0,iStatus = 0; </li></ul><ul><li>asm{ </li></ul><ul><li>mov ax,0; </li></ul><ul><li>int 0x33; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>void yesmouse(void) </li></ul><ul><li>{ </li></ul><ul><li>asm{ </li></ul><ul><li> mov ax,1; </li></ul><ul><li> int 0x33; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>void nomouse(void) </li></ul><ul><li>{ </li></ul><ul><li>asm{ </li></ul><ul><li> mov ax,2; </li></ul><ul><li> int 0x33; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  52. 52. <ul><li>void mouse(void) </li></ul><ul><li>{ </li></ul><ul><li> asm{ </li></ul><ul><li> mov ax,3; </li></ul><ul><li> int 0x33; </li></ul><ul><li> mov iRow,dx; </li></ul><ul><li> mov iCol,cx; </li></ul><ul><li> mov iStatus,bx; </li></ul><ul><li> } </li></ul><ul><li>} </li></ul><ul><li>void limmouse(int iMinX,int iMinY,int iMaxX,int iMaxY) </li></ul><ul><li>{ </li></ul><ul><li> yesmouse(); </li></ul><ul><li> asm{ </li></ul><ul><li> mov ax,7 </li></ul><ul><li> mov cx,iMinX </li></ul><ul><li> mov dx,iMaxX </li></ul><ul><li> int 0x33 </li></ul><ul><li> } </li></ul><ul><li> asm{ </li></ul><ul><li> mov ax,8 </li></ul><ul><li> mov cx,iMinY </li></ul><ul><li> mov dx,iMaxY </li></ul><ul><li> int 0x33 </li></ul><ul><li> } } </li></ul>
  53. 53. <ul><li>void draw_chess_board() </li></ul><ul><li>{ </li></ul><ul><li> int color1,color2,poly[8],i,j; </li></ul><ul><li> x=0;y=0; </li></ul><ul><li> color1=1; </li></ul><ul><li> color2=0; </li></ul><ul><li> for(i=0;i<size;i++) </li></ul><ul><li> { </li></ul><ul><li>color1=color2; </li></ul><ul><li>for(j=0;j<size;j++) </li></ul><ul><li>{ </li></ul><ul><li> if(color1==1) </li></ul><ul><li> color1=0; </li></ul><ul><li> else if(color1==0) </li></ul><ul><li>color1=1; </li></ul>
  54. 54. <ul><li>setcolor(2); </li></ul><ul><li> rectangle(x,y,x+(getmaxy()/size),y+(getmaxy()/size)); </li></ul><ul><li> poly[0] = x; </li></ul><ul><li> poly[1] = y; </li></ul><ul><li> poly[4] = x+(getmaxy()/size); </li></ul><ul><li> poly[5] = y+(getmaxy()/size); </li></ul><ul><li> poly[2] = x+(getmaxy()/size); </li></ul><ul><li> poly[3] = y; </li></ul><ul><li> poly[6] = x; </li></ul><ul><li> poly[7] = y+(getmaxy()/size); </li></ul><ul><li> setcolor(2); </li></ul><ul><li> if(color1!=0) </li></ul><ul><li> { </li></ul><ul><li> setfillstyle(1,color1); </li></ul><ul><li> fillpoly(4,poly); </li></ul><ul><li> x=x+getmaxy()/size; </li></ul><ul><li> } </li></ul><ul><li> else </li></ul><ul><li> { </li></ul><ul><li>rectangle(x,y,x+getmaxy()/size,getmaxy()/size); </li></ul><ul><li>x=x+getmaxy()/size; </li></ul><ul><li> } </li></ul><ul><li>} </li></ul><ul><li>if(color2==1) </li></ul><ul><li> color2=0; </li></ul><ul><li>else if(color2==0) </li></ul><ul><li>color2=1; </li></ul><ul><li>x=0; </li></ul><ul><li>y=y+getmaxy()/size; </li></ul><ul><li> } </li></ul><ul><li>} </li></ul>
  55. 55. <ul><li>void result() </li></ul><ul><li>{ </li></ul><ul><li> int gd=DETECT,gm,count,i,j; </li></ul><ul><li> initgraph(&gd,&gm,&quot;..gi&quot;); </li></ul><ul><li> draw_chess_board(); </li></ul><ul><li> settextstyle(3,0,4); </li></ul><ul><li> setcolor(5); </li></ul><ul><li> outtextxy(500,5,&quot;Solution&quot;); </li></ul><ul><li> outtextxy(500,50,&quot;Found&quot;); </li></ul><ul><li> setcolor(2); </li></ul><ul><li> rectangle(495,150,getmaxx(),479); </li></ul><ul><li> setcolor(15); </li></ul><ul><li> settextstyle(1,0,1); </li></ul><ul><li> outtextxy(500,200,&quot;This Queen Is&quot;); </li></ul><ul><li> outtextxy(500,220,&quot;Placed By User&quot;); </li></ul><ul><li> setcolor(4); </li></ul><ul><li> setfillstyle(10,4); </li></ul><ul><li> fillellipse(550,180,20,20); </li></ul>
  56. 56. <ul><li>setcolor(15); </li></ul><ul><li> outtextxy(500,300,&quot;These Queens&quot;); </li></ul><ul><li> outtextxy(500,320,&quot;Are Placed&quot;); </li></ul><ul><li> outtextxy(500,340,&quot;According to&quot;); </li></ul><ul><li> outtextxy(500,360,&quot;Queen Placed&quot;); </li></ul><ul><li> outtextxy(500,380,&quot;By User&quot;); </li></ul><ul><li> setcolor(6); </li></ul><ul><li> setfillstyle(9, 6); </li></ul><ul><li> fillellipse(550,280,20,20); </li></ul><ul><li> x=y=((getmaxy()/size)/2); </li></ul><ul><li> for(i=0;i<size;i++) </li></ul><ul><li> { </li></ul><ul><li> x=((getmaxy()/size)/2); </li></ul><ul><li>for(j=0;j<size;j++) </li></ul><ul><li>{ </li></ul><ul><li> if(chess[i][j]==(i+50)) </li></ul><ul><li> { </li></ul><ul><li> if(i==placed_row) </li></ul><ul><li> { </li></ul><ul><li>setcolor(4); </li></ul><ul><li>setfillstyle(10, 4); </li></ul><ul><li> } </li></ul><ul><li> else </li></ul><ul><li> { </li></ul><ul><li>setcolor(6); </li></ul><ul><li>setfillstyle(9, 6); </li></ul><ul><li> } </li></ul><ul><li> fillellipse(x,y,radiusx,radiusy); </li></ul><ul><li> } </li></ul><ul><li> x=x+((getmaxy()/size)); </li></ul><ul><li>} </li></ul><ul><li>y=y+((getmaxy()/size)); </li></ul><ul><li> } </li></ul><ul><li> getch(); </li></ul><ul><li> closegraph(); </li></ul><ul><li>} </li></ul>
  57. 57. <ul><li>void erase() </li></ul><ul><li>{ </li></ul><ul><li> int pixel; </li></ul><ul><li> pixel=getpixel(x+radiusx+1,y); </li></ul><ul><li> setcolor(pixel); </li></ul><ul><li> setfillstyle(1,pixel); </li></ul><ul><li> fillellipse(x,y,radiusx,radiusy); </li></ul><ul><li>} </li></ul><ul><li>void drawcircle() </li></ul><ul><li>{ </li></ul><ul><li> setcolor(4); </li></ul><ul><li> setfillstyle(10,4); </li></ul><ul><li> fillellipse(x,y,radiusx,radiusy); </li></ul><ul><li>} </li></ul><ul><li>int search_rowcol() </li></ul><ul><li>{ </li></ul><ul><li> y=0; </li></ul><ul><li> for(ro=0;ro<size;ro++) </li></ul><ul><li> { </li></ul><ul><li>x=0; </li></ul><ul><li>for(co=0;co<size;co++) </li></ul><ul><li>{ </li></ul><ul><li>if(x<iCol && iCol<(x+479/size) && y<iRow && iRow<(y+479/size)) </li></ul><ul><li>{ </li></ul><ul><li>return 1; </li></ul><ul><li>} </li></ul><ul><li>x=x+(479/size); </li></ul><ul><li> } </li></ul>
  58. 58. <ul><li>y=y+(479/size); </li></ul><ul><li> } </li></ul><ul><li> return 0; </li></ul><ul><li>} </li></ul><ul><li>void acceptbymouse() </li></ul><ul><li>{ </li></ul><ul><li>int prevx,prevy,break_flag,pressed,valid; </li></ul><ul><li>int gd=DETECT,gm; </li></ul><ul><li>initgraph(&gd,&gm,&quot;..gi&quot;); </li></ul><ul><li>draw_chess_board(); </li></ul><ul><li>initmouse(); </li></ul><ul><li>limmouse(0,0,getmaxx()-50,getmaxy()); </li></ul><ul><li>yesmouse(); </li></ul><ul><li>fill_poly(495,15,605,45,11,1); </li></ul><ul><li>fill_poly(500,20,600,40,5,1); </li></ul><ul><li>setcolor(14); </li></ul><ul><li>settextstyle(5,0,3); </li></ul><ul><li>outtextxy(525,12,&quot;Place&quot;); </li></ul><ul><li> setcolor(15); </li></ul><ul><li> settextstyle(1,0,3); </li></ul><ul><li> outtextxy(500,100,&quot;To Place&quot;); </li></ul><ul><li> outtextxy(500,120,&quot;A Queen&quot;); </li></ul><ul><li> outtextxy(500,140,&quot;LeftClick&quot;); </li></ul><ul><li> outtextxy(500,160,&quot;On Button&quot;); </li></ul><ul><li> outtextxy(500,180,&quot;'Placed' &quot;); </li></ul>
  59. 59. <ul><li>while(1) </li></ul><ul><li>{ </li></ul><ul><li>mouse(); </li></ul><ul><li>if(iStatus==1 && 500<=iCol &&iCol<=605 && 15<=iRow &&iRow<=40) </li></ul><ul><li>{ </li></ul><ul><li>nomouse(); </li></ul><ul><li>fill_poly(495,15,605,50,0,1); </li></ul><ul><li>break; </li></ul><ul><li>} </li></ul><ul><li> } </li></ul><ul><li> prevx=0;prevy=0; </li></ul><ul><li> fill_poly(500,0,getmaxx(),getmaxy(),0,1); </li></ul><ul><li> setcolor(15); </li></ul><ul><li> settextstyle(1,0,3); </li></ul><ul><li> outtextxy(500,100,&quot;To Place&quot;); </li></ul><ul><li> outtextxy(500,120,&quot;A Queen&quot;); </li></ul><ul><li> outtextxy(500,140,&quot;RightClick&quot;); </li></ul><ul><li> outtextxy(500,160,&quot;On Proper&quot;); </li></ul><ul><li> outtextxy(500,180,&quot;Place&quot;); </li></ul>
  60. 60. <ul><li>while(1) </li></ul><ul><li> { </li></ul><ul><li>yesmouse(); </li></ul><ul><li>mouse(); </li></ul><ul><li>if(iStatus==2) </li></ul><ul><li>{ </li></ul><ul><li> break; </li></ul><ul><li>} </li></ul><ul><li>valid=search_rowcol(); </li></ul><ul><li>if(valid==1) </li></ul><ul><li>{ </li></ul><ul><li> if(prevx<iCol && iCol<(prevx+479/size) && prevy<iRow && </li></ul><ul><li>iRow<(prevy+479/size)) </li></ul><ul><li> { </li></ul><ul><li>nomouse(); </li></ul><ul><li>setcolor(15); </li></ul><ul><li>prevx=x;prevy=y; </li></ul><ul><li>rectangle(x,y,x+(479/size),y+(479/size)); </li></ul><ul><li> } </li></ul><ul><li>else </li></ul><ul><li> { </li></ul><ul><li>setcolor(2); </li></ul><ul><li>rectangle(prevx,prevy,prevx+(479/size),prevy+(479/size)); </li></ul><ul><li>nomouse(); </li></ul><ul><li>setcolor(15); </li></ul><ul><li>prevx=x;prevy=y; </li></ul><ul><li>rectangle(x,y,x+(479/size),y+(479/size)); </li></ul><ul><li> } </li></ul><ul><li> yesmouse(); </li></ul><ul><li>} </li></ul><ul><li> } </li></ul><ul><li> nomouse(); </li></ul><ul><li> x=x+(479/size)/2; y=y+(479/size)/2; </li></ul><ul><li> drawcircle(); </li></ul><ul><li> placed_row=ro; </li></ul><ul><li> placequeen(ro,co,0); </li></ul><ul><li> delay(1000); </li></ul><ul><li> closegraph(); </li></ul><ul><li>} </li></ul>
  61. 61. <ul><li>void acceptbykeyboard() </li></ul><ul><li>{ </li></ul><ul><li> int gd=DETECT,gm,c,i,j; </li></ul><ul><li> initgraph(&gd,&gm,&quot;..gi&quot;); </li></ul><ul><li> draw_chess_board(); </li></ul><ul><li> x=(getmaxy()/size)/2; </li></ul><ul><li> y=(getmaxy()/size)/2; </li></ul><ul><li> i=0;j=0; </li></ul><ul><li> drawcircle(); </li></ul><ul><li> do </li></ul><ul><li> { </li></ul><ul><li> c=getch(); </li></ul><ul><li> if(c==0) </li></ul><ul><li> c=getch(); </li></ul><ul><li> if(c==72 && y-(getmaxy()/size)>0) </li></ul><ul><li> { </li></ul><ul><li> erase(); </li></ul><ul><li> y=y-(getmaxy()/size); </li></ul><ul><li> drawcircle(); </li></ul><ul><li> i--; </li></ul><ul><li> } </li></ul><ul><li> else </li></ul><ul><li>if(c==80 && y+(getmaxy()/size)<479) </li></ul><ul><li>{ </li></ul><ul><li> erase(); </li></ul><ul><li> y=y+(getmaxy()/size); </li></ul><ul><li> drawcircle(); </li></ul><ul><li> i++; </li></ul><ul><li>} </li></ul><ul><li>else </li></ul><ul><li>if(c==75&& x-(getmaxy()/size)>0) </li></ul><ul><li>{ </li></ul><ul><li> erase(); </li></ul><ul><li> x=x-(getmaxy()/size); </li></ul><ul><li> drawcircle(); </li></ul><ul><li> j--; </li></ul><ul><li>} </li></ul><ul><li>else </li></ul><ul><li>if(c==77 &&x+(getmaxy()/size)<479) </li></ul><ul><li>{ </li></ul><ul><li> erase(); </li></ul><ul><li> x=x+(getmaxy()/size); </li></ul><ul><li> drawcircle(); </li></ul><ul><li> j++; </li></ul><ul><li>} </li></ul><ul><li>if(c==13) </li></ul><ul><li>{ </li></ul><ul><li> drawcircle(); </li></ul><ul><li> placed_row=i; </li></ul><ul><li> placequeen(i,j,0); </li></ul><ul><li> c=27; </li></ul><ul><li>} </li></ul><ul><li> }while(c!=27); </li></ul><ul><li> closegraph(); </li></ul><ul><li>} </li></ul>
  62. 62. <ul><li> if(j1==size) </li></ul><ul><li> { </li></ul><ul><li> if(i-1!=placed_row) </li></ul><ul><li> { </li></ul><ul><li> i--; </li></ul><ul><li> row--; </li></ul><ul><li> } </li></ul><ul><li> else </li></ul><ul><li> { </li></ul><ul><li> i=i-2; </li></ul><ul><li> row=row-2; </li></ul><ul><li> } </li></ul><ul><li> for(j=0;j<size;j++) </li></ul><ul><li> { </li></ul><ul><li> if(chess[i][j]==(i+50)) </li></ul><ul><li> break; </li></ul><ul><li> } </li></ul><ul><li> chess[i][j]=-1; </li></ul><ul><li> diagonal_1_check(i,j,-1,i); </li></ul><ul><li> diagonal_2_check(i,j,-1,i); </li></ul><ul><li> column(i,j,-1,i); </li></ul><ul><li> textcolor(0); </li></ul><ul><li> textbackground(0); </li></ul><ul><li> gotoxy(--text_x,25); </li></ul><ul><li> cprintf(&quot; &quot;); </li></ul><ul><li> break_up=placequeen(row,j+1,0); </li></ul><ul><li>} </li></ul><ul><li> } </li></ul><ul><li> return 0; </li></ul><ul><li>} </li></ul><ul><li>int placequeen(int i,int j,int break_up) </li></ul><ul><li>{ </li></ul><ul><li> int j1; </li></ul><ul><li> if(break_up==0) </li></ul><ul><li> { </li></ul><ul><li> count_exceed++; </li></ul><ul><li> if(count_exceed>total_no_of_nodes) </li></ul><ul><li> { </li></ul><ul><li>error_mesg(); </li></ul><ul><li>outtextxy(110,210, &quot;Sorry,Solution Is Not Possible !!&quot;); </li></ul><ul><li>gotoxy(50,24); </li></ul><ul><li>printf( &quot;Press Any Key To Continue&quot;); </li></ul><ul><li>getch(); </li></ul><ul><li>closegraph(); </li></ul><ul><li>return 1; </li></ul><ul><li> } </li></ul><ul><li> for(j1=j;j1<size;j1++) </li></ul><ul><li> { </li></ul><ul><li> if(chess[i][j1]==-1) </li></ul><ul><li> { </li></ul><ul><li> textcolor(3); </li></ul><ul><li> gotoxy(text_x++,25); </li></ul><ul><li> cprintf(&quot;°&quot;); </li></ul><ul><li> chess[i][j1]=(i+50); </li></ul><ul><li> diagonal_1_check(i,j1,i,-1); </li></ul><ul><li> diagonal_2_check(i,j1,i,-1); </li></ul><ul><li> column(i,j1,i,-1); </li></ul><ul><li> break; </li></ul><ul><li> } </li></ul><ul><li> } </li></ul>
  63. 63. <ul><li>void diagonal_1_check(int i1,int j1,int val,int check) </li></ul><ul><li>{ </li></ul><ul><li> int i2,j2; </li></ul><ul><li> i2=i1; </li></ul><ul><li> j2=j1; </li></ul><ul><li> i2--;j2--; </li></ul><ul><li> while(i2>=0&&j2>=0) </li></ul><ul><li> { </li></ul><ul><li> if(check==chess[i2][j2]) </li></ul><ul><li> chess[i2][j2]=val; </li></ul><ul><li> i2--;j2--; </li></ul><ul><li> } </li></ul><ul><li> i2=i1; </li></ul><ul><li> j2=j1; </li></ul><ul><li> i2++;j2++; </li></ul><ul><li> while(i2<size&&j2<size) </li></ul><ul><li> { </li></ul><ul><li> if(check==chess[i2][j2]) </li></ul><ul><li> chess[i2][j2]=val; </li></ul><ul><li> i2++;j2++; </li></ul><ul><li> } </li></ul><ul><li>} </li></ul>
  64. 64. <ul><li>void diagonal_2_check(int i1,int j1,int val,int check) </li></ul><ul><li>{ </li></ul><ul><li>int i2,i3,j2; </li></ul><ul><li> i2=i1; </li></ul><ul><li> j2=j1; </li></ul><ul><li> i2--;j2++; </li></ul><ul><li> while(i2>=0&&j2<size) </li></ul><ul><li> { </li></ul><ul><li> if(check==chess[i2][j2]) </li></ul><ul><li> chess[i2][j2]=val; </li></ul><ul><li> i2--;j2++; </li></ul><ul><li> } </li></ul><ul><li> i2=i1; </li></ul><ul><li> j2=j1; </li></ul><ul><li> i2++;j2--; </li></ul><ul><li> while(i2<size&&j2>=0) </li></ul><ul><li> { </li></ul><ul><li> if(check==chess[i2][j2]) </li></ul><ul><li> chess[i2][j2]=val; </li></ul><ul><li> i2++;j2--; </li></ul><ul><li> } </li></ul><ul><li>} </li></ul>
  65. 65. <ul><li>void column(int i1,int j1,int val,int check) </li></ul><ul><li>{ </li></ul><ul><li> int j2; </li></ul><ul><li> for(j2=0;j2<size;j2++) </li></ul><ul><li> { </li></ul><ul><li> if(chess[i1][j2]==check) </li></ul><ul><li> { </li></ul><ul><li>chess[i1][j2]=val; </li></ul><ul><li> } </li></ul><ul><li> } </li></ul><ul><li> for(j2=0;j2<size;j2++) </li></ul><ul><li> { </li></ul><ul><li> if(chess[j2][j1]==check) </li></ul><ul><li> { </li></ul><ul><li>chess[j2][j1]=val; </li></ul><ul><li> } </li></ul><ul><li> } </li></ul><ul><li>} </li></ul>
  66. 66. <ul><li>if(status==0) </li></ul><ul><li>status=getch(); </li></ul><ul><li>switch(status) </li></ul><ul><li>{ </li></ul><ul><li>case 72:if(choice==1) </li></ul><ul><li>choice=6; </li></ul><ul><li>else </li></ul><ul><li>choice--; </li></ul><ul><li>break; </li></ul><ul><li>case 80:if(choice==6) </li></ul><ul><li>choice=1; </li></ul><ul><li>else </li></ul><ul><li>choice++; </li></ul><ul><li>break; </li></ul><ul><li>case 13: </li></ul><ul><li> if(choice==1) </li></ul><ul><li>instructions(); </li></ul><ul><li> else </li></ul><ul><li> if(choice==2) </li></ul><ul><li> { </li></ul><ul><li>acceptsize(); </li></ul><ul><li> } </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int i,j,choice,status,breakup,b[50]; </li></ul><ul><li>background(); </li></ul><ul><li>// first_screen(); </li></ul><ul><li>closegraph(); </li></ul><ul><li>loadprog(); </li></ul><ul><li>about_prog(); </li></ul><ul><li>size=-1; </li></ul><ul><li>choice=1; </li></ul><ul><li>do </li></ul><ul><li>{ </li></ul><ul><li>clrwin ( 0, 0, 25, 80, 0, 1 ) ; </li></ul><ul><li>drawbox ( 5, 20, 20, 55, 4, 0 ) ; </li></ul><ul><li>_setcursortype(_NOCURSOR); </li></ul><ul><li>for ( int i = 0 ; i <= 6 ; i ++ ) </li></ul><ul><li>{ </li></ul><ul><li> if ( choice == i ) </li></ul><ul><li> writestring ( menu[i], 20, 7 + 2 * i, 0, 10 ) ; </li></ul><ul><li> else </li></ul><ul><li> writestring ( menu[i], 20, 7 + 2 * i, 10, 4 ) ; </li></ul><ul><li>} </li></ul><ul><li>status=getch(); </li></ul>
  67. 67. <ul><li>else if(choice==6) { </li></ul><ul><li> doneby(); </li></ul><ul><li> exit(0); </li></ul><ul><li> </li></ul><ul><li>else if(size==-1) </li></ul><ul><li> { </li></ul><ul><li>error_mesg(); </li></ul><ul><li>outtextxy(110,210, &quot;First Enter Size Of ChessBoard&quot;); </li></ul><ul><li>gotoxy(50,24); </li></ul><ul><li>printf( &quot;Press Any Key To Continue&quot;); </li></ul><ul><li>getch(); </li></ul><ul><li>closegraph(); </li></ul><ul><li> } </li></ul><ul><li> else </li></ul><ul><li> if(choice==5) </li></ul><ul><li> { </li></ul><ul><li>for(i=0;i<size;i++) </li></ul><ul><li>{ </li></ul><ul><li>b[i]=0; </li></ul><ul><li>} </li></ul><ul><li>exit_p=0; </li></ul><ul><li>cal_positions(b,size,0,0); </li></ul><ul><li> } </li></ul><ul><li>if(status==0) </li></ul><ul><li>status=getch(); </li></ul><ul><li>switch(status) </li></ul><ul><li>{ </li></ul><ul><li>case 72:if(choice==1) </li></ul><ul><li>choice=6; </li></ul><ul><li>else </li></ul><ul><li>choice--; </li></ul><ul><li>break; </li></ul><ul><li>case 80:if(choice==6) </li></ul><ul><li>choice=1; </li></ul><ul><li>else </li></ul><ul><li>choice++; </li></ul><ul><li>break; </li></ul><ul><li>case 13: </li></ul><ul><li> if(choice==1) </li></ul><ul><li>instructions(); </li></ul><ul><li> else </li></ul><ul><li> if(choice==2) </li></ul><ul><li> { </li></ul><ul><li>acceptsize(); } </li></ul>
  68. 68. <ul><li>else if(choice==4||choice==3) </li></ul><ul><li> { </li></ul><ul><li>if(choice==4) </li></ul><ul><li> acceptbykeyboard(); </li></ul><ul><li>else if(choice==3) </li></ul><ul><li> acceptbymouse(); </li></ul><ul><li> gotoxy(30,13); </li></ul><ul><li> textcolor(3); </li></ul><ul><li> textbackground(1); </li></ul><ul><li> printf(&quot;Placing Please Wait........&quot;); </li></ul><ul><li> row=0; </li></ul><ul><li> count_exceed=0; </li></ul><ul><li> breakup=0; </li></ul><ul><li>while(row!=size &&breakup==0) </li></ul><ul><li> { </li></ul><ul><li> if(row==placed_row) </li></ul><ul><li> row++; </li></ul><ul><li> if(row==size) </li></ul><ul><li> break; </li></ul><ul><li> breakup=placequeen(row,0,0); </li></ul><ul><li> row++; </li></ul><ul><li> } </li></ul><ul><li> if(breakup==0) </li></ul><ul><li> { </li></ul><ul><li> for(i=text_x;i<79;i++) </li></ul><ul><li> { </li></ul><ul><li> textcolor(2); </li></ul><ul><li> cprintf(&quot;°&quot;); </li></ul><ul><li> delay(30); </li></ul><ul><li> } </li></ul><ul><li> result(); </li></ul><ul><li> } </li></ul>
  69. 69. <ul><li>} </li></ul><ul><li> break; </li></ul><ul><li>} </li></ul><ul><li> }while(1); </li></ul><ul><li> } </li></ul>
  70. 70. END OF THE SOURCE CODE
  71. 71. FLOW CHART START SET BACKGROUND() LINK THE BGI GRAPHIC FILE WITH USER SCREEN A
  72. 72. READ SIZE OF CHESS BOARD A IF SIZE IS BETWEEN 4-8 PLACE-QUEEN () B YES EXIT(0) NO
  73. 73. DISPLAY INSTRUCTION TO PLACE B DISPLAY THE RESULT IF EXIT CLOSE GRAPH() YES C
  74. 74. C STOP EXIT(0)
  75. 75. SCREEN SHOT
  76. 76. CONCLUSION <ul><li>BROAD CONCLUSION </li></ul><ul><li>Faster move,intelligent decisions in moving the queens are the promises of standardising on interests of the players to play this puzzle. </li></ul><ul><li>Finally we conclude that our project will be satisfying the players in all the aspects. </li></ul>
  77. 77. <ul><li>Future Scope and Enhancement </li></ul><ul><li>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. </li></ul>
  78. 78. REFERENCES <ul><li>www.howstuffworks.com </li></ul><ul><li>www.wikipedia.org </li></ul><ul><li>www.google.com </li></ul><ul><li>“ C++ Complete reference” by Schildt </li></ul><ul><li>C++ programs by Varalakshmi </li></ul><ul><li>Keyhtmldos books online </li></ul>

×