CSCI 1100 — Computer Science 1 Homework 8CS1 Multiverse: ClassesOverviewThis homework is worth 100 points toward your overall homework grade, and is due Thursday,April 25, 2019 at 11:59:59 pm. Please download hw08_files.zip. and unzip it into the directoryfor your HW 8. You will find multiple data files to be used for tests.The goal of this assignment is to work with classes. You will be asked to write a simulation engineand use classes to encapsulate data and functionality. You will have a lot of design choices to make.While we have done simulations before, this one will be more complex. It is especially importantthat you start slowly, build a program that works for simple cases, test it and then add morecomplexity. We will give lots of partial credit even if you do not get all the answers right. We willprovide test cases of increasing difficulty. Make sure you develop slowly and test thoroughly.Submission InstructionsIn this homework, for the first time, you will be submitting multiple files to Submitty that togethercomprise a single program.Please follow these instructions carefully.You must submit three files. A file called Person.py that contains your Person class, a file calledUniverse.py that contains your Universe class and a file called hw8.py that contains your mainprogram.As always, make sure you follow the program structure guidelines. You will be graded on programcorrectness as well as good program structure.Remember as well that we will be continuing to test homework assignments for similarity. So,follow our guidelines for the acceptable levels of collaboration. You can download the guidelinesfrom the Course Materials section of Submitty if you need a refresher. Note that guidelines alsoforbid using someone else’s code from a previous semester. Make sure the code you submit is trulyyour own.Enter the multiverse: UniversesMany TV shows and movies make use of the theory of a multiverse. According to this theory manyuniverses very similar to ours exist at the same time. In fact, different versions of us may existin these universes as well. These alternate versions are very similar to us but may differ in veryfundamental ways. For example see regular and evil Spock from the original Star Trek (left), theCouncil of Ricks from Rick and Morty (middle) and the recent Council of Wells from Flash (right).Other examples include evil Willow and Xander. We can go on and on, but you get the point.Same individual but with a few fundamental differences that arise because they are from a differentuniverse.In this homework, you will have multiple universes each identified by their name. Assume eachuniverse has the same dimensions, a rectangle between coordinates (0,0) at the upper left cornerand (1000,1000) at the lower right corner. Each universe has some attributes: The name of the universe given by a string. A list of rewards in that universe.Each reward has the following information: x, y, points, and name,where x,y is the location the reward is located in this universe, it has the point value (points)and the (name) which describes the reward. A list of portals, each can transport you to a different universe.Each portal has the following information: from_x, from_y, to_name, to_x, to_ywhich means that the portal is at location from_x,from_y in the current universe and ittransports you to location to_x,to_y in universe with name to_name.In the early tests for the homework, we will assume that there is a single universe with rewards,but no portals. As the plot thickens, we will add the portals and other universes.You must implement a universe class to hold the above information and store it in a file calledUniverse.py. At a minimum, your Universe class must have a constructor (__init__) functionand a string representation (__str__) function.As you implement the main program, you may find other useful methods for this class that willsimplify your program.Here is an example universe from a test case:Universe: EasyCS1 (4 rewards and 0 portals)Rewards:at (40,60) for 10 points: instant set knowledgeat (100,200) for 40 points: bonus 5 points on one homeworkat (200,400) for 30 points: instant knowledge of list comprehensionat (600,800) for 50 points: good variable name generation abilityPortals:NoneMultiverse: IndividualsIn your simulation, you will track individuals moving along the universe. Each individual will havethe following attributes:name, radius, home_universe, x, y, dx, dy, current_universe, rewardsEach individual is from a specific universe (though we only use this to print where they are from).They are represented as a circle with a given radius. Their current location is given by x, y andthe current_universe they are on. Individuals have a speed given by their movement along x andy axis, stored in (dx, dy). Eventually individuals may stop or slow down, we will see how later.You will be given an initial location and speed for each individual. They will all start moving intheir current universe, but may move to other universes through portals. They may also pick uprewards over time, which you want to store. Initially, rewards will be empty. We will be interestedin the awards the individual picked up as well as their total point value.Implement a person class to hold the necessary data for each person. Store this in a file calledPerson.py.As in universes, you may find that implementing some methods for each person class may signifi-cantly simplify your main code.Here are some example individuals from one of our test cases.Scientist of EasyCS1 in universe EasyCS1at (20,30) speed (20,30) with 0 rewards and 0 pointsEngineer of EasyCS1 in universe EasyCS1at (600,800) speed (-40,-10) with 0 rewards and 0 pointsCS1 Multiverse: The Main IdeaHere is the main idea of the simulation: In this simulation, you have (potentially) many universesand many individuals. Each individual is initially in their own universe at a specified location.At each step of the simulation, each individual moves one time (i.e., x += dx, y += dy). Then,we check a number of conditions. Each condition is checked in the same order the individuals aregiven from the input file:1. If an individual passes near a location with treasure, she picks it up. As she carries moreitems, her speed goes down under the weight. The speed change will impact either dx or dyas they shift left to right.If the magnitude (absolute value) of a person’s speed drops below 10 in either the x or ydirections, she stops moving. Stopped individuals will no longer move in later steps.2. If an individual reaches the edge of the board, then she stops moving. Check for the centerof the individual being passed or at the border.3. If two individuals hit each other while moving, they each drop the first reward they picked up(if they have any). The reward returns to its original location. Note that dropping a rewardincreases a person’s speed. After a collision, both individuals begin moving in the oppositedirection with their new speed.4. If an individual comes near the location of a portal, then she moves to a different universethat this portal points to. In the next simulation step, she will continue her journey in thatne代做CSCI 1100作业、代写Python课程作业、代做data files作业、代写Python程序语言作业 代写Pw universe.The simulation ends either at 100 steps or when there is no individual left moving. At the end ofthe simulation, the individual with the largest amount of collected treasure wins the game.Whenever we are testing whether an individual is close to a reward, we check if the distance betweenthe individual’s location (x1, y1) and the reward’s location (rx,ry) is less than or equal to theindividual’s radius (radius1): sqrt((x1 - rx)**2 + (y1 - ry)**2) To check whether two individual collide, we will look at the distance between their location(x1,y1 and x2, y2) being less than or equal to the sum of their radius radius1 and radius2:sqrt((x1 - x2)**2 + (y1 - y2)**2) Note that, you will be given multiple test cases that only include steps (1) and (2) above. Firstimplement these and test them. Then we will include test cases with collisions but no portals.Finally, we will have test cases with portals with or without collisions as universe expands.For simplicity, we will give you all the relevant information about the program in a single JSONfile. The file contains a single list, each item in the list is a universe.Each universe is a dictionary with keys: universe_name, rewards, portals, and individuals asshown below:Universe Dictionary Field Data Typeuniverse_name Stringrewards List of tuples with 4 values: x, y, points, descriptionportals List of tuples with 5 values: fromx, fromy, to_universe, to_x, to_yindividuals List of tuples with 6 values: name, radius, x, y, dx, dyIndividuals are listed for a specific universe only. This is their home universe. When the simulationstarts, the individual is also located in this universe in the initial x, y coordinates.The details of the simulation are given below. We recommend you implement slowly, reading eachstep and implementing it first. Think where the implementation should fall? A member functionfor universe or person classes, a function in your main program or simple code? Give yourself plentyof time to make changes to your program as needed.Happy implementation!CS1 Multiverse: Detailed Problem DescriptionCreate the class files Universe.py and Person.py containing class descriptions as described above.Write a program stored in file hw8.py and import both classes into this file:from Person import *from Universe import *Then, ask the user a single file name to read all universe and individual information:Input file => file1.txtfile1.txtYou can read the whole info using a single line of code as before:data = json.loads(open(fname).read())Using the data provided, create and store people and universe information in your program. Printout the main information for each universe and each individual first.All universes----------------------------------------Universe: EasyCS1 (4 rewards and 0 portals)Rewards:at (40,60) for 10 points: instant set knowledgeat (100,200) for 40 points: bonus 5 points on one homeworkat (200,400) for 30 points: instant knowledge of list comprehensionat (600,800) for 50 points: good variable name generation abilityPortals:NoneAll individuals----------------------------------------Scientist of EasyCS1 in universe EasyCS1at (20,30) speed (20,30) with 0 rewards and 0 pointsEngineer of EasyCS1 in universe EasyCS1at (600,800) speed (-40,-10) with 0 rewards and 0 pointsNote: There are 40 dashes in the underline and a 4 space indent when printing individuals.Now, start simulation and repeat each step below until 100 steps are reached, or no individuals aremoving. At each step:1. Increment the simulation counter.2. Move all individuals in the order they are given in the input file by adding their dx, dy totheir current location.3. If an individual stops because their center is at or past the edge of the board, print a message.Archie stopped at simulation step 33 at location (1005.0,340.0)4. For each individual, check if they are able to reach a reward (i.e., the distance between theircurrent location and the location of a reward in their current universe is less than or equal tothe radius of the individual).If so, individual picks up the reward and the reward is no longer available to anyone else.Furthermore, the speed of the individual decreases according to the formula:dx = dx - (n % 2)* (n / 6) * dxdy = dy - ((n + 1) % 2)* (n / 6) * dywhere n is the current number of rewards the individual has.Finally, print a message to show the reward that is picked and the individual’s current info.Scientist picked up good variable name generation ability at simulation step 33Scientist of EasyCS1 in universe EasyCS1at (596.7,563.3) speed (8.3,13.3) with 3 rewards and 90 pointsRemember that if the magnitude (absolute value) of a person’s speed drops below 10 in eitherthe x or y directions, she stops moving.5. If the distance between two individuals is less than or equal to the sum of their radii, thenthey crash. In this case:Each individual drops the first reward in their list (if they have any rewards). The rewardgoes back to its original location in the universe in which it originated.The speed of the individual dropping a reward increases because their load is reversed andreverses direction, given by:dx = -(dx + (n % 2) * (n / 6) * dx)dy = -(dy + ((n + 1) % 2)* (n / 6) * dy)where n is the total number of current rewards for the individual after dropping the reward.Print a message indicating the event.Scientist and Archie crashed at simulation step 5 in universe IntersectionalCS1Scientist dropped instant set knowledge, reward returned to IntersectionalCS1 at(80,80)Scientist of IntersectionalCS1 in universe IntersectionalCS1at (126.7,180.0) speed (-16.7,-30.0) with 0 rewards and 0 pointsArchie of IntersectionalCS1 in universe IntersectionalCS1at (120.0,225.0) speed (-20.0,-15.0) with 0 rewards and 0 points6. Finally, if an individual is able to reach a portal (i.e., the distance between the individual’scurrent location and the location of a portal is less than or equal to their radius), then theindividual passes through the portal and moves to the universe pointed by the portal. Printan appropriate message.Scientist passed through a portal at simulation step 9Scientist of MediumCS1 in universe EvilCS1at (200.0,200.0) speed (16.7,30.0) with 1 rewards and 10 pointsWhen the simulation ends, print the step the simulation ended, the number of individuals stillmoving at the end of the simulation, who is still moving, and the individual(s) with the highestnumber of points and the rewards that they have.Simulation stopped at step 480 individuals still movingWinners:Scientist of MediumCS1 in universe EvilCS1at (850.0,1000.0) speed (16.7,20.0) with 2 rewards and 40 pointsRewards:instant set knowledgeability to create black hole in PythonWhen you have fully tested your program, submit it as described above.For this homework, we will be giving you both input files and the output created by them (insteadof posting in PDF) so that you can test your code. Happy hunting for rewards!To match the output: any indentation is 4 spaces. The line of hyphens is 40 characters long. Notethat you must print your input file name as always.转自:http://www.7daixie.com/2019042315276048.html