ESc 014

Assignment 2 -- X's and O's
Due: Tuesday, April 16, 2002

Objectives

Your Mission

Your task is to write a program that will play 2-player tic-tac-toe. Two users will take turns placing an X or an O on a 3 X 3 grid. The first player to create three Xs or three Os in a row either horizontally, vertically, or diagonally wins. A tie results if all spaces are filled without a winner.

The Algorithm

The basic procedure for playing a game of tic-tac-toe is as follows:

Sample Output

Here is what your output should look like for the first couple of moves of the game. It need not be exactly like this, but it gives you an idea of what needs to be included.

| | | |
_______
| | | |
_______
| | | |
_______
it is X's turn.

What row (1-3)? 1
What column (1-3)? 2

| |X| |
_______
| | | |
_______
| | | |
_______
it is O's turn.

What row (1-3)? 3
What column (1-3)? 3

| |X| |
_______
| | | |
_______
| | |O|
_______
it is X's turn.

What row (1-3)?

The Details

You are required to use a two-dimensional array for the game board. You are also not allowed to "ignore" index 0. Use it! You should also use nested loops whenever possible for traversing the slots of the game board. This will keep you from having to type the same code over and over. In order to figure out whether you should be using a loop or not in a certain place in your program, ask yourself the following: if you wanted to change your program to play tic-tac-toe on a 4 X 4 grid (4-in-a-row to win), or a 10 X 10 grid (10-in-a-row to win), how much work would be required to change your program? Loops should allow you to make such changes very easily. You will lose a significant number of points for inefficient code that does not use loops effectively.

Remember to use functions to break up this problem into smaller pieces. Here are some of the functions you may consider using:

You may use other functions as well.

Extra Credit alert: I've given you the minimum requirements for this program, but there is a lot of room for enhancement. Here are some ideas that will net you extra credit:

Grading

This assignment is worth 50 points, divided as follows:

Remember to turn in both a paper and an electronic copy of your project on BlackBoard. Name your file with your FULL NAME along with the assignment number (e.g. chrisfernandes_hw2.cpp)

Having trouble? Don't wait until the last minute! Come see me and get your $80 worth.

Administrative statement

Programming assignments are individual projects. I encourage you to talk to others about the general nature of the project and ideas about how to pursue it. However, the technical work, the writing, and the inspiration behind these must be substantially your own. If any person besides you contributes in any way to the project, you must credit their work on your homework. Similarly, if you include information that you have gleaned from other published sources, you must cite them as references. Looking at, and/or copying, other people's programs or written work is inappropriate, and will be considered cheating.
Return to Assignment Index