This is the final report showing all the work put into Mark Smith and Trevor Snaith's noughts and crosses program, for this semesters work. The report includes the aims throughout the project, which is to produce a noughts and crosses programme in "C", the problems which we encountered during writing the program and how we solved them. It shows the results of our noughts and crosses program including some printout from the program and an explanation of how the programme works. It also shows some improvements on how the programme could be made better, and a conclusion.
To develop a "C" program that allows two people to play "noughts and crosses. The computer must decide when the game has been won and by whom, or whether the game has been drawn. The computer should display the board after each move.
When the programme is first run the opening screen appears as below:-
This opening screen is put together using a series of "printf" functions. It asks the user if they wish to play, if the user decides to play they key in number one. The one is stored as an integer in a box called "play". Using an if statement, if play is equal to one then this follows:-
Once the one is pressed then the rules appear and using a printf statement to bring up "Player 1 (x) please enter your first name", Mark the first player then enters his name which is stored using a scanf statement. Once his name has been entered and the carriage return button is pressed then "Player 2 (o) please enter your first name" appears. Trevor the second player enters his name, which is also stored as a scanf statement. Once the carriage return is pressed the following appears:-
"Mark will go first" appears using a printf statement. Before the board appears the computer checks using a while statement to see if there is a win for "x - Mark", "0 - Trevor" or a draw, if none of these statements are true then the board is displayed and "Mark please enter a row number and press enter" appears. Mark goes first and enters in a row number followed by a column number, the computer checks to see if the space is occupied or not, if the box is occupied then "please enter a valid move" appears (See problems part). If the box is not occupied then the computer displays a new board with an "X" in the appropriate box and "Trevor please enter the row number and press enter" appears.
Before "Trevor please enter the row number and press enter" the computer checks for another win or draw and then prints the printf statement. Trevor enters his row and column, the computer checks to see if it is a valid move, then displays the "O" in the appropriate box. The computer then prompts Mark to take his go after checking for a win or a draw..
This sequence of events continues to occur until either there is a win by one of the two players or a draw. When a win or a draw occurs then the comparer prints out "Player "X" wins Mark is far superior than Trevor" or "Player "O" wins. Trevor is far superior than Mark", if it is a draw then it prints out "Sorry this game is a draw".
Then the programme ends.
The board is a set of printf statements with a series of numbers, lines and %c's
printf (" COLUMNSnn");
printf ("   n");
printf ("n  %c | %c | %c n", grid  , grid  , grid   );
printf ("R ---| --- |----n");
printf ("O  %c | %c | %c n", grid  , grid  , grid   );
printf ("W ---| --- |----n");
printf ("  %c | %c | %c n", grid  , grid  , grid   );
There are three rows with three %c's in each of them, all of which have been given grid arrays so all the %c have been given a particular grid reference once a %c has been given a character it remains there till the programme finishes. The character can not be changed once a character has been placed there because of an if statement after the code which allows the player to make a move.
Please join StudyMode to read the full document