Description
Unformatted Attachment Preview
CS262, Project 1
Character Soup
Due: Sunday, Mar 03 at 11:59 pm ET
In this project, you will code in C the game Character Soup, in which two players compete, trying
to have the most matches with a soup (randomly generated string). This project serves to reinforce
the C fundamentals, control flow, functions, arrays, and random number generation.
It is important to review the rand() and srand() functions and understand how to generate
random numbers in an interval because they are widely used for this implementation.
Overview:
ASCII stands for American Standard Code for Information Interchange. The range of the ASCII
table is 0-127, where number is associated with a specific character, which can be: letter, number,
symbol, or non-printable character.
The Character Soup game is a computer vs human game that uses the ASCII table to generate
a soup (random string), whose characters can be mixed, only letters or only digits. Then, for 10
rounds, opponents compete to earn points based on how many matches their randomly generated
soup has with the soup in play (match). At the end of the 10 rounds, the score of each player is
match points + round points. The player who scores the most is the winner of the game.
•
•
For a char match in the string between the soup codes, you earn one point.
Per round wins are 5 points, per tie rounds are 2 points.
Instructions:
The game displays a welcome message and asks for the player’s name, as follows:
**********************************
*
Welcome to Character Soup
*
**********************************
Player’s name:
After, a menu with these options is displayed asking to enter an option.
1. Mixed soup
2. Alphabet soup
3. Number soup
4. Quit
Select an option:
If the option is invalid (a number out of range), then an Error message is displayed, and the player
is prompted again to enter a valid option.
1/9
CS262: Introduction to low-level programming
George Mason University
Professors: González Hernández, Andrea, Mughal
Once a valid option is selected, the program shows:
• A message of the selected soup type.
• The updated score status for each player in the form:
,
match points: round points:
Computer,
match points: round points:
• The message [Play], which runs the next round.
Assume the player’s name is Peter Parker and he selects Number soup, what was described
above would be displayed as follows:
****************************
*
Number soup
*
****************************
Peter Parker, match points: 0 round points: 0
Computer,
match points: 0 round points: 0
[Play]
After selecting [Play] is displayed:
• The current round in the form Round: #/10, where # = [1-10].
• The soup (random string enclosed in “”) and its code (see Guidelines for more details).
• A line “************************************”
• Each player’s soup, soup code, match for the round soup, and a graphical match sequence
[with X or – to indicate a match or mismatch respectively].
• The updated score status.
• The message [Continue].
Example:
Round: 1/10
Soup:
“3951206784”
Soup code:
51575349504854555652
************************************
Peter Parker’s soup:
“4513967820”
Soup code:
52534951575455565048
Match: 0
[———-]
Computer’s soup:
“4951206783”
Soup code:
52575349504854555651
Match: 8
[-XXXXXXXX-]
Peter Parker, match points: 0 round points: 0
Computer, match points: 8 round points: 5
[Continue]
2/9
CS262: Introduction to low-level programming
George Mason University
Professors: González Hernández, Andrea, Mughal
After completing all 10 consecutive rounds and select [Continue] is displayed, the following
is shown:
•
•
•
•
•
Game Over
The score for each player indicating match points and round points.
If there is a winner: won this game.
If both earned the same score: The game ended in a tie.
[Return to menu].
Example:
Game Over
Peter Parker, score: 34
match points: 9 round points: 25
Computer, score: 33
match points: 13 round points: 20
Peter Parker won this game.
[Return to menu]
Required Functions:
The program must contain at least the following functions:
int menu(…)
Displays the menu with all options and retrieves user input.
int is_valid_option(…)
Checks if the menu entry is the correct range and type (int).
void score_status(…)
Prints the updated score for each player.
A function with logic for each mathematical operation
void mixed_soup (…)
void alphabet_soup (…)
void number_soup(…)
Choose the appropriate parameters (…) for each of the following functions.
You can create additional functions that help you better organize the game logic.
Guidelines:
•
•
•
•
•
Global variables are not allowed.
Include comments in your code explaining the main logic of each important part.
The player’s name can only contain letters and blank spaces and is at most 25 characters.
Initialize the random seed with srand(time(NULL)). The seed is initialized only once,
i.e., you must not call this function again during your program run.
Assume that the user input to select an option in the menu is an integer.
3/9
CS262: Introduction to low-level programming
George Mason University
Professors: González Hernández, Andrea, Mughal
Soups:
• A soup always has 10 chars (excluding the NULL terminator i.e. ‘