CS 0449 – Project 1: RPS and ID3 Tags

Due: Sunday, September 21, 2008, at 11:59pm

Your first project is to write two programs in C that provide some experience with a wide range of the topics we have been discussing in class.

Rock, Paper, Scissors (30 points)

For the first part of this project, you will be implementing the game of Rock, Paper, Scissors. For those unfamiliar with the rules, typically the game is played with two people who use hand gestures to represent a rock (closed fist), paper (an open hand), or scissor (a vee made with your fingers). Each person displays their choice at the same time and the winner is determined by (winner in bold):

Scissors cuts paper, paper covers rock, rock breaks scissors

Your job is to write a program where a human can play against the computer in a best-of-5 tournament. The first to win three games wins the match. Have the human player enter their choice, and then have the computer randomly pick its choice. If the two match, the game is a tie and doesn’t count. Otherwise you will add one to the score of the winner. After the match is over, you should ask the user if they would like to play again.

Example:

Welcome to Rock, Paper, Scissors

Would you like to play? yes

What is your choice? scissors
The computer chooses rock. You lose this game!

The score is now you: 0 computer: 1

Hints

·         Generating random numbers in C is a two-step part. First, we need to seed the random number generator once per program. The idiom to do this is:
srand((unsigned int)time(NULL));

·         When we need random numbers, we can use the rand() function. It returns an unsigned integer between 0 and RAND_MAX. We can use modulus to reduce it to the range we need:
int value = rand() % (high - low + 1) + low;

ID3 Tag Editor (70 points)

An ID3 version 1.1 tag for MP3s (and other multimedia files) adds metadata describing the file. The contents of an ID3 tag are the following:

Offset

length

description

0

3

"TAG" identifier string.

3

30

Song title string.

33

30

Artist string.

63

30

Album string.

93

4

Year string.

97

28

Comment string.

125

1

Zero byte separator.

126

1

Track number byte.

127

1

Genre identifier byte.

 

 

 

 

 

 

An ID3 (v1.1) tag like above is appended to a file as the last 128 bytes. The tag is present if at the -128 from end offset there are the three ASCII characters TAG.

What To Do

For your project you will make a utility that can print the contents of an existing tag, if there, and add or modify a tag.

Make a program called id3tagEd and make it so that it runs with the following command line options:

id3tagEd FILENAME

should print the contents of the ID3 tag to the console if present, or give a message if not present

id3tagEd FILENAME -FIELD VALUE

should set the specified field to the value that follows it. You should handle the following field names (specified in lowercase):

·         Title

·         Artist

·         Album

·         Year

·         Comment

·         Track

 

Make sure you are able to handle multiple {field, value} pairs on the command line at once. If the tag already exists in the specified file, then edit it, if not create a new tag by appending a tag at the end with the specified fields populated. Assume all others are to be empty (filled with 0s.)

Hints and Requirements

·         The strings may not have a null-terminator. Be careful that you do the right thing in these cases. Look into the strn family of functions.

·         We need to treat these files as binary files rather than text files. Make sure to open the file correctly, and to use fread and fwrite for I/O.

·         Please use a structure to represent an ID3 tag rather than a bunch of disjoint strings.

·         Note that you do NOT need to handle the genre field. Just leave it unchanged if editing, and make it 0 if making a new tag.

Submission

When you’re done, create a gzipped tarball (as we did in the first lab) of your commented source files and compiled executables and copy them to:

 ~jrmst106/submit/449/

Make sure you name the file with your username, and that you have your name in the comments of your source file.

Note that this directory is insert-only, you may not delete or modify your submissions once in the directory. If you’ve made a mistake before the deadline, resubmit with a number suffix like abc123_1.tar.gz

The highest numbered file before the deadline will be the one that is graded, however for simplicity, please make sure you’ve done all the work and included all necessary files before you submit