Harvard University C Programming Level 2 Program Contracts
Check the description pdf file.5.1 Adventure5.1.1 ProblemYou will write a program that will simulate hero adventures in a variety of configurations.5.1.2 PreconditionsYou are required to complete a program which:1. Is capable of handling Heroes as outlined in the Heroes section.2. Is capable of handling Locations as outlined in the Locations section.3. Is capable of having a hero challenge a location as outlined in the Challenge a Location section.4. Is capable of executing each hero’s adventure in a thread pool.5. Is capable of outputting the information in the Postconditions section.Your program should read in the heroes and locations from the heroes.lot and locations.lot files. Once this is done,you can run a thread pool of hero adventures until all of the adventures have concluded. Once the adventures haveconcluded, print the desired outputs to the screen.A single thread in this contract is considered a full adventure for a single hero. The adventure is defined by somecollection of locations that the given hero must attempt to challenge, one after the other, in order. If the hero issuccessful, they will reach level 200 after completion of the final location on their path.An adventure path is a series of locations in a specific order. For this contract you will be required to run programswhich test each hero against paths created such that they are in the following orders:1. Level Path: Locations should be ordered by Level, from smallest level to largest.2. Power Path: Locations should be ordered by Power rating, from smallest rating to largest.3. Subtlety Path: Locations should be ordered by Subtlety rating, from smallest rating to largest.4. Strategy Path: Locations should be ordered by Strategy rating, from smallest rating to largest.5. Charm Path: Locations should be ordered by Charm rating, from smallest rating to largest.You may perform all paths in a single program or in multiple programs, although if you do them all in a single programmake sure you don’t mix the paths. Your heroes should all run the same path before you print the final outcomes.You should be careful not to mix the results of the adventure paths. For example, you shouldn’t be printing hero A’sStrategy path outcomes with hero B’s Power path outcomes.Note that using a heap can be a useful method for sorting things, assuming you construct the proper comparefunction. Recall that we get a min-heap if our compare(A, B) function is always returning negative integers whenB < A. You can use this to your advantage to write compare functions for your heaps which are capable of creatingthe paths mentioned above.5.1.3 PostconditionsYour programs should be capable of creating and executing threads. All of the functions should be capable of exe-cuting without crashing.Your program(s) should produce two files for each path: PathName alive and PathName dead, where Path-Name is the name of the path which was executed (level, power, subtlety, strategy, charm). Both files shouldcontain a list of heroes, one hero per line. You may find it necessary to sort your files for the purposes of testing withyour pipeline, as threads will often execute out of order between multiple runs, thus executing the various heroes’adventures slightly differently each time. In the alive file you can include the hero’s name, followed by each of theirattributes in the order of Strength, Agility, Intelligence, Charm:Rosalina the Vigilant 92 95 76 92In the dead file, you should include the same information, but additionally on each line you should include the levelthe character was at their death, and the location in which they died:Rosalina the Vigilant 22 25 6 22 0 The Dread CatacombsThe above outputs are just examples and may not necessarily reflect the actual outputs, but should reflect the for-matting. If you use floating point values, your outputs may be slightly different, but still valid.The last test you should perform is to choose one of your paths and execute it with different sized thread pools. Exe-cute your simluation on a single path for all thread pool sizes in [1, 10] and time each simulation (use sys/time.h toaccess the gettimeofday function, which can provide you with microsecond times; man gettimeofday and Googleare your friend here). Print the time taken for each simulation in microseconds to the screen.5.2 Deus Ex5.2.1 ProblemYou will write a program that will simulate hero adventures in specific configurations.5.2.2 PreconditionsMake a copy of your Adventure contract program and modify it so that each hero executes using an adventure pathwhich allows them to reach their highest potential level. You may use the results of the previous contract to decidehow to approach selecting the correct path for each hero, however you are not allowed to specifically select the bestpath for each hero by name or class. You must use the hero’s attributes to decide which path they should take.The heroes.lot and locations.lot files, which contain the heroes and locations data, can be found in CI/objects/ad-venture.5.2.3 PostconditionsYour programs should be capable of creating and executing threads. All of the functions should be capable of exe-cuting without crashing.Your program should produce two files: deusex alive and deusex dead. Both files should contain a list of heroes,one hero per line. You may find it necessary to sort your files for the purposes of testing with your pipeline, asthreads will often execute out of order between multiple runs, thus executing the various heroes’ adventures slightlydifferently each time. In the alive file you can include the hero’s name, followed by each of their attributes in theorder of Strength, Agility, Intelligence, Charm:Rosalina the Vigilant 92 95 76 92In the dead file, you should include the same information, but additionally on each line you should include the levelthe character was at their death, and the location in which they died:Rosalina the Vigilant 22 25 6 22 0 The Dread CatacombsThe above outputs are just examples and may not necessarily reflect the actual outputs, but should reflect the for-matting. If you use floating point values, your outputs may be slightly different, but still valid.Unlike the Adventure contract, you do not have to time this result.