CSc 3320

Programming project #3

DUE DATE: October 23, 2002

Objectives

1. Learning about shell scripts: conditional programming, list processing, and other materials discussed in chapter 6.

2. Writing a C-shell script

3. Setting up an utility program with command-line parameters.

Introduction

Your assignment is given below. To solve it, write a program that reads the necessary information to compute and output the indicated values, as efficiently as possible. First, design your program by specifying its behavior, identifying the objects and operations it needs to solve the problem, and then organizing the objects and operations into an algorithm. Then code your design as a C-shell script using stepwise translation. Finally, test your program thoroughly.

Project

1. Your program will allow two people to play tic-tac-toe. The game will be explained in class briefly. If you do not know how this game works, see the instructor or teaching assistant.
2. INPUT: Your program will need to know the names of the two players. Input can come from the command line OR if the program is invoked without parameters, it should use standard input (for the users' names). Your program will also need to read in the players' moves. If the user enters a bad number (e.g. 0), prompt the user again. Do not allow the user to select a spot that already has an X or O on it.

INPUT PARAMETERS:

·  The first parameter passed by the user is the first player's (X) name.

·  The second parameter passed by the user is the second player's (O) name.

·  Do not expect the "-" character.

·  If one parameter is passed, ask for the second player's name.

·  If no parameters are passed, ask for both player's names (one at a time).

·  If more than 2 parameters are passed, ignore the rest.


3. OUTPUT: Echo a welcome message to the players. Output the board in an easy-to-read fashion. Clearly prompt the users for their moves. Indicate who wins, or if the game is a tie.
Use digits 1..9 to mark open spots on the board. Put a capital X or O on the board as these spots are taken.

4. EXAMPLES:

VLSI% hmwk3.sh
Player 1 please enter your name: Fred
hi Fred, you will have X

Player 2 please enter your name: Barney
hi Barney, you will have O

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

Your move Fred? ^C
Thanks for playing.

VLSI% hmwk3.sh Wilma Betty
hi Wilma, you will have X

hi Betty, you will have O

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

Your move Wilma ? 5

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

Your move Betty ? 2
<stuff deleted>
| |
1 | O | 3
| |
------
| |
X | X | 6
| |
------
| |
O | 8 | 9
| |

Your move Wilma ? 6
| |
1 | O | 3
| |
------
| |
X | X | 6
| |
------
| |
O | 8 | 9
| |

We have a winner. Congratulations Wilma.

5. See page 201 of your Unix book. Include a section of code to handle control-C.

6. Name your source file 'assign3.csh' and store it in your home directory.

7. Be sure to include the header information as comments at the top of your source file.
#!/bin/csh
#
# assign3.csh
#
# Author: Your Name
# Account: your account number
# CSc 3320
# Program #23
# Due date: XXXX
#
# Description:
# Give a brief description of what your program does.
#
# Input:
# State what the program inputs are.
#
# Output:
# State what the program outputs are.

8. As you are aware certain types of assistance are inappropriate in this class. Read the collaboration policy given to you at the beginning of the semester, if you have any questions.

9. Follow program standards as presented in class and in your book. Pay special attention to comments, identifier style, and consistent 3-space indentation. You should indent your code as you normally would.

10. Turn In Hard Copies of your source code, your input files and the corresponding output files from three different executions in which you test the correctness of your program (using a script).

Use script assign3.log to record all things you type and the responses from the system. "assign3.log” is just the name of the file it creates. After finishing the recording, type CTRL-D to exit from your script session.