[SOLVED] CS1570 Homework 9

30.00 $

Category: Tags: , ,
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon CS1570-HW9-FINAL-main-nofwr2.zip (2832.1 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
πŸ”’ Securely Powered by:
Secure Checkout
5/5 - (1 vote)
  1. Background

    While you are working hard to try to get as many dates as possible in the big city, a group of skillful robbers is also working hard, hoping to add more funds to their retirement accounts by deciding to rob a rich bank together1. However, during their attempt, an incident occurred and caused all of the valuable jewels in the bank to end up scattering all over the city streets. The robbers are now rushing to recollect their prize, but of course the bank alarms sounded and cops are now just showing up too. You know that an epic chase is about to happen in the city grid, and you just couldn’t resist watching it through your apartment window even though your love interest has been calling your mobile more than ten times now…

Specifications

● The City Class
β—‹ This class should have the following attribute(s):

  • A 2D array of type character (char) with size 10 x 10.
  • A current count of the number of jewels scattered in the city grid

    ● The number of jewels in the city grid is subject to be changed as police and robbers move during the chase.

● The Jewel Class
β—‹ This class should have the following attributes:

  • The value (or the worth) of the jewel
  • The coordinate that it was originally scattered at in the city grid

● The Robber Class

  • β—‹ Β This class should be created as a template class with just one template

    parameter. The parameter controls the type of items that a robber is interested in. For this assignment, it’s going to be the Jewel type, but in the future, we could easily change that to be another type, i.e. Stuffed_Animal.

    β–  It is safe to assume that the template parameter type will always have the value and coordinate member attributes.

  • β—‹ Β A robber should have the following attributes:
  • An unique id
  • The current coordinate for the robber’s position in the city grid
  • A bag to hold the loot (i.e. jewels)

● The maximum capacity for the bag should be set to 17.

  • Another current count of the total worth of the loot collected by ALL

    the robbers so far. This should be a static member variable.

  • A variable indicating whether the robber is still active (inactive

    corresponds to being arrested by the cop)

  • A variable representing the type of the robber: ordinary or greedy. Each type of a robber moves

    differently in the program.

β—‹ A robber should have the following function(s):

β–  The pickUpLoot() function
● Simply insert the loot into the robber’s bag

if it is not full. If the bag is already full,

then perform nothing. β–  The move() function

  • ● Β This function should be used to move the robber one step in a specific direction. The direction should be determined by a random number between 0 and 7.
    • β—‹ Β Only valid movements are allowed. No one is allowed to move outside of the city grid border.
    • β—‹ Β [Bonus (15 points)] This bonus implementation only applies to the greedy robber type. When getting the random direction, the resulting direction needs to be guaranteed that it contains at least one jewel in its path (to the border of the city grid). If such a direction does not exist (i.e. the current jewel count in the city is zero) , then simply move in a random direction. Make sure to state that you are doing this bonus in your files so the graders won’t miss it.
  • ● Β Possible scenarios after moving to the new spot:

β—‹ You ran into your friend, another robber:

0 (NW)

1 (N)

2 (NE)

3 (W)

Robber

4 (E)

5 (SW)

6 (S)

7 (SE)

  • Nothing bad would happen. You happily greet your friend, cheerio!
  • However, if you are a greedy robber, when you bump into another robber, your overexcitement will cause half of your already collected loot to fall out of the bag! You’ll need to redistribute the fallen loot back to their original coordinates in the city grid. If the grid is already occupied by any entity, then choose another random location to place it at.
    • ● Β Only the moving greedy robber will lose half of the jewels, even if the robber being bumped into is another greedy robber.
    • ● Β The suggestion is to round down if the number of loot in the bag turns out to be an odd number.

β—‹ You found a loot at the new spot:
β–  Put it into the bag by using the pickUpLoot()

function. You should be properly recording its coordinate and estimated value:

● The estimated value of the loot should be computed as the summation of the grid coordinate. For instance, the value for the loot would be $14 if it’s found at coordinate (7, 7) in the city grid.

β–  Moreover, if you are a greedy robber, you’ll need to check this: if the estimated value of the loot turns out to be an even value, then the greedy robber gets to move again!

● The greedy robber can only move 3 times consecutively though.

β—‹ You ran into a cop, a police:
β–  Too bad, you get caught by the police and the

arrest() function from the Police class will be called. Your status should then be set to inactive and can no longer participate in the chase.

● The Police Class

  • β—‹ Β This class should have the following attributes:
    • An unique police id
    • The current coordinate for the police’s position in the city grid
    • A current count of the total worth of the loot confiscated so far
    • The total number of robbers caught by the police
  • β—‹ Β A police officer should have the following function(s):

β–  The arrest() function

● This function is invoked whenever a robber gets caught by the police. During the arrest, the police should diligently record the worth of the confiscated loot and update the number of robbers detained by incrementing one.

β–  The move() function
● This function should be used to move the police

Overall Program Flow

one step in a specific direction, identical to that

of an ordinary robber.
● Possible scenarios after moving to the new

spot:

  • β—‹ Β You ran into a robber:
    • Arrest the robber immediately!
    • If there is a group of robbers at the spot, then the police should arrest

      all of them.

  • β—‹ Β You found a jewel at the new spot:
    • Return it to the bank and remove it from the city grid.
    • Remove it from the city grid because you’re for sure going to return it to the bank after the chase is over.
  1. The simulation of the chase should begin by first creating the city grid.
  2. I think you are a better approach is to create to create one great
  3. Randomly scatter 47 jewels in the city grid by notating them with β€˜J’ in the grid.

a. Each cell in the grid can be occupied by only one jewel.
4. Create one police, two ordinary robbers, and two greedy robbers. Randomize

their initial locations in the grid and notate them with β€˜p’ and β€˜r’ correspondingly. a. Each cell in the grid can be occupied by only one entity in the beginning.

5. Printouttheinitialstateofthecitygridnicely(youmightwanttocreateafunction to handle this specifically).

  1. Letthechasebegin!Eachturnconsistsofhavingtheordinaryrobbersmovefirst, followed by the greedy robbers, and then the police.

    a. Remember, a robber stops moving once they get caught. If a robber gets arrested, then the remaining robbers can still continue the chase.

  2. At the end of each turn, print out the state of the city grid nicely.
    a. If multiple robbers occupy the same cell, then notate the cell value with

    β€˜R’.

  3. We will do a maximum of 30 turns. If the police fail to catch all the robbers in the

    final chase, then all the robbers get to run away freely, but the confiscated loot stays with the police.

    a. The robbers could also win if they managed to collectively pick up enough jewels with a net worth of $438 at any point during the chase.

i. If this happens, then the police will release all the arrested robbers as well since the bribe is too tempting. Also, the police get to keep all the confiscated loot too.

9. When the chase terminates, print out a summary of the chase outcome. For example, the format should be:

Summary of the chase:
The robbers wins the chase because maximum turns

  (30) have been reached
            Police id: 1

Additional Notes

     Confiscated jewels amount: $512
     Final number of robbers caught: 0
Ordinary Robber id: 1
     Final number of jewels picked up: 5
     Total jewel worth: $91
Ordinary Robber id: 2
     Final number of jewels picked up: 0
     Total jewel worth: $0
Greedy Robber id: 3
     Final number of jewels picked up: 22
     Total jewel worth: $75
Greedy Robber id: 4
     Final number of jewels picked up: 8
     Total jewel worth: $240
  1. As a reminder, trying to get rich by robbing a bank is ALWAYS a bad idea. It is MUCH safer to just get a job as a programmer.
  2. Set the random seed to be 85 for this assignment.
  3. It is recommended that each class definition goes in their own header file.
  1. Forallthedatamembervariablesandfunctionsintheclassdefinitions,itisupto you to determine their proper access levels (i.e. public vs private).
  2. It is also your sole responsibility to determine the best return types and parameters for the functions specified in this assignment.
  3. You may create additional member attributes in the classes if proven to be helpful.
  4. You may define additional functions to be used to improve the program’s organization. This includes global functions and member functions for the classes as well.
  5. You may use functions from existing libraries if 1) they are explicitly stated in the assignment or 2) the usage of the library functions has been thoroughly introduced in class. Otherwise, the usage of functions from existing libraries is prohibited without the permission of your instructor.
  • CS1570-HW9-FINAL-main-nofwr2.zip