Final Exam Project

I am going to give you a fairly simple programming project for your final exam in this course. The lab involves no graphics, and is a relatively easy console version of this classic game. We will not use anything fancy, like artificial intelligence to get the computer to play one side. Instead, you will play both sides to prove your game works!

While it would be fun to build a shoot-em-up space alien game, that is probably a bit too involved for this point in your programming career. So, let’s try a simple variant of:

Tic-Tac-Toe

For our version of this game, we are just going to set up a simple display so we can record the game on the screen and see who won. This should be fairly simple, so don’t get too worried about the task.

The basic playing field

We want to display a simple board where we will place the ‘’‘X’‘’ and ‘’‘O’‘’ symbols. Since these are characters, we will set up a simple module that draws the board, with a symbol where it should go, or a blank character if no symbol has been placed in that particular position. (Actually, we will not put blanks in the drawing, see below).

 | |
-----
 | |
-----
 | |

This drawing is just a bunch of characters: vertical bars for the vertical lines, and dashes for the horizontal lines. There are blanks showing where the players would put a symbol, but we will do something different with those spaces in a moment. Since there are nine spots where a symbol could go, we will set up an array of nine characters, and fill in one of those spots with an ‘’‘X’‘’ of ‘’‘O’‘’ as the game is played.

Playing the game

To make playing the game easy, let’s number the spaces - like so:

1|2|3
-----
4|5|6
-----
7|8|9

All we need to do is ask the player to select the numbered space where they want to place their symbol. Once they provide the number, we figure out how to update the board array to show their character in the right space.

If you have your board display module set up, and replace the chosen number with the right symbol, redrawing the display will show the new game situation. (Note that you just print out a new board, you do not have to write over the old board in this game,)

Checking for wins

Now, how do we tell if the game has been won. There are several possibilities, right. Assuming you know how this game is played, we need to check for a number of situations. Like this:

if ((board[0] == 'X') && (board[1] == 'X') && (board[2] == X)) {
    // looks like a win
}

In this example, the nine spots where players can choose to place their marker are stored in an array of characters named “board”.

Obviously there is a bit more to this, but you should get the picture.

Your task

Write a program that lets two players play the game until one wins. The first player will place X markers on the board, then the next player will place the O markers. Your program should show the board for each turn and ask each player to place their marker (you should tell them which marker to place on each turn). After each move is made, check the board to see if the current player won the game. If so, announce a winner, and end the game. If all the spaces are filled and no one won, we should tell the played that they tied (a draw).

Pay attention to good style in your code. By now you should know whay nicely presented code looks like, and I will be looking for this. I will compile your program, play a simple game or two, then check to see that it looks good before assigning a final grade. If it does not compile, you will not get a good grade. Use the “baby steps” approach to putting this together, and test often. DO not sit down and try to blast the entire program together before even running that. That is not how you should be approaching problem solveing!

Project Report

I want a short document (written in something like Microsoft Word) to be included with your code. That report should include a description of each module you wrote for this project, and why you decided to create the module. I am interested in hearing how you designed the final project. You can include the actual program code in this report if you like.

What to turn in

Your program and report are due by Sunday at midnight, Dec 13 (the official end of this term). Upload the program code to Blackboard by that time.

You will get partial credit for your work, even if the game does not run correctly. Just document what you were trying to do, and Why you think your program has problems. Turn it in and I will grade the code you wrote plus your report to assign the final grade for this exam.

Have fun with this, many students before you have managed to get this done nicely!