ma project

78
INFO INSTITUTE OF INFO INSTITUTE OF ENGINEERING ENGINEERING WELCOMES WELCOMES U U ALL ALL

Upload: aisu

Post on 21-Dec-2014

1.123 views

Category:

Business


3 download

DESCRIPTION

 

TRANSCRIPT

Page 1: ma project

INFO INSTITUTE OF INFO INSTITUTE OF ENGINEERING ENGINEERING

WELCOMES WELCOMES UU

ALLALL

Page 2: ma project

EIGHT QUEENS PROBLEMEIGHT QUEENS PROBLEM

Page 3: ma project

EIGHT-QUEENS PROBLEMEIGHT-QUEENS PROBLEM

Project Report submitted byProject Report submitted by

V.J.Aiswaryadevi (07BIT03),V.J.Aiswaryadevi (07BIT03), S.Dhivya S.Dhivya (07BIT15), (07BIT15), M.Kumuthanandhini (07BIT23)M.Kumuthanandhini (07BIT23)

Page 4: ma project

OBJECTIVEOBJECTIVE

In partial fulfillment of the In partial fulfillment of the requirements for the award requirements for the award of degree of Bachelor of of degree of Bachelor of Engineering in Information Engineering in Information Technology in Info Institute Technology in Info Institute of Engineering of Engineering

Page 5: ma project

Under the guidance of Under the guidance of

Lecturers,Department of Lecturers,Department of Information TechnologyInformation Technology

Department of Information Department of Information TechnologyTechnology

Info Institute of Engineering Info Institute of Engineering

Coimbatore -641101Coimbatore -641101

BATCH 2007-2011BATCH 2007-2011

Page 6: ma project

ACKNOWLEDGEMENTACKNOWLEDGEMENT

First and foremost we acknowledge First and foremost we acknowledge the abundant grace and presence of the abundant grace and presence of our LORD GOD ALMIGHTY our LORD GOD ALMIGHTY throughout the project work and its throughout the project work and its successful completion.successful completion.

We thank our beloved founder late We thank our beloved founder late Shri . K.K.Veluchamy ,B.E .for their Shri . K.K.Veluchamy ,B.E .for their unceasing prayers for the student unceasing prayers for the student community community

Page 7: ma project

ACKNOWLEDGEMENTACKNOWLEDGEMENT

And we thank all our beloved and And we thank all our beloved and respectful Dharbari charitable trustees respectful Dharbari charitable trustees for their grate source of inspiration for their grate source of inspiration during the project ,encouragement in during the project ,encouragement in the project.the project.

We wish to thank our Information We wish to thank our Information Technology (IT) department lecturers Technology (IT) department lecturers for their valuable guidance.We would for their valuable guidance.We would like to thank all other staffs for their co-like to thank all other staffs for their co-operation with us during our project.operation with us during our project.

Page 8: ma project

ACKNOWLEDGEMENTACKNOWLEDGEMENT

Last but not least we cannot fail to Last but not least we cannot fail to acknowledge the support and acknowledge the support and encouragement provided by our encouragement provided by our parents,friends and the staffs of parents,friends and the staffs of Department of Information Department of Information Technology. Technology.

Page 9: ma project

SYNOPSISSYNOPSIS

The project eight queens is a puzzle The project eight queens is a puzzle game, that deals with the simple game, that deals with the simple alignment or placing of queens alignment or placing of queens without interfacing each other without interfacing each other diagonally,horizontally or vertically.It diagonally,horizontally or vertically.It is also called as one of the Chess is also called as one of the Chess board games. board games.

Page 10: ma project

INDEXINDEX

1 INTRODUCTION1 INTRODUCTION PurposePurpose Intended Audience & Reading Intended Audience & Reading

SuggestionsSuggestions Project ScopeProject Scope Platform OverviewPlatform Overview

Page 11: ma project

INDEXINDEX

2 PROJECT OVERVIEW2 PROJECT OVERVIEW Description of 8-Queens algorithmDescription of 8-Queens algorithm Operating environmentOperating environment Source code 22-70Source code 22-70

Page 12: ma project

INDEXINDEX

3 MODULE DESCRIPTION3 MODULE DESCRIPTION Block diagramBlock diagram Screen shotsScreen shots

Page 13: ma project

CONCLUSION CONCLUSION

Broad conclusion Broad conclusion Future Scope and Enhancement Future Scope and Enhancement

Page 14: ma project

INTRODUCTIONINTRODUCTION

1.1 Purpose1.1 Purpose Eight queens Eight queens is the chess board is the chess board

puzzle game which gives enough puzzle game which gives enough entertainment. Besides being an entertainment. Besides being an amusing puzzle this problem is amusing puzzle this problem is interesting because kids love it and it's interesting because kids love it and it's a great teaching tool in the upper a great teaching tool in the upper grades of Elementary School. It also grades of Elementary School. It also provides great programming exercises. provides great programming exercises.

Page 15: ma project

1.21.2 Intended Audience and reading Intended Audience and reading suggestionssuggestions

1.2.1Intended users – 1.2.1Intended users – All players and All players and developersdevelopers

1.2.2 Description – 1.2.2 Description – The rest of this document The rest of this document contains the technical study of what the project contains the technical study of what the project is actually about.It is a general view into the is actually about.It is a general view into the planned working of the system through planned working of the system through sequence diagram and functional and non-sequence diagram and functional and non-functional requirements of the system. functional requirements of the system.

1.2.3 Developer –1.2.3 Developer – is aware of the system to be is aware of the system to be

developed so they could start their reading developed so they could start their reading from system features and follow on.from system features and follow on.

Page 16: ma project

1.3 Project Scope1.3 Project Scope

This project is to solve the queens This project is to solve the queens puzzle with different solutions.Here puzzle with different solutions.Here user and system interaction is user and system interaction is established. The dynamic reports are established. The dynamic reports are available for the players.If there is no available for the players.If there is no solution,the project will display the solution,the project will display the message “there is no solution”.In chess message “there is no solution”.In chess board, a queen can move as far as she board, a queen can move as far as she pleases, horizontally, vertically, or pleases, horizontally, vertically, or diagonally. A chess board has 8 rows diagonally. A chess board has 8 rows and 8 columns. The standard 8 by 8 and 8 columns. The standard 8 by 8 Queen's problem asks how to place 8 Queen's problem asks how to place 8 queens on an ordinary chess board so queens on an ordinary chess board so that none of them can hit any other in that none of them can hit any other in one move is the basic reveal that we one move is the basic reveal that we get from this project.get from this project.

Page 17: ma project

1.3 Project Scope1.3 Project Scope

An obvious modification of the 8 by 8 An obvious modification of the 8 by 8 problem is to consider an problem is to consider an NN by by NN "chess "chess board" and ask if one can place board" and ask if one can place NN queens on such a board. It's pretty easy queens on such a board. It's pretty easy to see that this is impossible if to see that this is impossible if NN is 2 or is 2 or 3, and it's reasonably straightforward to 3, and it's reasonably straightforward to find solutions when find solutions when NN is 4, 5, 6, or 7. is 4, 5, 6, or 7.

Page 18: ma project

1.4 Platform Overview 1.4 Platform Overview

1.4.1 Model:1.4.1 Model:

The platform used here is Windows The platform used here is Windows xp.This project is done using the C++ xp.This project is done using the C++ software in its Integrated software in its Integrated Development environment(IDE).This Development environment(IDE).This project is platform dependent. It is project is platform dependent. It is developed using more graph concepts developed using more graph concepts like combinatorial concepts.Simple like combinatorial concepts.Simple concepts are used for developing this concepts are used for developing this

Page 19: ma project

2-PROJECT OVERVIEW2-PROJECT OVERVIEW2.1 Description of Eight Queens 2.1 Description of Eight Queens

Product FeaturesProduct Features

Using the Control PanelUsing the Control Panel Let's run through the rows of the Control Let's run through the rows of the Control

Panel: Panel: Row 1.Row 1.

Naturally, the Naturally, the QuitQuit button lets you quit the button lets you quit the program. You can also exit by clicking again program. You can also exit by clicking again on the applet, by typing 'x', 'X', 'q', or 'Q' in on the applet, by typing 'x', 'X', 'q', or 'Q' in the control window, or by quitting your the control window, or by quitting your browser. You can dismiss a single solution browser. You can dismiss a single solution or the drawing window by typing 'x', 'X', 'q', or the drawing window by typing 'x', 'X', 'q', or 'Q' in the relevant window. or 'Q' in the relevant window.

Page 20: ma project

Row 2.Row 2.

The The redred textfield let's you change the value textfield let's you change the value of of N N , the dimension of the chess board. You , the dimension of the chess board. You can decrease or increase can decrease or increase NN by clicking on by clicking on the "<" Size">" button from 4-8, the "<" Size">" button from 4-8, respectively. respectively.

The The Display MenuDisplay Menu let's you determine the let's you determine the degree of animation on the drawing board. degree of animation on the drawing board. There are four levels, ordered by There are four levels, ordered by decreasing animation and increasing speed: decreasing animation and increasing speed: Place QueenPlace Queen shows queens being shows queens being

moved, and has a ghost queen move from moved, and has a ghost queen move from any queen that can hit the recently any queen that can hit the recently moved queen in the rightmost column. moved queen in the rightmost column.

Page 21: ma project

2.3 Operating Environment2.3 Operating EnvironmentHardware requirementsHardware requirements ProcessorProcessor : Intel Pentium : Intel Pentium

processors, processors, AMD sempron etc., AMD sempron etc.,

MemoryMemory : 512MB – 1GB RAM: 512MB – 1GB RAM Hard disk Hard disk : 60-240GB hard : 60-240GB hard

disk(Even disk(Even more than more than this)this)

MonitorMonitor : Any compatible: Any compatible KeyboardKeyboard : Any compatible: Any compatibleSoftware requirementsSoftware requirements Operating SystemOperating System : Windows XP/Vista: Windows XP/Vista Platform Platform : C++: C++

Page 22: ma project

Source CodeSource Code

Code :Code :/* modified final*//* modified final*/#include<stdio.h>#include<stdio.h>#include<conio.h>#include<conio.h>#include<graphics.h>#include<graphics.h>#include<dos.h>#include<dos.h>#include<math.h>#include<math.h>#include<process.h>#include<process.h>

Page 23: ma project

//Functions used//Functions used

void about_prog();void about_prog();

void gotorc ( int, int ) ;void gotorc ( int, int ) ;

void mainmenu ( ) ;void mainmenu ( ) ;

void drawbox ( int, int, int, int, int, int ) ;void drawbox ( int, int, int, int, int, int ) ;

void writechar ( char, int, int, int, int ) ;void writechar ( char, int, int, int, int ) ;

void writestring ( char*, int, int, int, int, int = void writestring ( char*, int, int, int, int, int = 0 ) ;0 ) ;

void clrwin ( int=0, int=0, int=25, int=80, void clrwin ( int=0, int=0, int=25, int=80, int=7, int=0 ) ;int=7, int=0 ) ;

void rules ( ) ;void rules ( ) ;

void about ( ) ;void about ( ) ;

void quit ( ) ;void quit ( ) ;

void back ( ) ;void back ( ) ;

Page 24: ma project

void initmouse(void);void initmouse(void);void yesmouse(void);void yesmouse(void);void nomouse(void);void nomouse(void);void mouse(void);void mouse(void);void limmouse(int,int,int,int);void limmouse(int,int,int,int);void background();void background();void first_screen();void first_screen();void loadprog();void loadprog();void acceptsize();void acceptsize();void error_mesg();void error_mesg();

Page 25: ma project

int possible_results();int possible_results(); int search_rowcol();int search_rowcol();

void doneby();void doneby();void fill_poly(int,int,int,int,int,int);void fill_poly(int,int,int,int,int,int);void draw_chess_board();void draw_chess_board();void erase();void erase();void drawcircle();void drawcircle();void acceptbymouse();void acceptbymouse();void acceptbykeyboard();void acceptbykeyboard();int placequeen(int,int,int);int placequeen(int,int,int);void diagonal_1_check(int,int,int,int);void diagonal_1_check(int,int,int,int);void diagonal_2_check(int,int,int,int);void diagonal_2_check(int,int,int,int);

void column(int,int,int,int);void column(int,int,int,int);void result();void result();

Page 26: ma project

////Global VariablesGlobal Variablesint exit_p;int exit_p;int chess[50][50];int chess[50][50];int int placed_row,size,row,col,x,y,radiusx,radiusy,ro,co,text_x=1;placed_row,size,row,col,x,y,radiusx,radiusy,ro,co,text_x=1;int iRow,iCol,iStatus;int iRow,iCol,iStatus;long int total_no_of_nodes,temp;long int total_no_of_nodes,temp;long int count_exceed;long int count_exceed;int x_center = 320, y_center = 200, rad = int x_center = 320, y_center = 200, rad = 100,p[100],q[100];100,p[100],q[100];long int count_num=0;long int count_num=0;union REGS i,o;union REGS i,o;char far *scr=(char far *) 0xB8000000L ; //screen addresschar far *scr=(char far *) 0xB8000000L ; //screen addresschar ch, *menu[]=char ch, *menu[]={{" *** MENU *** "," *** MENU *** "," ^Instructions "," ^Instructions "," ^Enter Size Of ChessBoard "," ^Enter Size Of ChessBoard "," ^Use Mouse To place Queen "," ^Use Mouse To place Queen "," ^USE Keyboard To Place Queen "," ^USE Keyboard To Place Queen "," ^Possible Solutions "," ^Possible Solutions "," ^Exit "" ^Exit "};};

Page 27: ma project

void about_prog()void about_prog()

{{

clrwin ( 0, 0, 25, 80, 0, 3 ) ;clrwin ( 0, 0, 25, 80, 0, 3 ) ;

drawbox ( 2, 2, 22, 75, 0, 8 ) ;drawbox ( 2, 2, 22, 75, 0, 8 ) ;

writestring ( "About Program", 30, 2, 14, writestring ( "About Program", 30, 2, 14, 0 ) ;0 ) ;

writestring ( "* A Classic Combinatorial writestring ( "* A Classic Combinatorial Problem Is Problem Is To Place N-Queens To Place N-Queens on N by N", 3, 4, on N by N", 3, 4,

11, 0) ;11, 0) ;

writestring ( "ChessBoard So That No writestring ( "ChessBoard So That No Two Two 'Attack',that is,so that no 'Attack',that is,so that no two of them two of them ", 5, 6, 11, 0 ) ;", 5, 6, 11, 0 ) ;

Page 28: ma project

writestring ( "are on the same row,column or diagonal.", 5, writestring ( "are on the same row,column or diagonal.", 5, 8, 11, 0 ) ;8, 11, 0 ) ;writestring ( "* This Problem Is Solved By writestring ( "* This Problem Is Solved By 'BackTracking',BackTracking 'BackTracking',BackTracking is a", is a", 3,10,11, 0 ) ;3,10,11, 0 ) ;writestring ( "Algorithmic Strategy.", 5, 12, 15, 0 ) ;writestring ( "Algorithmic Strategy.", 5, 12, 15, 0 ) ;writestring ( "* In This Program You Have To Choose a writestring ( "* In This Program You Have To Choose a Position OnPosition On

ChessBoard For", 3, 14, 12, 0 ) ;ChessBoard For", 3, 14, 12, 0 ) ;writestring ( "a Queen Then The BackTracking Algorithm writestring ( "a Queen Then The BackTracking Algorithm Places All N-1Places All N-1

Queens", 5, 16, 12, 0 ) ;Queens", 5, 16, 12, 0 ) ;writestring ( "On Right Place Satisfing Above Conditions.", writestring ( "On Right Place Satisfing Above Conditions.", 5, 18,12,0 ) ;5, 18,12,0 ) ;writestring ( "* Number Of All Possible Solutions For writestring ( "* Number Of All Possible Solutions For Placed PositionsPlaced Positions

Can Be Viewed.", 3, 18, 13, 0 ) ;Can Be Viewed.", 3, 18, 13, 0 ) ;writestring ( "Press Any Key To Continue", 50, 21, 13, 0 ) ;writestring ( "Press Any Key To Continue", 50, 21, 13, 0 ) ;getch();getch();}}

Page 29: ma project

void error_mesg()void error_mesg(){{

int gd=DETECT,gm;int gd=DETECT,gm;initgraph(&gd,&gm,"..\bgi");initgraph(&gd,&gm,"..\bgi");cleardevice();cleardevice();background();background();fill_poly(100,200,550,250,12,10);fill_poly(100,200,550,250,12,10);settextstyle(8, HORIZ_DIR, 3);settextstyle(8, HORIZ_DIR, 3);setcolor(15);setcolor(15);

}}

Page 30: ma project

void loadprog()void loadprog(){{

int i;int i;_setcursortype(_NOCURSOR);_setcursortype(_NOCURSOR);drawbox ( 10, 30, 13, 50, 2, 0 ) ;drawbox ( 10, 30, 13, 50, 2, 0 ) ;writestring ( "Loading.... ", 32, 11, 0, writestring ( "Loading.... ", 32, 11, 0,

2, 1 ) ;2, 1 ) ;gotoxy(1,25);gotoxy(1,25);textcolor(CYAN);textcolor(CYAN);for(i=0;i<79;i++)for(i=0;i<79;i++){{ cprintf("°");cprintf("°"); delay(20);delay(20);}}

}}

Page 31: ma project

void acceptsize()void acceptsize(){{ int i,j;int i,j; _setcursortype(_NOCURSOR);_setcursortype(_NOCURSOR); clrwin ( 0, 0, 25, 80, 0, 1 ) ;clrwin ( 0, 0, 25, 80, 0, 1 ) ; dodo {{

drawbox ( 10, 20, 14, 65, 2, 0 ) ;drawbox ( 10, 20, 14, 65, 2, 0 ) ; writestring ( "ENTER THE SIZE OF writestring ( "ENTER THE SIZE OF

CHESSBOARD (4 TO 25): ", 22, 12,0, 2, 1 ) ;CHESSBOARD (4 TO 25): ", 22, 12,0, 2, 1 ) ;

_setcursortype(_NORMALCURSOR);_setcursortype(_NORMALCURSOR); gotorc ( 12,61) ;gotorc ( 12,61) ; scanf("%d",&size);scanf("%d",&size); _setcursortype(_NOCURSOR);_setcursortype(_NOCURSOR);

}while(size<4 || size>26);}while(size<4 || size>26);

Page 32: ma project

total_no_of_nodes=0;total_no_of_nodes=0; for(j=0;j<size;j++)for(j=0;j<size;j++) {{

temp=1;temp=1;for(i=0;i<=j;i++)for(i=0;i<=j;i++){{

temp=temp*(size-i);temp=temp*(size-i);}}total_no_of_nodes=total_no_of_nodes+temp;total_no_of_nodes=total_no_of_nodes+temp;

}} //total_no_of_nodes=temp;//total_no_of_nodes=temp; for(i=0;i<size;i++)for(i=0;i<size;i++) {{

for(j=0;j<size;j++)for(j=0;j<size;j++){{

chess[i][j]=-1;chess[i][j]=-1;}}

}} radiusy=((479/size))/2-3;radiusy=((479/size))/2-3; radiusx=((479/size))/2-3;radiusx=((479/size))/2-3;}}

Page 33: ma project

int possible_results()int possible_results(){{

int gd=DETECT,gm,i,j,ex;int gd=DETECT,gm,i,j,ex;char buff[5];char buff[5];initgraph(&gd,&gm,"..\bgi");initgraph(&gd,&gm,"..\bgi");draw_chess_board();draw_chess_board();setcolor(10);setcolor(10);settextstyle(1,0,3);settextstyle(1,0,3);outtextxy(500,100,"Solution");outtextxy(500,100,"Solution");outtextxy(500,120,"Number");outtextxy(500,120,"Number");sprintf(buff,"%d",count_num+1);sprintf(buff,"%d",count_num+1);outtextxy(500,140,buff);outtextxy(500,140,buff);

Page 34: ma project

x=y=((getmaxy()/size)/2);x=y=((getmaxy()/size)/2); for(i=0;i<size;i++)for(i=0;i<size;i++) {{

x=((getmaxy()/size)/2);x=((getmaxy()/size)/2);for(j=0;j<size;j++)for(j=0;j<size;j++){{ if(chess[i][j]==(i+50))if(chess[i][j]==(i+50)) {{

setcolor(6);setcolor(6);setfillstyle(9,6);setfillstyle(9,6);fillellipse(x,y,radiusx,radiusy);fillellipse(x,y,radiusx,radiusy);

}} x=x+((getmaxy()/size));x=x+((getmaxy()/size));

}}y=y+((getmaxy()/size));y=y+((getmaxy()/size));

}}

Page 35: ma project

ex=getch();ex=getch();if(ex==0)if(ex==0)

ex=getch();ex=getch();

if(ex==27)if(ex==27){{

closegraph();closegraph();return 1;return 1;

}}closegraph();closegraph();return 0;return 0;

}}

Page 36: ma project

void cal_positions(int *a,int index,int row,int ptr)void cal_positions(int *a,int index,int row,int ptr){{

int i,j,b[50],k,placed,l,m,remove;int i,j,b[50],k,placed,l,m,remove;if(exit_p==0)if(exit_p==0){{

if(index >= 1)if(index >= 1){{

i=0;i=0;j=1;j=1;k=0;k=0;for(i=1;i<=size;i++)for(i=1;i<=size;i++){{ for(j=0;j<ptr;j++)for(j=0;j<ptr;j++) {{ if(a[j]==i)if(a[j]==i)

break;break; }}

Page 37: ma project

if(j==ptr)if(j==ptr)b[k++]=i;b[k++]=i;

}}i=j=0;i=j=0;while(i<index && exit_p==0)while(i<index && exit_p==0){{

remove=0;remove=0;if(chess[row][b[i]-1]==-1&& if(chess[row][b[i]-1]==-1&&

exit_p==0)exit_p==0){{

chess[row][b[i]-chess[row][b[i]-1]=(row+50);1]=(row+50);

diagonal_1_check(row,b[i]-diagonal_1_check(row,b[i]-1,row,-1,row,- 1);1);

diagonal_2_check(row,b[i]-diagonal_2_check(row,b[i]-1,row,-1,row,- 1);1);

column(row,b[i]-1,row,-1);column(row,b[i]-1,row,-1);remove=1;remove=1;a[ptr]=b[i];a[ptr]=b[i];cal_positions(a,index-cal_positions(a,index-

1,row+1,ptr+1);1,row+1,ptr+1);

}}

Page 38: ma project

if(remove==1 && exit_p==0)if(remove==1 && exit_p==0){{

chess[row][b[i]-1]=-1;chess[row][b[i]-1]=-1;diagonal_1_check(row,b[i]-diagonal_1_check(row,b[i]-

1,-1,- 1,row);1,row);diagonal_2_check(row,b[i]-diagonal_2_check(row,b[i]-

1,-1,- 1,row);1,row);column(row,b[i]-1,-1,row);column(row,b[i]-1,-1,row);

}}i++;i++;

}}}}elseelse{{

exit_p=possible_results();exit_p=possible_results();count_num++;count_num++;

}}}}

}}

Page 39: ma project

void instructions( ) // RULESvoid instructions( ) // RULES{{

clrwin ( 0, 0, 25, 80, 0, 3 ) ;clrwin ( 0, 0, 25, 80, 0, 3 ) ;drawbox ( 2, 2, 21, 75, 0, 8 ) ;drawbox ( 2, 2, 21, 75, 0, 8 ) ;writestring ( "INSTRUCTIONS", 30, 2, 12, 0 ) ;writestring ( "INSTRUCTIONS", 30, 2, 12, 0 ) ;writestring ( "YOU CAN USE KEYBOARD OR MOUSE TO writestring ( "YOU CAN USE KEYBOARD OR MOUSE TO

PLACE A PLACE A QUEEN", 5, 4,11, 0) ;QUEEN", 5, 4,11, 0) ;writestring ( "* USING KEYBOARD", 5, 6, 4, 0 ) ;writestring ( "* USING KEYBOARD", 5, 6, 4, 0 ) ;writestring ( " - USE ARROW KEYS TO GO writestring ( " - USE ARROW KEYS TO GO

UP,DOWN,LEFT,RIGHT.", 10, 8, UP,DOWN,LEFT,RIGHT.", 10, 8, 11,0 ) ;11,0 ) ;

writestring ( " - THEN PRESS ENTER TO PLACE A writestring ( " - THEN PRESS ENTER TO PLACE A QUEEN", 10,10,11, 0 ) ;QUEEN", 10,10,11, 0 ) ;

writestring ( "~* USING MOUSE ", 5, 12, 4, 0 ) ;writestring ( "~* USING MOUSE ", 5, 12, 4, 0 ) ;writestring ( "- FIRST LEFTCLICK ON BUTTON 'PLACED' writestring ( "- FIRST LEFTCLICK ON BUTTON 'PLACED'

WHICH IS AT WHICH IS AT RIGHTTOP.", 10, 14, 11, 0 ) ;RIGHTTOP.", 10, 14, 11, 0 ) ;writestring ( "- THEN SELECT A PLACE ON writestring ( "- THEN SELECT A PLACE ON

CHESSBOARD BY CHESSBOARD BY RIGHTCLICK. ", RIGHTCLICK. ", 10,16, 11, 0 ) ;10,16, 11, 0 ) ;

writestring ( "* THEN WAIT FOR FEW MINUTES", 5, 18, writestring ( "* THEN WAIT FOR FEW MINUTES", 5, 18, 13, 0 ) ;13, 0 ) ;

writestring ( "Press Any Key To Continue", 50, 20, 13, 0 ) ;writestring ( "Press Any Key To Continue", 50, 20, 13, 0 ) ;getch();getch();

}}

Page 40: ma project

void writestring(char*str,int row,int col,int fore, int void writestring(char*str,int row,int col,int fore, int back, int del )back, int del ){{

//WRITES A STRING TO THE SCREN//WRITES A STRING TO THE SCRENint x = 30 * del ; // DEL = 1 IF THERE SHOULD BE int x = 30 * del ; // DEL = 1 IF THERE SHOULD BE

A DELAY IN DISPLAYA DELAY IN DISPLAY// 0 OTHER WISE. IT IS SET TO ZERO BY DEFAULT// 0 OTHER WISE. IT IS SET TO ZERO BY DEFAULTwhile ( *str )while ( *str ){{

// THE NEXT CHAR WILL BE DISPLAYED IN // THE NEXT CHAR WILL BE DISPLAYED IN ATTRIBUTED MANNERATTRIBUTED MANNER

if ( *str == '^' ) // HOT KEYSif ( *str == '^' ) // HOT KEYS{{

str++ ;str++ ;writechar (*str++, row++, col, 1, writechar (*str++, row++, col, 1,

back ) ;back ) ;delay ( x ) ;delay ( x ) ;nosound ( ) ;nosound ( ) ;delay ( x ) ;delay ( x ) ;

}}

Page 41: ma project

else if ( *str == 126 ) // HOT KEYSelse if ( *str == 126 ) // HOT KEYS{{

str++;str++;writechar(*str++, row++, col, 10, writechar(*str++, row++, col, 10,

back );back );delay ( x ) ;delay ( x ) ;nosound ( ) ;nosound ( ) ;delay ( x ) ;delay ( x ) ;

}}elseelse{{

writechar (*str++, row++, col, fore, writechar (*str++, row++, col, fore, back ) ;back ) ;

delay ( x ) ;delay ( x ) ;nosound ( ) ;nosound ( ) ;delay ( x ) ;delay ( x ) ;

}}}}nosound ( ) ;nosound ( ) ;return ;return ;

}}

Page 42: ma project

void clrwin(int sr,int sc,int er,int ec,int fore, int void clrwin(int sr,int sc,int er,int ec,int fore, int back)back){{// CLEARS THE WINDOW WITH THE GIVEN // CLEARS THE WINDOW WITH THE GIVEN //FOREGROUND AND BACKGROUND COLOR//FOREGROUND AND BACKGROUND COLOR

i.h.ah=6;i.h.ah=6;i.h.al=0;i.h.al=0;i.h.ch=sr;i.h.ch=sr;i.h.cl=sc;i.h.cl=sc;i.h.dh=er;i.h.dh=er;i.h.dl=ec;i.h.dl=ec;i.h.bh=back*16+fore;i.h.bh=back*16+fore;int86(0x10,&i,&i); //clears the screenint86(0x10,&i,&i); //clears the screengotorc ( 0, 0 ) ; //moves the cursor to the gotorc ( 0, 0 ) ; //moves the cursor to the

appropriate positionappropriate position}}

Page 43: ma project

void gotorc ( int r, int c )void gotorc ( int r, int c ){{// MOVES THE CURSOR TO THE // MOVES THE CURSOR TO THE //APPROPRIATE LOCATION//APPROPRIATE LOCATION

REGS i, o ;REGS i, o ;i.h.ah = 2 ;i.h.ah = 2 ;i.h.bh = 0 ;i.h.bh = 0 ;i.h.dh = r ;i.h.dh = r ;i.h.dl = c ;i.h.dl = c ;int86 ( 16, &i, &o ) ;int86 ( 16, &i, &o ) ;

}}

Page 44: ma project

void drawbox ( int starty, int startx, int endy, int endx, int void drawbox ( int starty, int startx, int endy, int endx, int color, int shad )color, int shad ){{

// FUNCTION TO DRAW THE BOX// FUNCTION TO DRAW THE BOX// JUST STEP THRU THE FUNCTION USING F7 // JUST STEP THRU THE FUNCTION USING F7

KEYKEYint i, j ;int i, j ;if ( starty > endy || startx > endx || color > 7 )if ( starty > endy || startx > endx || color > 7 )

return ;return ;for ( i = startx ; i < endx ; i ++ )for ( i = startx ; i < endx ; i ++ ){{

for ( j = starty ; j < endy ; j ++ )for ( j = starty ; j < endy ; j ++ )writechar ( ' ', i, j, 0, color ) ;writechar ( ' ', i, j, 0, color ) ;writechar ( 219, i + 1, endy, shad, 0 ) ;writechar ( 219, i + 1, endy, shad, 0 ) ;

}}for ( i = endy ; i >= starty + 1 ; i -- )for ( i = endy ; i >= starty + 1 ; i -- ){{

writechar ( 219, endx, i, shad, 0 ) ;writechar ( 219, endx, i, shad, 0 ) ;writechar ( 219, endx + 1, i, shad, 0 ) ;writechar ( 219, endx + 1, i, shad, 0 ) ;

}}}}

Page 45: ma project

void writechar(char ch,int row,int col,int fore, int back)void writechar(char ch,int row,int col,int fore, int back){{

* ( scr + col * 160 + row * 2 ) = ch ;* ( scr + col * 160 + row * 2 ) = ch ;* ( scr + col * 160 + row * 2 + 1 ) = back * 16 * ( scr + col * 160 + row * 2 + 1 ) = back * 16

+ fore ;+ fore ;return ;return ;

}}void doneby()void doneby(){{

int i,j,z,c;int i,j,z,c;int gd=DETECT,gm;int gd=DETECT,gm;initgraph(&gd,&gm,"..\bgi");initgraph(&gd,&gm,"..\bgi");x_center = 320, y_center = 200;x_center = 320, y_center = 200;rad=100;rad=100;setcolor(13);setcolor(13);line(40,70,590,70);line(40,70,590,70);setcolor(2);setcolor(2);rectangle(50,340,590,420);rectangle(50,340,590,420);setcolor(10);setcolor(10);

Page 46: ma project

settextstyle(5,0,5);settextstyle(5,0,5);outtextxy(55,345,“IT");outtextxy(55,345,“IT");settextstyle(4,0,3);settextstyle(4,0,3);for(i=1;i<=640;i++)for(i=1;i<=640;i++){{

setcolor(9);setcolor(9);line(i,20,i,20);line(i,20,i,20);line(i,30,i,30);line(i,30,i,30);delay(1);delay(1);

}}for(j=10;j<=460;j++)for(j=10;j<=460;j++){{

setcolor(9);setcolor(9);line(610,j,610,j);line(610,j,610,j);line(620,j,620,j);line(620,j,620,j);delay(1);delay(1);

}}for( z=640;z>=1;z--)for( z=640;z>=1;z--) {{

line(z,435,z,435);line(z,435,z,435);line(z,445,z,445);line(z,445,z,445);delay(1);delay(1);

}}for( c=460;c>=10;c--)for( c=460;c>=10;c--){{

setcolor(9);setcolor(9);line(20,c,20,c);line(20,c,20,c);line(30,c,30,c);line(30,c,30,c);delay(1);delay(1);

}}

Page 47: ma project

for ( i = 0; i < 10; i++ )for ( i = 0; i < 10; i++ ){{ p[i] = x_center + rad * cos(36*i*3.14159/180);p[i] = x_center + rad * cos(36*i*3.14159/180); q[i] = y_center + rad * sin(36*i*3.14159/180);q[i] = y_center + rad * sin(36*i*3.14159/180);}}for ( i = 0; i < 10; i++ )for ( i = 0; i < 10; i++ ){{

for ( j = 0; j < 10; j++ )for ( j = 0; j < 10; j++ ){{

setcolor(14);setcolor(14);line(p[i],q[i],p[j],q[j]);line(p[i],q[i],p[j],q[j]);delay(25);delay(25);

}}}}delay(500);delay(500);closegraph();closegraph();error_mesg();error_mesg();outtextxy(250,210, "Thank You");outtextxy(250,210, "Thank You");gotoxy(50,24);gotoxy(50,24);printf( "Press Any Key To Exit");printf( "Press Any Key To Exit");getch();getch();

}}

Page 48: ma project

void fill_poly(int x1,int y1,int x2,int y2,int color,int void fill_poly(int x1,int y1,int x2,int y2,int color,int style)style){{

int poly[8],i;int poly[8],i;poly[0] = x1;poly[0] = x1;poly[1] = y1;poly[1] = y1;poly[2] = x2;poly[2] = x2;poly[3] = y1;poly[3] = y1;poly[4] = x2;poly[4] = x2;poly[5] = y2;poly[5] = y2;poly[6] = x1;poly[6] = x1;poly[7] = y2;poly[7] = y2;setfillstyle(style,color);setfillstyle(style,color);setcolor(color);setcolor(color);fillpoly(4, poly);fillpoly(4, poly);

}}

Page 49: ma project

void background()void background(){{

int gd=DETECT,gm;int gd=DETECT,gm;initgraph(&gd,&gm,"..\bgi");initgraph(&gd,&gm,"..\bgi");fill_poly(0,20,getmaxx(),40,11,11);fill_poly(0,20,getmaxx(),40,11,11);fill_poly(getmaxx()-40,0,getmaxx()-fill_poly(getmaxx()-40,0,getmaxx()-

20,getmaxy(),11,11);20,getmaxy(),11,11);fill_poly(0,getmaxy()-fill_poly(0,getmaxy()-

40,getmaxx(),getmaxy()-20,11,11);40,getmaxx(),getmaxy()-20,11,11);fill_poly(20,0,40,getmaxy(),11,11);fill_poly(20,0,40,getmaxy(),11,11);

}}void first_screen()void first_screen(){{

int i,j,k;int i,j,k;fill_poly(125,50,500,100,12,10);fill_poly(125,50,500,100,12,10);settextstyle(10, HORIZ_DIR, 3);settextstyle(10, HORIZ_DIR, 3);setcolor(10);setcolor(10);

Page 50: ma project

outtextxy(135,50, "N-Queen's Problem");outtextxy(135,50, "N-Queen's Problem");fill_poly(125,300,500,350,12,10);fill_poly(125,300,500,350,12,10);settextstyle(7, HORIZ_DIR, 3);settextstyle(7, HORIZ_DIR, 3);setcolor(11);setcolor(11);outtextxy(135,300, "N-Queen's Problem");outtextxy(135,300, "N-Queen's Problem");fill_poly(50,50,100,350,12,10);fill_poly(50,50,100,350,12,10);settextstyle(8, 1, 3);settextstyle(8, 1, 3);setcolor(12);setcolor(12);outtextxy(50,55, "N-Queen's Problem");outtextxy(50,55, "N-Queen's Problem");fill_poly(525,50,575,350,12,10);fill_poly(525,50,575,350,12,10);settextstyle(5, 1, 3);settextstyle(5, 1, 3);setcolor(13);setcolor(13);outtextxy(525,50, "N-Queen's Problem");outtextxy(525,50, "N-Queen's Problem");gotoxy(50,25);gotoxy(50,25);printf("Press any key to continue");printf("Press any key to continue");for ( i = 0; i < 10; i++ )for ( i = 0; i < 10; i++ ){{

p[i] = x_center + rad * cos(36*i*3.14159/180);p[i] = x_center + rad * cos(36*i*3.14159/180);q[i] = y_center + rad * sin(36*i*3.14159/180);q[i] = y_center + rad * sin(36*i*3.14159/180);

}}for ( i = 0; i < 10; i++ )for ( i = 0; i < 10; i++ ){{

for ( j = 0; j < 10; j++ )for ( j = 0; j < 10; j++ ){{

setcolor(14);setcolor(14);line(p[i],q[i],p[j],q[j]);line(p[i],q[i],p[j],q[j]);delay(50);delay(50);

}}}}getch();getch(); }}

Page 51: ma project

void initmouse(void)void initmouse(void){{

iRow = 0,iCol = 0,iStatus = 0;iRow = 0,iCol = 0,iStatus = 0;asm{asm{

mov ax,0;mov ax,0;int 0x33;int 0x33;

}}}}void yesmouse(void)void yesmouse(void){{

asm{asm{ mov ax,1;mov ax,1; int 0x33;int 0x33;

}}}}void nomouse(void)void nomouse(void){{

asm{asm{ mov ax,2;mov ax,2; int 0x33;int 0x33;

}}}}

Page 52: ma project

void mouse(void)void mouse(void){{

asm{asm{ mov ax,3;mov ax,3; int 0x33;int 0x33; mov iRow,dx;mov iRow,dx; mov iCol,cx;mov iCol,cx; mov iStatus,bx;mov iStatus,bx;

}}}}void limmouse(int iMinX,int iMinY,int iMaxX,int iMaxY)void limmouse(int iMinX,int iMinY,int iMaxX,int iMaxY){{

yesmouse();yesmouse(); asm{asm{

mov ax,7mov ax,7 mov cx,iMinXmov cx,iMinX mov dx,iMaxXmov dx,iMaxX int 0x33int 0x33

}} asm{asm{

mov ax,8mov ax,8 mov cx,iMinYmov cx,iMinY mov dx,iMaxYmov dx,iMaxY int 0x33int 0x33

}} }}

Page 53: ma project

void draw_chess_board()void draw_chess_board(){{ int color1,color2,poly[8],i,j;int color1,color2,poly[8],i,j; x=0;y=0;x=0;y=0; color1=1;color1=1; color2=0;color2=0; for(i=0;i<size;i++)for(i=0;i<size;i++) {{

color1=color2;color1=color2;for(j=0;j<size;j++)for(j=0;j<size;j++){{ if(color1==1)if(color1==1) color1=0;color1=0; else if(color1==0)else if(color1==0)

color1=1;color1=1;

Page 54: ma project

setcolor(2);setcolor(2); rectangle(x,y,x+(getmaxy()/size),y+(getmaxy()/size));rectangle(x,y,x+(getmaxy()/size),y+(getmaxy()/size)); poly[0] = x;poly[0] = x; poly[1] = y;poly[1] = y; poly[4] = x+(getmaxy()/size);poly[4] = x+(getmaxy()/size); poly[5] = y+(getmaxy()/size);poly[5] = y+(getmaxy()/size); poly[2] = x+(getmaxy()/size);poly[2] = x+(getmaxy()/size); poly[3] = y;poly[3] = y; poly[6] = x;poly[6] = x; poly[7] = y+(getmaxy()/size);poly[7] = y+(getmaxy()/size); setcolor(2);setcolor(2); if(color1!=0)if(color1!=0) {{

setfillstyle(1,color1);setfillstyle(1,color1); fillpoly(4,poly);fillpoly(4,poly); x=x+getmaxy()/size;x=x+getmaxy()/size;

}} elseelse {{

rectangle(x,y,x+getmaxy()/size,getmaxy()/size);rectangle(x,y,x+getmaxy()/size,getmaxy()/size);x=x+getmaxy()/size;x=x+getmaxy()/size;

}}}}if(color2==1)if(color2==1) color2=0;color2=0;else if(color2==0)else if(color2==0)

color2=1;color2=1;x=0;x=0;y=y+getmaxy()/size;y=y+getmaxy()/size;

}}}}

Page 55: ma project

void result()void result(){{ int gd=DETECT,gm,count,i,j;int gd=DETECT,gm,count,i,j; initgraph(&gd,&gm,"..\bgi");initgraph(&gd,&gm,"..\bgi"); draw_chess_board();draw_chess_board(); settextstyle(3,0,4);settextstyle(3,0,4); setcolor(5);setcolor(5); outtextxy(500,5,"Solution");outtextxy(500,5,"Solution"); outtextxy(500,50,"Found");outtextxy(500,50,"Found"); setcolor(2);setcolor(2); rectangle(495,150,getmaxx(),479);rectangle(495,150,getmaxx(),479); setcolor(15);setcolor(15); settextstyle(1,0,1);settextstyle(1,0,1); outtextxy(500,200,"This Queen Is");outtextxy(500,200,"This Queen Is"); outtextxy(500,220,"Placed By User");outtextxy(500,220,"Placed By User"); setcolor(4);setcolor(4); setfillstyle(10,4);setfillstyle(10,4); fillellipse(550,180,20,20);fillellipse(550,180,20,20);

Page 56: ma project

setcolor(15);setcolor(15); outtextxy(500,300,"These Queens");outtextxy(500,300,"These Queens"); outtextxy(500,320,"Are Placed");outtextxy(500,320,"Are Placed"); outtextxy(500,340,"According to");outtextxy(500,340,"According to"); outtextxy(500,360,"Queen Placed");outtextxy(500,360,"Queen Placed"); outtextxy(500,380,"By User");outtextxy(500,380,"By User"); setcolor(6);setcolor(6); setfillstyle(9, 6);setfillstyle(9, 6); fillellipse(550,280,20,20);fillellipse(550,280,20,20); x=y=((getmaxy()/size)/2);x=y=((getmaxy()/size)/2); for(i=0;i<size;i++)for(i=0;i<size;i++) {{

x=((getmaxy()/size)/2);x=((getmaxy()/size)/2);for(j=0;j<size;j++)for(j=0;j<size;j++){{ if(chess[i][j]==(i+50))if(chess[i][j]==(i+50)) {{ if(i==placed_row)if(i==placed_row) {{

setcolor(4);setcolor(4);setfillstyle(10, 4);setfillstyle(10, 4);

}} elseelse {{

setcolor(6);setcolor(6);setfillstyle(9, 6);setfillstyle(9, 6);

}} fillellipse(x,y,radiusx,radiusy);fillellipse(x,y,radiusx,radiusy); }} x=x+((getmaxy()/size));x=x+((getmaxy()/size));}}y=y+((getmaxy()/size));y=y+((getmaxy()/size));

}} getch();getch(); closegraph();closegraph();

}}

Page 57: ma project

void erase()void erase(){{

int pixel;int pixel; pixel=getpixel(x+radiusx+1,y);pixel=getpixel(x+radiusx+1,y); setcolor(pixel);setcolor(pixel); setfillstyle(1,pixel);setfillstyle(1,pixel); fillellipse(x,y,radiusx,radiusy);fillellipse(x,y,radiusx,radiusy);

}}void drawcircle()void drawcircle(){{ setcolor(4);setcolor(4); setfillstyle(10,4);setfillstyle(10,4); fillellipse(x,y,radiusx,radiusy);fillellipse(x,y,radiusx,radiusy);}}int search_rowcol()int search_rowcol(){{ y=0;y=0; for(ro=0;ro<size;ro++)for(ro=0;ro<size;ro++) {{

x=0;x=0;for(co=0;co<size;co++)for(co=0;co<size;co++){{

if(x<iCol && iCol<(x+479/size) && y<iRow && if(x<iCol && iCol<(x+479/size) && y<iRow && iRow<(y+479/size))iRow<(y+479/size))

{{return 1;return 1;

}}x=x+(479/size);x=x+(479/size);

}}

Page 58: ma project

y=y+(479/size);y=y+(479/size); }} return 0;return 0;}}void acceptbymouse()void acceptbymouse(){{

int prevx,prevy,break_flag,pressed,valid;int prevx,prevy,break_flag,pressed,valid;int gd=DETECT,gm;int gd=DETECT,gm;initgraph(&gd,&gm,"..\bgi");initgraph(&gd,&gm,"..\bgi");draw_chess_board();draw_chess_board();initmouse();initmouse();limmouse(0,0,getmaxx()-50,getmaxy());limmouse(0,0,getmaxx()-50,getmaxy());yesmouse();yesmouse();fill_poly(495,15,605,45,11,1);fill_poly(495,15,605,45,11,1);fill_poly(500,20,600,40,5,1);fill_poly(500,20,600,40,5,1);setcolor(14);setcolor(14);settextstyle(5,0,3);settextstyle(5,0,3);outtextxy(525,12,"Place");outtextxy(525,12,"Place"); setcolor(15);setcolor(15); settextstyle(1,0,3);settextstyle(1,0,3); outtextxy(500,100,"To Place");outtextxy(500,100,"To Place"); outtextxy(500,120,"A Queen");outtextxy(500,120,"A Queen"); outtextxy(500,140,"LeftClick");outtextxy(500,140,"LeftClick"); outtextxy(500,160,"On Button");outtextxy(500,160,"On Button"); outtextxy(500,180,"'Placed' ");outtextxy(500,180,"'Placed' ");

Page 59: ma project

while(1)while(1){{

mouse();mouse();if(iStatus==1 && 500<=iCol if(iStatus==1 && 500<=iCol

&&iCol<=605 && &&iCol<=605 && 15<=iRow 15<=iRow &&iRow<=40)&&iRow<=40)

{{nomouse();nomouse();fill_poly(495,15,605,50,0,1);fill_poly(495,15,605,50,0,1);break;break;

}} }} prevx=0;prevy=0;prevx=0;prevy=0; fill_poly(500,0,getmaxx(),getmaxy(),0,1);fill_poly(500,0,getmaxx(),getmaxy(),0,1); setcolor(15);setcolor(15); settextstyle(1,0,3);settextstyle(1,0,3); outtextxy(500,100,"To Place");outtextxy(500,100,"To Place"); outtextxy(500,120,"A Queen");outtextxy(500,120,"A Queen"); outtextxy(500,140,"RightClick");outtextxy(500,140,"RightClick"); outtextxy(500,160,"On Proper");outtextxy(500,160,"On Proper"); outtextxy(500,180,"Place");outtextxy(500,180,"Place");

Page 60: ma project

while(1)while(1) {{

yesmouse();yesmouse();mouse();mouse();if(iStatus==2)if(iStatus==2){{ break;break;}}

valid=search_rowcol();valid=search_rowcol();if(valid==1)if(valid==1){{

if(prevx<iCol && if(prevx<iCol && iCol<(prevx+479/size) && iCol<(prevx+479/size) && prevy<iRow &&prevy<iRow &&

iRow<(prevy+479/size))iRow<(prevy+479/size)) {{

nomouse();nomouse();

setcolor(15);setcolor(15);

prevx=x;prevy=y;prevx=x;prevy=y;

rectangle(x,y,x+(479/rectangle(x,y,x+(479/size),y+(479/size));size),y+(479/size));

}}

elseelse {{

setcolor(2);setcolor(2);

rectangle(prevx,prevy,prevx+(479/rectangle(prevx,prevy,prevx+(479/size),prevy+(479/size));size),prevy+(479/size));

nomouse();nomouse();

setcolor(15);setcolor(15);

prevx=x;prevy=y;prevx=x;prevy=y;

rectangle(x,y,x+(479/rectangle(x,y,x+(479/size),y+(479/size));size),y+(479/size));

}}

yesmouse();yesmouse();}}

}} nomouse();nomouse(); x=x+(479/size)/2; x=x+(479/size)/2;

y=y+(479/size)/2;y=y+(479/size)/2; drawcircle();drawcircle(); placed_row=ro;placed_row=ro; placequeen(ro,co,0);placequeen(ro,co,0); delay(1000);delay(1000); closegraph();closegraph();

}}

Page 61: ma project

void acceptbykeyboard()void acceptbykeyboard()

{{ int gd=DETECT,gm,c,i,j;int gd=DETECT,gm,c,i,j; initgraph(&gd,&gm,"..\bgi");initgraph(&gd,&gm,"..\bgi"); draw_chess_board();draw_chess_board(); x=(getmaxy()/size)/2;x=(getmaxy()/size)/2; y=(getmaxy()/size)/2;y=(getmaxy()/size)/2; i=0;j=0;i=0;j=0; drawcircle();drawcircle(); dodo {{ c=getch();c=getch(); if(c==0)if(c==0)

c=getch();c=getch(); if(c==72 && y-(getmaxy()/size)>0)if(c==72 && y-(getmaxy()/size)>0) {{

erase();erase(); y=y-(getmaxy()/size);y=y-(getmaxy()/size); drawcircle();drawcircle(); i--;i--;

}} elseelse

if(c==80 && if(c==80 && y+(getmaxy()/size)<479)y+(getmaxy()/size)<479)

{{ erase();erase(); y=y+(getmaxy()/size);y=y+(getmaxy()/size); drawcircle();drawcircle(); i++;i++;}}

elseelseif(c==75&& if(c==75&&

x-(getmaxy()/size)>0)x-(getmaxy()/size)>0){{ erase();erase(); x=x-(getmaxy()/size);x=x-(getmaxy()/size); drawcircle();drawcircle(); j--;j--;}}elseelseif(c==77 if(c==77

&&x+(getmaxy()/size)<479)&&x+(getmaxy()/size)<479){{ erase();erase(); x=x+(getmaxy()/size);x=x+(getmaxy()/size); drawcircle();drawcircle(); j++;j++;}}if(c==13)if(c==13){{ drawcircle();drawcircle(); placed_row=i;placed_row=i; placequeen(i,j,0);placequeen(i,j,0); c=27;c=27;}}

}while(c!=27);}while(c!=27); closegraph();closegraph();}}

Page 62: ma project

if(j1==size)if(j1==size) {{ if(i-1!=placed_row)if(i-1!=placed_row) {{ i--;i--; row--;row--; }} elseelse {{ i=i-2;i=i-2; row=row-2;row=row-2; }} for(j=0;j<size;j++)for(j=0;j<size;j++) {{ if(chess[i]if(chess[i]

[j]==(i+50))[j]==(i+50)) break;break;

}} chess[i][j]=-1;chess[i][j]=-1; diagonal_1_check(i,j,-diagonal_1_check(i,j,-

1,i);1,i); diagonal_2_check(i,j,-diagonal_2_check(i,j,-

1,i);1,i); column(i,j,-1,i);column(i,j,-1,i); textcolor(0);textcolor(0); textbackground(0);textbackground(0); gotoxy(--text_x,25);gotoxy(--text_x,25); cprintf(" ");cprintf(" ");

break_up=placequeen(row,j+1,0);break_up=placequeen(row,j+1,0);}}

}} return 0;return 0;

}}

int placequeen(int i,int j,int break_up)int placequeen(int i,int j,int break_up){{

int j1;int j1; if(break_up==0)if(break_up==0) {{

count_exceed++;count_exceed++;

if(count_exceed>total_no_of_nodes)if(count_exceed>total_no_of_nodes) {{

error_mesg();error_mesg();

outtextxy(110,210, "Sorry,Solution Is Not outtextxy(110,210, "Sorry,Solution Is Not Possible !!");Possible !!");

gotoxy(50,24);gotoxy(50,24);printf( "Press printf( "Press

Any Key To Continue");Any Key To Continue");getch();getch();closegraph();closegraph();return 1;return 1;

}} for(j1=j;j1<size;j1++)for(j1=j;j1<size;j1++) {{ if(chess[i][j1]==-1)if(chess[i][j1]==-1) {{ textcolor(3);textcolor(3); gotoxy(text_x++,25);gotoxy(text_x++,25); cprintf("°");cprintf("°"); chess[i][j1]=(i+50);chess[i][j1]=(i+50);

diagonal_1_check(i,j1,i,-1);diagonal_1_check(i,j1,i,-1);

diagonal_2_check(i,j1,i,-1);diagonal_2_check(i,j1,i,-1); column(i,j1,i,-1);column(i,j1,i,-1); break;break; }} }}

Page 63: ma project

void diagonal_1_check(int i1,int j1,int val,int check)void diagonal_1_check(int i1,int j1,int val,int check){{ int i2,j2;int i2,j2; i2=i1;i2=i1; j2=j1;j2=j1; i2--;j2--;i2--;j2--; while(i2>=0&&j2>=0)while(i2>=0&&j2>=0) {{

if(check==chess[i2][j2])if(check==chess[i2][j2]) chess[i2][j2]=val;chess[i2][j2]=val;

i2--;j2--;i2--;j2--; }} i2=i1;i2=i1; j2=j1;j2=j1; i2++;j2++;i2++;j2++; while(i2<size&&j2<size)while(i2<size&&j2<size) {{

if(check==chess[i2][j2])if(check==chess[i2][j2]) chess[i2][j2]=val;chess[i2][j2]=val;

i2++;j2++;i2++;j2++; }}}}

Page 64: ma project

void diagonal_2_check(int i1,int j1,int val,int check)void diagonal_2_check(int i1,int j1,int val,int check){{

int i2,i3,j2;int i2,i3,j2; i2=i1;i2=i1; j2=j1;j2=j1; i2--;j2++;i2--;j2++; while(i2>=0&&j2<size)while(i2>=0&&j2<size) {{

if(check==chess[i2][j2])if(check==chess[i2][j2]) chess[i2][j2]=val;chess[i2][j2]=val;

i2--;j2++;i2--;j2++; }} i2=i1;i2=i1; j2=j1;j2=j1; i2++;j2--;i2++;j2--; while(i2<size&&j2>=0)while(i2<size&&j2>=0) {{

if(check==chess[i2][j2])if(check==chess[i2][j2]) chess[i2][j2]=val;chess[i2][j2]=val;

i2++;j2--;i2++;j2--; }}}}

Page 65: ma project

void column(int i1,int j1,int val,int check)void column(int i1,int j1,int val,int check){{

int j2;int j2; for(j2=0;j2<size;j2++)for(j2=0;j2<size;j2++) {{

if(chess[i1][j2]==check)if(chess[i1][j2]==check) {{

chess[i1][j2]=val;chess[i1][j2]=val; }}

}} for(j2=0;j2<size;j2++)for(j2=0;j2<size;j2++) {{ if(chess[j2][j1]==check)if(chess[j2][j1]==check) {{

chess[j2][j1]=val;chess[j2][j1]=val; }} }}

}}

Page 66: ma project

if(status==0)if(status==0)status=getch();status=getch();switch(status)switch(status){{case 72:if(choice==1)case 72:if(choice==1)choice=6;choice=6;elseelsechoice--;choice--;break;break;case 80:if(choice==6)case 80:if(choice==6)choice=1;choice=1;elseelsechoice++;choice++;break;break;case 13:case 13: if(choice==1)if(choice==1)instructions();instructions(); elseelse if(choice==2)if(choice==2) {{acceptsize();acceptsize(); }}

void main()void main(){{

int int i,j,choice,status,breakup,b[50];i,j,choice,status,breakup,b[50];

background();background();//// first_screen();first_screen();

closegraph();closegraph();loadprog();loadprog();about_prog();about_prog();size=-1;size=-1;choice=1;choice=1;dodo{{

clrwin ( 0, 0, 25, 80, 0, clrwin ( 0, 0, 25, 80, 0, 1 ) ;1 ) ;

drawbox ( 5, 20, 20, drawbox ( 5, 20, 20, 55, 4, 0 ) ;55, 4, 0 ) ;

_setcursortype(_NOCURSOR);_setcursortype(_NOCURSOR);for ( int i = 0 ; i <= 6 ; for ( int i = 0 ; i <= 6 ;

i ++ )i ++ ){{ if ( choice == i )if ( choice == i ) writestring writestring

( menu[i], 20, 7 + 2 * i, 0, 10 ) ;( menu[i], 20, 7 + 2 * i, 0, 10 ) ; elseelse writestring writestring

( menu[i], 20, 7 + 2 * i, 10, 4 ) ;( menu[i], 20, 7 + 2 * i, 10, 4 ) ;}}status=getch();status=getch();

Page 67: ma project

else if(choice==6)else if(choice==6) { {

doneby();doneby();

exit(0);exit(0);

else if(size==-1)else if(size==-1) {{

error_mesg();error_mesg();

outtextxy(110,210, "First Enter Size Of outtextxy(110,210, "First Enter Size Of ChessBoard");ChessBoard");

gotoxy(50,24);gotoxy(50,24);

printf( "Press Any Key To Continue");printf( "Press Any Key To Continue");

getch();getch();

closegraph();closegraph(); }}

elseelse

if(choice==5)if(choice==5) {{

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

{{

b[i]=0;b[i]=0;

}}

exit_p=0;exit_p=0;

cal_positions(b,size,0,0);cal_positions(b,size,0,0); }}

if(status==0)if(status==0)status=getch();status=getch();switch(status)switch(status){{case 72:if(choice==1)case 72:if(choice==1)choice=6;choice=6;elseelsechoice--;choice--;break;break;case 80:if(choice==6)case 80:if(choice==6)choice=1;choice=1;elseelsechoice++;choice++;break;break;case 13:case 13: if(choice==1)if(choice==1)instructions();instructions(); elseelse if(choice==2)if(choice==2) {{acceptsize();acceptsize();

} }

Page 68: ma project

else if(choice==4||choice==3)else if(choice==4||choice==3)

{{

if(choice==4)if(choice==4)

acceptbykeyboard();acceptbykeyboard();

else if(choice==3)else if(choice==3)

acceptbymouse();acceptbymouse();

gotoxy(30,13);gotoxy(30,13);

textcolor(3);textcolor(3);

textbackground(1);textbackground(1);

printf("Placing Please Wait........");printf("Placing Please Wait........");

row=0;row=0;

count_exceed=0;count_exceed=0;

breakup=0;breakup=0;

while(row!=size &&breakup==0)while(row!=size &&breakup==0) {{

if(row==placed_row)if(row==placed_row)

row++;row++;

if(row==size)if(row==size)

break;break;

breakup=placequeen(row,0,0);breakup=placequeen(row,0,0);

row++;row++; }}

if(breakup==0)if(breakup==0) {{

for(i=text_x;i<79;i++)for(i=text_x;i<79;i++)

{{

textcolor(2);textcolor(2);

cprintf("°");cprintf("°");

delay(30);delay(30);

}}

result();result(); }}

Page 69: ma project

}}

break;break;

}}

}while(1);}while(1);

}}

Page 70: ma project

END OF THEEND OF THE

SOURCE CODESOURCE CODE

Page 71: ma project

FLOW CHARTFLOW CHART

START

SET BACKGROUND()

LINK THE BGI GRAPHIC FILE WITHUSER SCREEN

A

Page 72: ma project

READ SIZE OF CHESS BOARD

A

IF SIZE IS BETWEEN 4-8

PLACE-QUEEN ()

B

YES

EXIT(0)

NO

Page 73: ma project

DISPLAY INSTRUCTION TO PLACE

B

DISPLAY THE RESULT

IF EXIT

CLOSE GRAPH()

YES

C

Page 74: ma project

C

STOP

EXIT(0)

Page 75: ma project

SCREEN SHOTSCREEN SHOT

Page 76: ma project

CONCLUSIONCONCLUSION

BROAD CONCLUSIONBROAD CONCLUSION Faster move,intelligent Faster move,intelligent

decisions in moving the queens decisions in moving the queens are the promises of are the promises of standardising on interests of the standardising on interests of the players to play this puzzle.players to play this puzzle.

Finally we conclude that our Finally we conclude that our project will be satisfying the project will be satisfying the players in all the aspects.players in all the aspects.

Page 77: ma project

Future Scope and EnhancementFuture Scope and Enhancement

The application is much flexible and The application is much flexible and extensible and hence further extensible and hence further enhancements if needed,can be enhancements if needed,can be developed to perform quick move and to developed to perform quick move and to implement all the features of the implement all the features of the puzzle.The screen shots are shown above puzzle.The screen shots are shown above which reveals the entire performance of which reveals the entire performance of the project.Synchronizaton modules can the project.Synchronizaton modules can be used to store the user’s play on the be used to store the user’s play on the puzzles. puzzles.

Page 78: ma project

REFERENCESREFERENCES

www.howstuffworks.comwww.howstuffworks.com www.wikipedia.orgwww.wikipedia.org www.google.comwww.google.com ““C++ Complete reference” by C++ Complete reference” by

Schildt Schildt C++ programs by VaralakshmiC++ programs by Varalakshmi Keyhtmldos books onlineKeyhtmldos books online