e Character Soup game is a computer vs human game that uses the ASCII table to generate a soup (random string),

Description


Unformatted Attachment Preview

Don't use plagiarized sources. Get Your Custom Assignment on
e Character Soup game is a computer vs human game that uses the ASCII table to generate a soup (random string),
From as Little as $13/Page

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. ‘’).
• Each char in a soup is different from each other.
Example of an invalid Number soup: “0132451125”
• A soup with all consecutive char values is considered invalid: e.g. “0123456789”
• Mixed soup chars are ASCII values in [33-126].
• Alphabet soup chars include [‘a’-‘z’,’A’-‘Z’].
• Number soup chars include [‘0’-‘9’].
• The soup code in a Number soup concatenates the ASCII (2 digits) of each char.
Example: “3951206784” Code: 51575349504854555652
• The soup code in a Mixed or Alphabet soup concatenates the ASCII (3 digits) of each char.
E.g., the code for ‘%’ is 037, not 37.
Note: 037 is NOT an octal, it is just the code to represent that character in the soup.
Makefile:
Create a Makefile and include the following macros.
CC = gcc
CFLAGS = -g -Wall -std=c99 -pedantic-errors
TARGET = p1__
Create a target for the gcc command as follows:
$(TARGET): $(TARGET).c
Edit the command to create the executable as follows:
$(CC) $(TARGET).c -o $(TARGET) $(CFLAGS)
Additionally, create a clean target to remove the executable using the TARGET macro.
Submission:
1. On zeus, create a directory named p1__
a. Your source file and Makefile must be in this directory
b. The name of the source file must be p1__.c
2. Create a typescript with the following content:
a. Show that you are on zeus
b. Show a listing of your directory
c. Show your source code
d. Compile the code using the Makefile
e. Run your program and select a not valid option, then, select Number soup and
complete the game. Finally, return to the menu and quit your program.
f. Terminate the typescript.
3. Make sure your directory only contains the source file, typescript and Makefile.
4. Create the p1__.tar tarfile of your project directory.
5. Submit this tarfile to Blackboard no later than the due date.
Congratulations, you have finished your assignment!
4/9
CS262: Introduction to low-level programming
George Mason University
Professors: González Hernández, Andrea, Mughal
Run Example:
**********************************
*
Welcome to Character Soup *
**********************************
Player’s name: Peter Parker
1. Mixed soup
2. Alphabet soup
3. Number soup
4. Quit
Select an option: 0
Option 0 is not valid!
Select an option: 6
Option 6 is not valid!
Select an option: 3
****************************
*
Number soup
*
****************************
Peter Parker,
match points: 0 round points: 0
Computer,
match points: 0 round points: 0
[Play]
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]
Round: 2/10
Soup: “9857230641”
Soup code: 57565355505148545249
************************************
5/9
CS262: Introduction to low-level programming
George Mason University
Professors: González Hernández, Andrea, Mughal
Peter Parker’s soup: “5378046912”
Soup code: 53515556485254574950
Match: 0
[———-]
Computer’s soup: “2479056813”
Soup code: 50525557485354564951
Match: 0
[———-]
Peter Parker,
match points: 0 round points: 2
Computer, match points: 8 round points: 7
[Continue]
Round: 3/10
Soup: “6147523890”
Soup code: 54495255535051565748
************************************
Peter Parker’s soup: “4107926853”
Soup code: 52494855575054565351
Match: 4
[-X-X-X-X–]
Computer’s soup: “6173245908”
Soup code: 54495551505253574856
Match: 2
[XX——–]
Peter Parker,
match points: 4 round points: 7
Computer, match points: 10 round points: 7
[Continue]
Round: 4/10
Soup: “4812576039”
Soup code: 52564950535554485157
************************************
Peter Parker’s soup: “7534908612”
Soup code: 55535152574856544950
Match: 0
[———-]
Computer’s soup: “7198260453”
Soup code: 55495756505448525351
Match: 0
[———-]
Peter Parker,
match points: 4 round points: 9
Computer, match points: 10 round points: 9
[Continue]
Round: 5/10
Soup: “3698751042”
Soup code: 51545756555349485250
6/9
CS262: Introduction to low-level programming
George Mason University
Professors: González Hernández, Andrea, Mughal
************************************
Peter Parker’s soup: “0748695231”
Soup code: 48555256545753505149
Match: 1
[—X——]
Computer’s soup: “9012653487”
Soup code: 57484950545351525655
Match: 1
[—–X—-]
Peter Parker,
match points: 5 round points: 11
Computer, match points: 11 round points: 11
[Continue]
Round: 6/10
Soup: “5791068234”
Soup code: 53555749485456505152
************************************
Peter Parker’s soup: “7458092316”
Soup code: 55525356485750514954
Match: 1
[—-X—–]
Computer’s soup: “3651847902”
Soup code: 51545349565255574850
Match: 1
[—X——]
Peter Parker,
match points: 6 round points: 13
Computer, match points: 12 round points: 13
[Continue]
Round: 7/10
Soup: “7851639204”
Soup code: 55565349545157504852
************************************
Peter Parker’s soup: “5132846970”
Soup code: 53495150565254575548
Match: 0
[———-]
Computer’s soup: “6107985324”
Soup code: 54494855575653515052
Match: 1
[———X]
Peter Parker,
match points: 6 round points: 13
Computer, match points: 13 round points: 18
[Continue]
Round: 8/10
7/9
CS262: Introduction to low-level programming
George Mason University
Professors: González Hernández, Andrea, Mughal
Soup: “0647189352”
Soup code: 48545255495657515350
************************************
Peter Parker’s soup: “1832496705”
Soup code: 49565150525754554853
Match: 0
[———-]
Computer’s soup: “8496035127”
Soup code: 56525754485153495055
Match: 0
[———-]
Peter Parker,
match points: 6 round points: 15
Computer, match points: 13 round points: 20
[Continue]
Round: 9/10
Soup: “6594837120”
Soup code: 54535752565155495048
************************************
Peter Parker’s soup: “1807234659”
Soup code: 49564855505152545357
Match: 1
[—–X—-]
Computer’s soup: “5681704932”
Soup code: 53545649554852575150
Match: 0
[———-]
Peter Parker,
match points: 7 round points: 20
Computer, match points: 13 round points: 20
[Continue]
Round: 10/10
Soup: “7198542603”
Soup code: 55495756535250544851
************************************
Peter Parker’s soup: “3902148657”
Soup code: 51574850495256545355
Match: 2
[—–X-X–]
Computer’s soup: “4301857269”
Soup code: 52514849565355505457
Match: 0
[———-]
Peter Parker,
match points: 9 round points: 25
Computer, match points: 13 round points: 20
[Continue]
8/9
CS262: Introduction to low-level programming
George Mason University
Professors: González Hernández, Andrea, Mughal
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]
**********************************
*
Welcome to Character Soup *
**********************************
Player’s name: Peter Parker
1. Mixed soup
2. Alphabet soup
3. Number soup
4. Quit
Select an option: 4
Thank you for playing Character Soup! Good Bye
9/9
CS262: Introduction to low-level programming
George Mason University
Professors: González Hernández, Andrea, Mughal
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. ‘’).
• Each char in a soup is different from each other.
Example of an invalid Number soup: “0132451125”
• A soup with all consecutive char values is considered invalid: e.g. “0123456789”
• Mixed soup chars are ASCII values in [33-126].
• Alphabet soup chars include [‘a’-‘z’,’A’-‘Z’].
• Number soup chars include [‘0’-‘9’].
• The soup code in a Number soup concatenates the ASCII (2 digits) of each char.
Example: “3951206784” Code: 51575349504854555652
• The soup code in a Mixed or Alphabet soup concatenates the ASCII (3 digits) of each char.
E.g., the code for ‘%’ is 037, not 37.
Note: 037 is NOT an octal, it is just the code to represent that character in the soup.
Makefile:
Create a Makefile and include the following macros.
CC = gcc
CFLAGS = -g -Wall -std=c99 -pedantic-errors
TARGET = p1__
Create a target for the gcc command as follows:
$(TARGET): $(TARGET).c
Edit the command to create the executable as follows:
$(CC) $(TARGET).c -o $(TARGET) $(CFLAGS)
Additionally, create a clean target to remove the executable using the TARGET macro.
Submission:
1. On zeus, create a directory named p1__
a. Your source file and Makefile must be in this directory
b. The name of the source file must be p1__.c
2. Create a typescript with the following content:
a. Show that you are on zeus
b. Show a listing of your directory
c. Show your source code
d. Compile the code using the Makefile
e. Run your program and select a not valid option, then, select Number soup and
complete the game. Finally, return to the menu and quit your program.
f. Terminate the typescript.
3. Make sure your directory only contains the source file, typescript and Makefile.
4. Create the p1__.tar tarfile of your project directory.
5. Submit this tarfile to Blackboard no later than the due date.
Congratulations, you have finished your assignment!
4/9
CS262: Introduction to low-level programming
George Mason University
Professors: González Hernández, Andrea, Mughal
Run Example:
**********************************
*
Welcome to Character Soup *
**********************************
Player’s name: Peter Parker
1. Mixed soup
2. Alphabet soup
3. Number soup
4. Quit
Select an option: 0
Option 0 is not valid!
Select an option: 6
Option 6 is not valid!
Select an option: 3
****************************
*
Number soup
*
****************************
Peter Parker,
match points: 0 round points: 0
Computer,
match points: 0 round points: 0
[Play]
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]
Round: 2/10
Soup: “9857230641”
Soup code: 57565355505148545249
************************************
5/9
CS262: Introduction to low-level programming
George Mason University
Professors: González Hernández, Andrea, Mughal
Peter Parker’s soup: “5378046912”
Soup code: 53515556485254574950
Match: 0
[———-]
Computer’s soup: “2479056813”
Soup code: 50525557485354564951
Match: 0
[———-]
Peter Parker,
match points: 0 round points: 2
Computer, match points: 8 round points: 7
[Continue]
Round: 3/10
Soup: “6147523890”
Soup code: 54495255535051565748
************************************
Peter Parker’s soup: “4107926853”
Soup code: 52494855575054565351
Match: 4
[-X-X-X-X–]
Computer’s soup: “6173245908”
Soup code: 54495551505253574856
Match: 2
[XX——–]
Peter Parker,
match points: 4 round points: 7
Computer, match points: 10 round points: 7
[Continue]
Round: 4/10
Soup: “4812576039”
Soup code: 52564950535554485157
************************************
Peter Parker’s soup: “7534908612”
Soup code: 55535152574856544950
Match: 0
[———-]
Computer’s soup: “7198260453”
Soup code: 55495756505448525351
Match: 0
[———-]
Peter Parker,
match points: 4 round points: 9
Computer, match points: 10 round points: 9
[Continue]
Round: 5/10
Soup: “3698751042”
Soup code: 51545756555349485250
6/9
CS262: Introduction to low-level programming
George Mason University
Professors: González Hernández, Andrea, Mughal
************************************
Peter Parker’s soup: “0748695231”
Soup code: 48555256545753505149
Match: 1
[—X——]
Computer’s soup: “9012653487”
Soup code: 57484950545351525655
Match: 1
[—–X—-]
Peter Parker,
match points: 5 round points: 11
Computer, match points: 11 round points: 11
[Continue]
Round: 6/10
Soup: “5791068234”
Soup code: 53555749485456505152
************************************
Peter Parker’s soup: “7458092316”
Soup code: 55525356485750514954
Match: 1
[—-X—–]
Computer’s soup: “3651847902”
Soup code: 51545349565255574850
Match: 1
[—X——]
Peter Parker,
match points: 6 round points: 13
Computer, match points: 12 round points: 13
[Continue]
Round: 7/10
Soup: “7851639204”
Soup code: 55565349545157504852
************************************
Peter Parker’s soup: “5132846970”
Soup code: 53495150565254575548
Match: 0
[———-]
Computer’s soup: “6107985324”
Soup code: 54494855575653515052
Match: 1
[———X]
Peter Parker,
match points: 6 round points: 13
Computer, match points: 13 round points: 18
[Continue]
Round: 8/10
7/9
CS262: Introduction to low-level programming
George Mason University
Professors: González Hernández, Andrea, Mughal
Soup: “0647189352”
Soup code: 48545255495657515350
************************************
Peter Parker’s soup: “1832496705”
Soup code: 49565150525754554853
Match: 0
[———-]
Computer’s soup: “8496035127”
Soup code: 56525754485153495055
Match: 0
[———-]
Peter Parker,
match points: 6 round points: 15
Computer, match points: 13 round points: 20
[Continue]
Round: 9/10
Soup: “6594837120”
Soup code: 54535752565155495048
************************************
Peter Parker’s soup: “1807234659”
Soup code: 49564855505152545357
Match: 1
[—–X—-]
Computer’s soup: “5681704932”
Soup code: 53545649554852575150
Match: 0
[———-]
Peter Parker,
match points: 7 round points: 20
Computer, match points: 13 round points: 20
[Continue]
Round: 10/10
Soup: “7198542603”
Soup code: 55495756535250544851
************************************
Peter Parker’s soup: “3902148657”
Soup code: 51574850495256545355
Match: 2
[—–X-X–]
Computer’s soup: “4301857269”
Soup code: 52514849565355505457
Match: 0
[———-]
Peter Parker,
match points: 9 round points: 25
Computer, match points: 13 round points: 20
[Continue]
8/9
CS262: Introduction to low-level programming
George Mason University
Professors: González Hernández, Andrea, Mughal
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]
**********************************
*
Welcome to Character Soup *
**********************************
Player’s name: Peter Parker
1. Mixed soup
2. Alphabet soup
3. Number soup
4. Quit
Select an option: 4
Thank you for playing Character Soup! Good Bye
9/9
CS262: Introduction to low-level programming
George Mason University
Professors: González Hernández, Andrea, Mughal

Purchase answer to see full
attachment