
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question

Transcribed Image Text:Complete the function game, which simulates a simple, turn-based game between two players and returns the winner (if there is one).
The function takes four arguments:
• m1 and m2 are strings representing the moves for players 1 and 2, respectively.
• h1 and h2 are numbers that represent the starting health of players 1 and 2, respectively.
Each character in a player's string represents a different action (Attack, Defend or Shield). Player actions and their respective character codes
are described bellow:
Character Code
A
D
B
Action
Attack
Defend
Block with Shield
Taking Turns
Each player can make one move per round. The players conti to move until they run out of moves or one (or both) players are knocked out.
How much damage each player takes per round depends on the actions of the players:
• If both players choose to Defend or Block (in any combination), neither player takes any damage.
• If both players Attack, both players take 3 points of damage.
• If a player is Defending and their opponent Attacks, the Defender takes 2 points of damage.
• If a player Blocks (with the shield) and their opponent Attacks, the Blocker takes 1 point of damage.
Return Value
The game ends when one player is knocked out (health becomes ≤0), both players are knocked out, or both players run out of moves.
If Player 1 is not knocked out, but Player 2 is knocked out, the function returns P1, followed by the hit points of each player. (e.g., P1, 5,
0)
If Player 2 is not knocked out, but Player 1 is knocked out, the function returns P2, followed by the hit points of each player. (e.g., P2, -1,
8)
• If the game ends before either player is knocked out, or if both players are knocked out, the function returns Tie, followed by the
remaining hit points of each player. (e.g., Tie, 3, 8 or Tie, -1, 0)
• If the players don't have the same number of moves in their respective strings, return Error.
Assumptions
• You may assume that the strings m1 and m2 only contain characters corresponding to valid actions.

Transcribed Image Text:Examples:
Function Call
game ('DBDDD', 'DBDBD', 2, 5)
game ('DBD', 'ABDB', 3, 3)
game ('DABDA', 'AABDA', 6, 7)
game ('AAAADD', 'DDAABA', 9, 9)
game ('AAAADD', 'DDAABA', 19, 23)
game ('ADAABADA', 'DAADADAA', 5, 5)
game ('AADAABADA', 'ADAADADAA', 6, 6)
game ('ABDAAADBBDAABDAB', 'ABDBADBAAAAAAADA', 18, 22)
game (DDBBDAAADBDBD', 'AAAAAAAADAAAA', 17, 12)
game ('DBADABAABAABADABA', 'ABDADBDBADABDADAB', 15, 9)
game ('DBADADDDDDDBADABA', 'ABDADBDBAAAAAAAAB 15,9)
"
I
Return Value
('Tie', 2, 5)
Error
('P2', -2, 1)
('P1', 3, -1)
('Tie', 11, 13)
('Tie', 0, 0)
('Tie', -2, -2)
('P2¹, -1, 7)
('P2', 0, 3)
('P1', 10, 0)
('P2¹, -1, 2)
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Computer Science I need to write a program in C that allows the user to play a game of Mystery Word, here are the requirements: The program begins with a 6-letter word which is obscured by displaying an asterisk * in the place of each letter of the word. Four 6-letter words should be included in your program and have a theme. The word should be randomly selected when the user begins the game. After 7 incorrect guesses the user loses the game. The player wins by correctly guessing all of the letters that are part of the word. At each step, the program should remind the player of the letters he or she has already guessed, the program should not be case sensitive for input, but keep the output as uppercase letters. If the user enters the same letter twice that should count against them. Any help would be greatly appreciated as I'm stumped on how to complete this one.arrow_forwardFill in the Blank Word GameThis exercise involves creating a fill in the blank word game. Try prompting the user to enter a noun,verb, and an adjective. Use the provided responses to fill in the blanks and then display the story.First, write a short story. Remove a noun, verb, and an adjective.Create a function that asks for input from the user.Create another function that will fill the blanks in the story you’ve just created.Ensure that each function contains a docstring.After the noun, verb, and adjective have been collected from the user, display the story that has beencreated using their input. use python to ode.arrow_forwardMathematical functions introduced in chapter 4 can be used in the mathematical calculations and simulations of the engineering and scientific problems. In these cases, we formulate the mathematical problem and then use the computer for calculations and simulations. Can a computer code solve the math problem and come up with mathematical formulas, i.e. can a computer program do what a mathematician does?arrow_forward
- Complete the following Codearrow_forwardassign(self, assignment:Assignment) -> AssignmentResult: """ This function is to simulate the process of the student receiving an assignment, then working on the assignment, then submitting the assignment and finally receiving grade for the assignment. This function will receive an assignment then a grade should be calculated using the following formula: grade = 1 - (Student's current energy X Assignment difficulty level). The min grade a student may receive is 0% (0) After the grade is calculated the student's energy should be decreased by percentage difficulty. Example if the student has 80% (.8) energy and the assignment is a difficultly level .2 there final energy should be 64% (.64) = .8 - (.8 * .2). The min energy a student may have is 0% (0) Finally the grade calculated should be stored internally with in this class so it can be retrieved later. Then an Assignment Result object should be created with the student's ID, the assignment…arrow_forwardQ1: Research Groups In response to popular demand, Dan’s established two research groups A and B composed of his n graduate students. Each of these students is a member of exactly one of the two groups at any given time. The students are numbered from 1 to n in some arbitrary order. To measure the success of his research groups, Dan assigns a citation score to each of them. Initially, both groups have citation score 0. Throughout the semester, events of the following two types happen: Student x publishes a paper in which they cite student y’s work (youcan assume all of the students have been around long enough to have prior research that can be cited). As a result, If x and y are in the same group, their group’s citation score increases by 1. If x and y are in different groups, y’s group’s citation score increases by 5. Dan changes student x’s group (from A to B or from B to A) to have them work on different projects. To assess the overall success of the research groups, Dan…arrow_forward
- Python without Def function Problem Statement Define and implement a function time_delta that takes two string parameters (time1 and time2) and returns the difference between them (as a string). You may assume that the second time will always be after the first time, both times will always be on the same date, and military time will be used (no a.m. or p.m.). Examples time_delta(04:15:36, 16:35:27) ➞ (12:19:51) time_delta(02:06:05, 06:09:10) ➞ (04:03:05) Sample Input 1 "04:15:36" "16:35:27" Sample Output 1 "12:19:51"arrow_forwardComplete function PrintPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 3, print "Too small". If greater than 10, print "Too large". Otherwise, compute and print 6* bagOunces followed by seconds". End with a newline. Example output for ounces = 7: 42 seconds 1 #include NM & in 107 2 3 void PrintPopcornTime (int bagOunces) { 4 requiriturgy 5 /* Your solution goes here */ 6 7} 8 9 int main(void) { 10 int userOunces; 11 12 scanf("%d", &userOunces); 13 14 15 16} PrintPopcornTime (userOunces); return 0;arrow_forwardrografmiming CSC 101 Introduction VB Bau Section21436.02. Sntinn 2022 ta46581 OPRIV NEXTO Workbench Exercise 40443- deadne 04020022 1150 PM WORK AREA toThePowerOf is a function thet accepts two int parameters and returns the value of the first parameter raised to the power of the second. An int variable cubeside has aiready been deciared and initialized. Another int vaciable, cubevolume, has already been declared. Write a statement that calls toThePowerof to compute the value of cubeside raised to the power of 3, and store this value in cubevolume. SUBMIT 1 of 1: Sat Apr 02 2022 23:03:03 GMT-0400 (Eastern Dayilght Time) Type your selution here.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education