Acknowledgement: Date
Acknowledgement: Date
Acknowledgement: Date
Accomplishing this task would not have been possible without the support of a number of people. First and foremost we would like to thank the Almighty for giving us courage to bring up this project successfully. We are thankful to the Principal Dr. (Mrs.) Charanjit Mahal and Head of department Mrs. Kamlesh Gupta for their support, motivation and encouragement. At the outset , we would like to propose a word of thanks to our Project Guide, Mrs.Pawanjot Kaur who gave us unending support and help in numerous ways from the time when the idea of this project was conceived. We will also like to pay a special thanks to our family members for their unending co-operation and emotional support. Last but not the least a word of gratitude to all our friends and classmates.
Date:
CERTIFICATE
This is to certify that this project entitled Tic Tac Toe submitted to Panjab University ,Chandigarh in the partial fulfillment of the requirements for the degree of Masters of Science in the subject of Information Technology is a bonafide work carried out by Simran Kaur , Jaspreet Kaur and Jasleen Kaur under our supervision and no part of this work has been submitted for any other degree. The assistance and help received during the course of work has been fully acknowledged.
Principal Dr.(Mrs.)Charanjit Mahal Guru Nanak Girls College Model Town , Ludhiana.
STUDENT DECLARATION
We hereby declare that the project entitled TIC TAC TOE submitted by Simran Kaur , Jaspreet Kaur and Jasleen Kaur in the partial fulfillment of the requirements for the degree of Masters of Science in the subject of Information Technology(Ist Semester, Session 2012-13) is our original work and has not been submitted for the reward of any other degree/ diploma/ scholarship or any other similar title or prize.
LIST OF CONTENTS
Introduction Types of Computer Graphics Applications of Interactive Computer Graphics Advantages of Interactive Computer Graphics Functions of Interactive Computer Graphics Introduction of Project Objective of Project System feasibility report Coding and testing Hardware and Software requirements Coding Output Bibliography
Computer graphics can be used in many disciplines. Charting, Presentations, Drawing, Painting and Design, Image Processing and Scientific Visualizations.
APPLICATIONS OF GRAPHICS
Computers have become powerful tool for the rapid and economical production of pictures. Computer graphics are used in several areas such as
Science Engineering Business Industry Government Art Entertainment Advertising Education and training
to represent, manipulate, and analyze content from some data source. Two general types of data visualization are often referred to. Scientific visualization: refers to physical data that is obtained through measurement or simulation and is used to better understand underlying structure and relationships. Examples are visualizing airflow over a surface to understand the effect of different airfoil designs, displaying the temperature across a mechanical part as color, or modeling and animating air particles to visualize how a tornado is formed. Such visualization is useful for dealing with the vast amounts of physical data collected or generated through experiments, sensors, or computer models. Information visualization: is the other general category that refers to more abstract or derived data such as stock prices, network traffic, or gene sequences. Visualization of this type of data generally requires a more abstract technique, such as data graphing, versus trying to represent it with a physical interpretation. CAD : Computer Aided Design was one of the early applications of interactive computer graphics to assist engineers and designers in the modeling and analysis of automobiles, mechanical parts, and building structures. The auto industry is a good example of the benefits derived from using CAD. New car designs used to be created by hand with a full sized clay model built to see what it looked like in 3D. The model could take days or weeks to produce. Today, with the assistance of interactive graphics, all models are created in the computer.
Interactive graphics offers a large number of usercontrollable modes with which to encode and communicate information.
The 2D or 3D shape of objects in a picture, their gray scale or color, and the time variations of these properties. With the recent development of digital signal processing (DSP) and audio synthesis chips, audio feedback can now be provided to augment the graphical feedback and to make the simulated environment even more realistic.
By making communication more efficient, graphics make possible higher-quality and more precise results or products, greater productivity, and lower analysis and design costs.
GRAPHIC FUNCTIONS
Initgraph():
Purpose: It is used to initialize the graphics system. It initializes the graphics driver from the disk and then puts the system into graphics mode. It also reset the graphics setting like colors, fonts . Syntax: Void initgraph(int *gdriver,int* gmode,char* path); Gdriver is an integer that specifies the graphics driver to be used. Gmode is an integer that specifies the initial graphics mode. Path specifies the directory path where initgraph() fist look fo graphics driver.
Closegraph():
Purpose: Closegraph function closes the graphics mode, deallocates all memory allocated by graphics system and restores the screen to the mode it was in before you called initgraph. Syntax: Void closegraph();
Cleardevice() :
Purpose: Cleardevice function clears the screen in graphics mode and sets the current position to (0,0). Clearing the screen consists of filling the screen with current background color.
Arc():
Purpose: Arc function is used to draw an arc with center (x,y) and stangle specifies starting angle, endangle specifies the end angle and last parameter specifies the radius of the arc. arc function can also be used to draw a circle but for that starting angle and end angle should be 0 and 360 respectively. Syntax: void arc(int x, int y, int stangle, int endangle, int radius);
Circle():
Purpose: Circle function is used to draw a circle with center (x,y) and third parameter specifies the radius of the circle. The code given below draws a circle. Syntax: void circle(int x, int y, int radius);
Getbkcolor() :
Purpose: Getbkcolor function returns the current background color Syntax : int getbkcolor();
Getcolor():
Purpose: Getcolor function returns the current drawing color. Syntax : int getcolor();
Getmaxcolor():
Purpose: Getmaxcolor function returns maximum color value for current graphics mode and driver. Total number of colors available for current graphics mode and driver are ( getmaxcolor() + 1 ) as color numbering starts from zero. Syntax: int getmaxcolor();
Getmaxx():
Purpose: Getmaxx function returns the maximum X coordinate for current graphics mode and driver. Syntax: int getmaxx();
Getmaxy():
Purpose: Getmaxy function returns the maximum Y coordinate for current graphics mode and driver. Syntax : int getmaxy();
Getpixel():
Purpose: Getpixel function returns the color of pixel present at location(x, y). Syntax: int getpixel(int x, int y);
Line():
Purpose: Line function is used to draw a line from a point(x1,y1) to point(x2,y2) i.e. (x1,y1) and (x2,y2) are end points of the line.The code given below draws a line. Syntax: void line(int x1, int y1, int x2, int y2);
Rectangle():
Purpose: Rectangle function is used to draw a rectangle. Coordinates of left top and right bottom corner are required to draw the rectangle. left specifies the X-coordinate of top left corner, top specifies the Y-coordinate of top left corner, right specifies the X-coordinate of right bottom corner, bottom specifies the Ycoordinate of right bottom corner. The code given below draws a rectangle. Syntax: void rectangle(int left, int top, int right, int bottom);
Outtext():
Purpose: Outtext function displays text at current position. Syntax: void outtext(char *string);
Outtextxy():
Purpose: Outtextxy function display text or string at a specified point(x,y) on the screen. Syntax: void outtextxy(int x, int y, char *string);
Setbkcolor():
Purpose: Setbkcolor function changes current background color e.g.
setbkcolor(YELLLOW) changes the current background color to YELLOW. Remember that default drawing color is WHITE and background color is BLACK. Syntax: void setbkcolor(int color);
Setcolor():
Purpose: In Turbo Graphics each color is assigned a number. Total 16 colors are available. Strictly speaking number of available colors depends on current graphics mode and driver.For Example :- BLACK is assigned 0, RED is assigned 4 etc. setcolor function is used to change the current drawing color.e.g. setcolor(RED) or setcolor(4) changes the current drawing color to RED. Remember that default drawing color is WHITE. Syntax: void setcolor(int color);
Setfillstyle():
Purpose: Setfillstyle function sets the current fill pattern and fill color.
Settextstyle():
Purpose: Settextstyle function is used to change the way in which text appears, using it we can modify the size of text, change direction of text and change the font of text. Syntax: void settextstyle( int font, int direction, int charsize);
Settextjustify():
Purpose: Sets text justification fo graphics function.The default justification settings are LEFT_TEXT(for horizontal) and TOP_TEXT(fo vertical). Syntax: Void settextjustify(int hoiz,int vert);
Setfillpattern():
Purpose: Selects a use-defined fill patten. Syntax: Void setfillpattern(char* upattern,int color);
OUTPUT PRIMITIVES
Line() :- This function draws a line in graphics mode between two specify end points. It draws the line using the current color,line setting and style. Syntax: void line(int x1,int y1,int x2,int y2); Whereas x1 and y1 are the starting points of the line.x2 and y2 are the ending points of the line. Linerel():-Draws the line a relative distance from the current position. Syntax: void linerel(int dx,int dy); The parameters dx and dy is the horizontal and vertical distance. Lineto():-This function draws the line from current position to x,y position specified in the function. Syntax:void lineto(int x,int y); Circle():-This function draws the circle on the graphic screen with a centre given by x,y coordinates and the radius. Syntax:void circle(int x,int y,int radius); Rectangle():-This function draws the rectangle in graphics mode using current line style and color. Syntax:void rectangle(int left,int top,int right,int bottom); The first two parameters specified the coordinates of one corner of rectangle and other two parameters gives the opposite corner. Cleardevice():-This function clears the entire graphics screen and moves the current position to(0,0). Syntax: void cleardevice(); Closegraph():-This function shut down the graphics system and deallocates all memory allocated by graphics system. Syntax: void closegraph();
Ellipse():- This function draws an elliptical arc on the graphics screen. Syntax: void ellipse(int x, int y, int startangle, int endangle, int x radius, int y radius); This function draws an ellipitical arc in the current drawing color with its center(x,y) and the horizontal and vertical axes given by (xradious &yradious).The start angle and end angles of arc in decreases. Getmaxx():-This function gives the maximum horizontal screen co-ordinates as the return value. The horizontal screen co-ordinate specify x co-ordinate values. Syntax: int getmaxx(); Getmaxy():- This fynction returns the maximum vertical screen co-ordinates. The vertical screen co-ordinates specify the y co-ordinate value. Syntax: int getmaxy(); Putpixel():- This function plots a pixel at a specified point. Syntax: void putpixel(int x, int y, int color); Arc():- This function draws a circular arc on the graphics screen using current drawing color and line styles. Syntax: void arc(int x, int y, int startangle, int endangle, int radius); Bar():- This function draws a bar on the graphics screen by filling the specified rectangular area with the current fill color and fill pattern. Syntax: void bar(int left, int top, int right, int bottom); Bar3d():-This function draws a 3-dimentional bar, then fills it using the current fill pattern and fill color. Syntax: void bar3d( int left, int top,int right, int bottom, int depth, int flag); The parameters left,top specifies the upper left corner of the bar. The parameters right ,bottom specifies the lower right corner of the bar. The depth specifies the bars depth in pixels. The flag parameter governs whether a 3-dimensional top is put on the bar or not.
INTRODUCTION OF PROJECT
and
crosses)
is
a pencil-paper-game for
two
players, X and O, who take turns marking the spaces in a 33 grid. The player who succeeds in placing three respective marks in a horizontal, vertical,diagonal row wins the game. The following example game is won by the first player, X:
Players soon discover that best play from both parties leads to a draw (often referred to as cat or cat's game). Hence, tic-tac-toe is most often played by young children.
Despite its apparent simplicity, Tic-tac-toe requires detailed analysis to determine even some elementary combinatory facts, the most interesting of which are the number of possible games and Naive counting leads to 19,683 possible board layouts (39 since each of the nine spaces can be X, O or blank), and 362,880 (i.e. 9!) possible games (different sequences for placing the Xs and Os on the board). However, two matters much reduce these numbers: The game ends when three-in-a-row is obtained. The number of Xs is always either equal to or exactly 1 more than the number of Os (if X starts the number of possible positions. Tic-tac-toe is a good choice for an example program. Its a simple yet still non trivial game, so its interesting. Everyone knows the rules, which makes it easy to understand the architecture and code design.
PURPOSE
This project is developed using C and Computer Graphics.
This project provides us a mutual environment for playing the game.It provides us a 3x3 grid box in which two players can easily play.This is a pencil paper game which consists of two options (crosses and zeros). It is a childish game and is considered to be the best for passing time. It is very entertaining game and can be played by anyone. It is the most simple and interesting game to be played with. It also helps us for increasing the skills of the person.
SYSTEM FEASIBILITY
Before developing the system feasibility study was conducted. It was found that the proposed system is technically,economically and operationally feasible. TECHNICAL FEASIBILITY: The system was developed with window as an operating system. The system is user friendly,thus report generation of data entry is made easy. Easy retrieval and access to data is provided. Further development such as developing the software, so that automatic will can be printed. ECONOMIC FEASIBILITY: Economically feasibility basically is a good analysis.Keeping this in view the system is economically feasible.Possible questions raised in economic analysis are:
Estimated cost of hardware. Estimated cost of software/software development. Is the project possible, given the resource constraints?
OPERATIONAL FEASIBILITY: Proposed system is beneficial only if they can be turned into information system that will meet the organization operating requirements.As the system is user friendly , throughout , the system is well linked and approved by users showing
no resistance what so ever at all. If the user want more facitity,that can be provided. The system has been prepared keeping in mind the users current requirements. However further modifications can be made in the system in case the users requirements change in further.The proposed system will cause no harm to the organization but instead . It will enhance the result better respect.
CODING
Coding: the code and unit-testing phase entails converting the design language into program code and most important,designing and carrying out test of individual units.One individual modules or units have been tested and accepted,the integration and test begins. 1. Program language: Selecting a programming language according to the need of project i.e.compiler status,availability of training etc. 2. Simple style rule: Making identifying names as meaningful as to programming style and programming quality. Possible using local definitions etc. Comments statements e.g. using prologue an explanatory comment statement very efficient , providing important executable code neatly. 3. Program quality: Readability, understandability . Reuseable code.
TESTING
The basic levels of testing are unit testing ,integration testing ,system testing and acceptance testing. Unit Testing: Once the code is generated , the software program testing begins.Different testing methodologies are available to unravel the bugs that were commited during the previous phases.Different testing tools and methodologies are already available. Integation and unit testing: In this the different units are integrated and the overall system is tested.Integration testing is performed after the units testing of the components. Acceptance Testing Testing the system with the intent of confirming the product and customer acceptance. After passing Unit Testing and Sytem Testing project ia adjusted and Checked so that it can be accepted by the user.
Maintenance is necessary to eliminate errors in the working system during its working life and to tune the system to any variations in its working environment often small system deficiencies are found as a system is brought into operations and changes are made to remove them. System planners must always plan for resource availability to carry out these maintenance functions. The importance of maintenance is to continue to bring the new system to standards
MINIMUM SOFTWARE REQUIREMENTS: Window 3.0,Window XP or higher Operating System. C,C++,Graphics The above discussed system requirements are the minimum requirements that are need to run this system . The user may have more than the above discussed system requirements.
CODING:
#include<stdio.h> #include<conio.h>
void Board(); void PlayerX(); void PlayerO(); void Player_win(); void check(); int win=0,wrong_X=0,wrong_O=0,chk=0;
char name_X[30]; char name_O[30]; int pos_for_X[3][3]; int pos_for_O[3][3]; int pos_marked[3][3];
void main() { int i,ch,j; char ans; /*clrscr(); printf("\n\t\t\t\tTIC TAC TOE"); printf("\n\t\t\t\t");
for(i=1;i<=11;i++) { delay(10000); printf("*"); }*/ do { clrscr(); printf("\n\t\t\t\tTIC TAC TOE"); printf("\n\t\t\t\t"); for(i=1;i<=11;i++) { delay(10000); printf("*"); } printf("\n1.Start The Game"); printf("\n2.Quit The Game"); printf("\nEnter your choice(1-2) : "); scanf("%d",&ch); switch(ch) { case 1: chk=0; win=0;
for(i=1;i<=3;i++) { for(j=1;j<=3;j++) { pos_for_X[i][j]=0; pos_for_O[i][j]=0; pos_marked[i][j]=0; } } printf("\n\n"); clrscr(); printf("\nEnter the name of the player playing for \'X\': "); fflush(stdin); gets(name_X); printf("\nEnter the name of the player playing for \'O\': "); fflush(stdin); gets(name_O); Board(); for(;;) { if(win==1) break; check(); if(chk==9)
{ printf("\n\t\t\tMATCH DRAWS!!"); printf("\nPress any key...."); break; } else chk=0; printf("\nTURN FOR %s:",name_X); PlayerX(); do { if(wrong_X!=1) break; wrong_X=0; printf("\nTURN FOR %s:",name_X); PlayerX(); }while(wrong_X==1); check(); if(chk==9) { printf("\n\t\t\tMATCH DRAWS"); printf("\nPress any key...."); break; }
else chk=0; printf("\nTURN FOR %s:",name_O); PlayerO(); do { if(wrong_O!=1) break; wrong_O=0; printf("\nTURN FOR %s:",name_O); PlayerO(); } while(wrong_O==1); } Board(); if(win!=1) { printf("\n\t\t\tMATCH DRAWS!!"); printf("\nPress any key......."); } getch(); break; case 2: printf("\n\n\n\t\t\tThank You For Playing The Game.");
printf("\n\t\t\t###############################"); getch(); exit(1); break; } printf("\nWant To Play(Y/N) ? "); fflush(stdin); scanf("%c",&ans); }while(ans=='y' || ans=='Y'); } void Board() { int i,j; clrscr(); printf("\n\t\t\t\tTIC TAC TOE BOARD"); printf("\n\t\t\t\t*****************"); printf("\n\n\n"); printf("\n\t\t\t 1\t for(i=1;i<=3;i++) { printf("\n \t\t\t _____________________________"); printf("\n \t\t\t\t \t \t printf("\n\t\t%d\t",i); for(j=1;j<=3;j++) "); 2\t 3");
{ if(pos_for_X[i][j]==1) { printf(" X"); printf(" } else if(pos_for_O[i][j]==1) { printf(" O"); printf(" } else { printf(" continue; } } printf("\n\t\t\t\t \t \t } printf("\n\t\t\t------------------------------"); Player_win(); } void PlayerX() { "); "); "); ");
int row,col; if(win==1) return; printf("\nEnter the row no. : "); fflush(stdin); scanf("%d",&row); printf("Enter the column no. : "); fflush(stdin); scanf("%d",&col); if(pos_marked[row][col]==1 || row<1 || row>3 || col<1 || col>3) { printf("\nWRONG POSITION!! Press any key....."); wrong_X=1; getch(); Board(); } else { pos_for_X[row][col]=1; pos_marked[row][col]=1; Board(); } } void PlayerO()
{ int row,col; if(win==1) return; printf("\nEnter the row no. : "); scanf("%d",&row); printf("Enter the column no. : "); scanf("%d",&col); if(pos_marked[row][col]==1 || row<1 || row>3 || col<1 || col>3) { printf("\nWRONG POSITION!! Press any key...."); wrong_O=1; getch(); Board(); } else { pos_for_O[row][col]=1; pos_marked[row][col]=1; Board(); } } void Player_win() {
int i; for(i=1;i<=3;i++) { if(pos_for_X[i][1]==1 && pos_for_X[i][2]==1 && pos_for_X[i][3]==1) { win=1; printf("\n\nRESULT: %s wins!!",name_X); printf("\nPress any key............"); return; } } for(i=1;i<=3;i++) { if(pos_for_X[1][i]==1 && pos_for_X[2][i]==1 && pos_for_X[3][i]==1) { win=1; printf("\n\nRESULT: %s wins!!",name_X); printf("\nPress any key............"); return; } } if(pos_for_X[1][1]==1 && pos_for_X[2][2]==1 && pos_for_X[3][3]==1) { win=1;
printf("\n\nRESULTL: %s wins!!",name_X); printf("\nPress any key......"); return; } else if(pos_for_X[1][3]==1 && pos_for_X[2][2]==1 && pos_for_X[3][1]==1) { win=1; printf("\n\nRESULT: %s wins!!",name_X); printf("\nPress any key....."); return; } for(i=1;i<=3;i++) { if(pos_for_O[i][1]==1 && pos_for_O[i][2]==1 && pos_for_O[i][3]==1) { win=1; printf("\n\nRESULT: %s wins!!",name_O); printf("\nPress any key....."); return; } } for(i=1;i<=3;i++) {
if(pos_for_O[1][i]==1 && pos_for_O[2][i]==1 && pos_for_O[3][i]==1) { win=1; printf("\n\nRESULT: %s wins!!",name_O); printf("\nPress any key....."); return; } } if(pos_for_O[1][1]==1 && pos_for_O[2][2]==1 && pos_for_O[3][3]==1) { win=1; printf("\n\nRESULT: %s wins!!",name_O); printf("\nPress any key....."); return; } else if(pos_for_O[1][3]==1 && pos_for_O[2][2]==1 && pos_for_O[3][1]==1) { win=1; printf("\n\nRESULT: %s wins!!",name_O); printf("\nPress any key....."); return; } }
void check() { int i,j; for(i=1;i<=3;i++) { for(j=1;j<=3;j++) { if(pos_marked[i][j]==1) chk++; else continue; } } }
BIBLIOGRAPHY
References: 1. Interactive Computer Graphics 2. Theory & Problems of Computer Graphics 3. Computer Graphics 4. Computer Graphics and Multimedia Application 5.Mastering Turbo C 6.Fundamentals of Interactive Computer Graphics
Submitted by: Jaspreet Kaur Rollno. Simran Kaur Rollno. Jasleen Kaur Rollno.