Introduction to C - Programming Assignment #6



Introduction to C - Programming Assignment #6

Assigned: 11/16/06, Thursday

Due: 11/30/06, Thursday at 3:00am WebCT Time - NO LATE PROGRAMS!!!

Objective

1. To give students practice using structs.

2. To give students practice using and understanding pre-written code.

3. To create an application that utilizes many of the constructs which have been taught throughout the course.

Problem: Scrabble

Although implementing a full-blown version of the popular board game Scrabble is beyond the scope of this class, you will be asked to add to a program that completes some of the similar tasks that are necessary to write a Scrabble program. If you are not familiar with the rules of Scrabble, then please go to the following website:



Your goal will be to write two functions and edit a third. Your two functions will do the following:

1) Given a list of tiles the user has, and a word they want to enter, determine whether or not the user has the tiles to form the desired word.

2) Given the word the user wants to put on the board, and the specification for where on the board the user wants to place the word, you need to determine the number of points the word scores by itself. (You will be placing the word on an empty board, but unlike the real game, you will not be constrained in where to place the word on the board.) Note: You will never actually place the word on the board, or replace the user's tiles.

A code skeleton is posted on-line. The skeleton completes the following tasks:

1) Creates a bag of tiles.

2) Creates the game board marking all the special squares (double letter, triple letter, double word, triple word).

3) Chooses 7 tiles randomly from the bag for the user's "hand."

You will need to add functionality to do the two tasks listed above. In particular, in the code skeleton, you must completely write the two following functions:

// Checks if all the letters in word appear in tiles.

// Returns 1 if the letters are there, 0 otherwise.

int valid(struct tile tiles[], char word[]);

// Returns the score of playing word on the myscrabble board if we position

// word at coordinates x,y, and moving in direction.

int getWordScore(char word[], char myscrabble[][SIZE], int x, int y, int direction);

You will also have to fill in a few lines of the function

// Processes a case where tiles stores the users tiles, length is the length

// of the tiles array, and scrabble is the representation of the board.

void processCase(struct tile tiles[], int length, char scrabble[][SIZE]);

Rather than explain further details, the goal of the assignment is for you to closely examine the code that is already written so that you can figure out how to fill in the missing pieces. A couple sample runs have been included below so you have a clear idea of how the program should behave, in general. These sample runs do not cover all possible scoring issues. However, they illustrate the general format of how your program should run.

List of things not implemented (so don't worry about these issues)

1. No need to check if the word entered is actually in the dictionary.

2. No need to check if the user entered a word in all upper case letters. Assume they have.

3. Assume that the user always properly enters 0 or 1 for the direction.

4. Assume that the user always enters integers for the x and y coordinates of the upper left-hand corner of the word.

References

Textbook: Chapters 9, 10, 12 Notes: Lectures on arrays, strings and structs

Web site:

Restrictions

Rename the file you download, edit and turn in scrabble.c. Although you may use other compilers, your program must compile and run using Dev C++ or gcc. If you use your olympus account to work on this assignment, please follow the steps shown in class to create, compile, and test your program. Your program should include a header comment with the following information: your name, course number, section number, assignment title, and date. You should also include comments throughout your code, when appropriate. If you have any questions about this, please see a TA.

Deliverables

A single source file named scrabble.c turned in through WebCT.

Sample Run #1

Here is a print out of the scrabble board with row and column

numbers as well as the locations of all of the special squares.

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

0 T _ _ d _ _ _ T _ _ _ d _ _ T

1 _ D _ _ _ t _ _ _ t _ _ _ D _

2 _ _ D _ _ _ d _ d _ _ _ D _ _

3 d _ _ D _ _ _ d _ _ _ D _ _ d

4 _ _ _ _ D _ _ _ _ _ D _ _ _ _

5 _ t _ _ _ t _ _ _ t _ _ _ t _

6 _ _ d _ _ _ d _ d _ _ _ d _ _

7 T _ _ d _ _ _ D _ _ _ d _ _ T

8 _ _ d _ _ _ d _ d _ _ _ d _ _

9 _ t _ _ _ t _ _ _ t _ _ _ t _

10 _ _ _ _ D _ _ _ _ _ D _ _ _ _

11 d _ _ D _ _ _ d _ _ _ D _ _ d

12 _ _ D _ _ _ d _ d _ _ _ D _ _

13 _ D _ _ _ t _ _ _ t _ _ _ D _

14 T _ _ d _ _ _ T _ _ _ d _ _ T

Here are your tiles, letter & score: T 1, N 1, T 1, L 1, F 4, S 1, R 1

Please enter a word you would like to form.

HELLO

Sorry, you do not have the tiles to make that word.

Sample Run #2

Here is a print out of the scrabble board with row and column

numbers as well as the locations of all of the special squares.

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

0 T _ _ d _ _ _ T _ _ _ d _ _ T

1 _ D _ _ _ t _ _ _ t _ _ _ D _

2 _ _ D _ _ _ d _ d _ _ _ D _ _

3 d _ _ D _ _ _ d _ _ _ D _ _ d

4 _ _ _ _ D _ _ _ _ _ D _ _ _ _

5 _ t _ _ _ t _ _ _ t _ _ _ t _

6 _ _ d _ _ _ d _ d _ _ _ d _ _

7 T _ _ d _ _ _ D _ _ _ d _ _ T

8 _ _ d _ _ _ d _ d _ _ _ d _ _

9 _ t _ _ _ t _ _ _ t _ _ _ t _

10 _ _ _ _ D _ _ _ _ _ D _ _ _ _

11 d _ _ D _ _ _ d _ _ _ D _ _ d

12 _ _ D _ _ _ d _ d _ _ _ D _ _

13 _ D _ _ _ t _ _ _ t _ _ _ D _

14 T _ _ d _ _ _ T _ _ _ d _ _ T

Here are your tiles, letter & score: R 1, R 1, N 1, N 1, D 4, N 1, O 1

Please enter a word you would like to form.

NOR

Where would you like to place the word?

Enter the starting row coordinate(0-14).

0

Enter the starting column coordinate(0-14).

1

Would you like the word going down(0) or across(1)?

0

The score of your word is 6.

Sample Run #3

Here is a print out of the scrabble board with row and column

numbers as well as the locations of all of the special squares.

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

0 T _ _ d _ _ _ T _ _ _ d _ _ T

1 _ D _ _ _ t _ _ _ t _ _ _ D _

2 _ _ D _ _ _ d _ d _ _ _ D _ _

3 d _ _ D _ _ _ d _ _ _ D _ _ d

4 _ _ _ _ D _ _ _ _ _ D _ _ _ _

5 _ t _ _ _ t _ _ _ t _ _ _ t _

6 _ _ d _ _ _ d _ d _ _ _ d _ _

7 T _ _ d _ _ _ D _ _ _ d _ _ T

8 _ _ d _ _ _ d _ d _ _ _ d _ _

9 _ t _ _ _ t _ _ _ t _ _ _ t _

10 _ _ _ _ D _ _ _ _ _ D _ _ _ _

11 d _ _ D _ _ _ d _ _ _ D _ _ d

12 _ _ D _ _ _ d _ d _ _ _ D _ _

13 _ D _ _ _ t _ _ _ t _ _ _ D _

14 T _ _ d _ _ _ T _ _ _ d _ _ T

Here are your tiles, letter & score: R 1, R 1, N 1, N 1, D 4, N 1, O 1

Please enter a word you would like to form.

NOR

Where would you like to place the word?

Enter the starting row coordinate(0-14).

13

Enter the starting column coordinate(0-14).

14

Would you like the word going down(0) or across(1)?

0

Sorry, the word doesn't fit on the board.

Sample Run #4

Here is a print out of the scrabble board with row and column

numbers as well as the locations of all of the special squares.

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

0 T _ _ d _ _ _ T _ _ _ d _ _ T

1 _ D _ _ _ t _ _ _ t _ _ _ D _

2 _ _ D _ _ _ d _ d _ _ _ D _ _

3 d _ _ D _ _ _ d _ _ _ D _ _ d

4 _ _ _ _ D _ _ _ _ _ D _ _ _ _

5 _ t _ _ _ t _ _ _ t _ _ _ t _

6 _ _ d _ _ _ d _ d _ _ _ d _ _

7 T _ _ d _ _ _ D _ _ _ d _ _ T

8 _ _ d _ _ _ d _ d _ _ _ d _ _

9 _ t _ _ _ t _ _ _ t _ _ _ t _

10 _ _ _ _ D _ _ _ _ _ D _ _ _ _

11 d _ _ D _ _ _ d _ _ _ D _ _ d

12 _ _ D _ _ _ d _ d _ _ _ D _ _

13 _ D _ _ _ t _ _ _ t _ _ _ D _

14 T _ _ d _ _ _ T _ _ _ d _ _ T

Here are your tiles, letter & score: R 1, R 1, N 1, N 1, D 4, N 1, O 1

Please enter a word you would like to form.

NOR

Where would you like to place the word?

Enter the starting row coordinate(0-14).

-1

Enter the starting column coordinate(0-14).

3

Would you like the word going down(0) or across(1)?

0

Sorry, the word doesn't fit on the board.

Sample Run #5

Here is a print out of the scrabble board with row and column

numbers as well as the locations of all of the special squares.

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

0 T _ _ d _ _ _ T _ _ _ d _ _ T

1 _ D _ _ _ t _ _ _ t _ _ _ D _

2 _ _ D _ _ _ d _ d _ _ _ D _ _

3 d _ _ D _ _ _ d _ _ _ D _ _ d

4 _ _ _ _ D _ _ _ _ _ D _ _ _ _

5 _ t _ _ _ t _ _ _ t _ _ _ t _

6 _ _ d _ _ _ d _ d _ _ _ d _ _

7 T _ _ d _ _ _ D _ _ _ d _ _ T

8 _ _ d _ _ _ d _ d _ _ _ d _ _

9 _ t _ _ _ t _ _ _ t _ _ _ t _

10 _ _ _ _ D _ _ _ _ _ D _ _ _ _

11 d _ _ D _ _ _ d _ _ _ D _ _ d

12 _ _ D _ _ _ d _ d _ _ _ D _ _

13 _ D _ _ _ t _ _ _ t _ _ _ D _

14 T _ _ d _ _ _ T _ _ _ d _ _ T

Here are your tiles, letter & score: I 1, b 0, O 1, R 1, R 4, E 1, E 1

Please enter a word you would like to form.

VEER

Where would you like to place the word?

Enter the starting row coordinate(0-14).

11

Enter the starting column coordinate(0-14).

3

Would you like the word going down(0) or across(1)?

0

The score of your word is 8.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download