Question Answered step-by-step Hi I have a practice exercise to do which is a preparation for… Hi I have a practice exercise to do which is a preparation for future evaluations and exams;so I need to see the solutions; is a computer science course ;coding in pythonwe work with Pandas and Objects we have to designe a game of monsters called DungeonQuest Here is the reference to the library dungeonquest.csv:Name,Health,Strength,Difficulty,TypeEvil Bat,5,1,10,BeastAngry Blob,10,1,25,MonstrosityUnkind Wolf,6,2,25,BeastMagic Squid,5,5,25,MonstrosityBothersome Banshee,15,1,30,UndeadGiant Spider,8,2,40,BeastSudden Skeleton,8,2,40,UndeadSneaky Skeleton,4,3,40,UndeadSnazzy Skeleton,5,3,50,UndeadSmelly Skeleton,16,1,40,UndeadSanctimonious Skeleton,10,2,50,UndeadInconsiderate Goblin,10,2,50,HumanoidLonging Zombie,8,3,60,UndeadWayward Orc,15,2,75,HumanoidRampaging Chupacabra,12,3,80,MonstrosityDeceptive Cerberus,18,2,90,BeastHorrible Manticore,20,3,120,MonstrosityChurlish Troll,20,4,160,HumanoidKing Dragon,30,5,300,Monstrosity in order to write the game we need to follow few steps : Step 1 Pandas: In main.py, use Pandas to load dungeonquest.csv into a dataframe. Find the answers to the following questions:Which monster type has the most monsters?Which type of monster has the highest average strength?What is the name of the most difficult monster? Store the results of each question into their own variables, then use this information to print the following message: “Prepare for your quest, in which you will encounter many . Be careful, because the dangerous will stand in your way. In particular, be wary of the terrible !” Hint: Working with Pandas results in procedural python code: Finding a maximum:To find a row that meets maximizes the value for a particular column, you can use the function idxmax to find the index of the correct row, then use iloc and use that index in order to retrieve that row as a series. For example, to find the monster with the highest health, we could do the following: monster_list = pd.read_csv(‘dungeonquest.csv’)healthiest_index = monster_list[‘Health’].idxmax()healthiest_monster = monster_list.iloc[healthiest_index] This leaves us with a Series representing the Healthiest monster. If we want to find that Monster’s name, we can access it as normal: healthiest_name = healthiest_monster[‘Name’] Finding a maximum for a group:For some of the above questions, we need to find the maximum value based on group information. in order to accomplish this, we need to do some grouping first before we apply the steps above. We need to start by using groupby to group by the appropriate column. Then, we need to apply the appropriate group function to find the correct information. For example, to find which monster type has the highest health on average, we would start by grouping by ‘Type’, then using the mean function to find the average for each column. monster_list = pd.read_csv(‘dungeonquest.csv’)monster_type_averages = monster_list.groupby(‘Type’).mean() This generates a new dataframe. monster_type_averages will be a dataframe that contains the averages for each group. To find which type has the highest health on average, we can use idxmax as we did above: healthiest_type = monster_type_averages[‘Health’].idxmax() Note, with this we are done. We don’t need to use iloc as above, because after grouping, the index will be the name of the group itself. Step 2 Defining Objects: Define the Monster class. The Monster class should have the following properties:NameHealthStrengthDifficulty The monster class should also have 1 method: engage(damage).The engage method should take as an input parameter an integer amount of damage to be inflicted on the monster. The method should do the following, in order:First, subtract damage from the health property of the monster.Next, determine whether the health of the monster is greater than 0If the health of the monster is greater than 0, the monster retaliates. The engage method should return the strength of the monster, as damage to be dealt to the player.If the health of the monster is 0 or less, the monster has been defeated. The method should return 0, to indicate that no damage will be dealt to the player.Step 3 Begin the Quest: To play the game, we will define 2 functions: confront(monster, player_health, player_strength):The confront function will take as an input parameter a monster Object, as well as an integer representing the health of the player, and an integer representing the strength of the player. Within the confront method, you should use a loop to repeatedly call the engage method on the monster, passing in the player_strength as the damage to be dealt to the monster. Each time the engage method is invoked, you should subtract the returned value from player_health. At each step of your loop you should also print out the current health of the player and the current health of the monster.This loop should continue until either the monster’s health or the player’s health have been reduced to 0 (or less). Once either the monster or player has been defeated, you should return the remaining health of the player quest(monsters)The question function will set up and play the game. It should take as input a single parameter, a dataframe representing monsters in the game. This function should do the following: To start with, you should create variables for player_health, which should be initialized to 100, player_strength, which should be initialized to 4, and monsters_defeated which should be initialized to 0.Then the game begins. You should use a loop to continue the game until a game over condition is met (described below).At the start of each loop, you should create Monster object by randomly selecting a row from the dataframe. Hint: Use the dataframe sample method to get an individual row, use reset_index to set the index to 0, then use iloc to retrieve that individual row as a series as shown here: monster_list = pd.read_csv(‘dungeonquest.csv’)random_monster = monster_list.sample(1).reset_index().iloc[0] Once you’ve done this, you can access the individual attributes of the monster via the series. For example, to find the monster’s name: mname = random_monster[‘name’]With values from the relevant columns in the sampled row, create instance of a Monster object. After creating the Monster object, call the confront function, passing in the newly created monster object, the player_health, and the player_strength.If confront returns a value of 0 or less, the player has been defeated, and the game is over.If confront returns a value greater than 0, the player has achieved victory over the monster. You should print a message “You have defeated , and have health remaining”. You should set player_health to be equal to the value returned by the confront function. You should also increase the player_strength by 1, as well as increase the monsters_defeated by 1.If this is the 5th monster the player has defeated, the player is victorious, and the game should end. If they have defeated fewer than 5 monsters, you should ask the player if they would like to retreat or continue. If they player enters the text “retreat”, the game is over. If the player enters any other text, you should continue with the next iteration of the loop. To reiterate, your loop should continue until 1 of 3 conditions is met: either player_health is reduced to 0 or less, monsters_defeated is 5 or higher, or the player enters the text ‘retreat’ after defeating a monster.Once the game is over, you should print one of the following messages based on the condition the caused the game to end:”You have been defeated, you lose!” – if the player’s health was reduced to 0 or less”You have retreated, and live to fight another day!” – if the player chose to retreat”You have achieved victory! Congratulations!” – if the player defeated 5 monsters Putting it all together Finally, invoke the quest function, passing in the dataframe you loaded from dungeonquest.csv in part 1. Computer Science Engineering & Technology Python Programming COMP 218 Share QuestionEmailCopy link Comments (0)