Question: Please solve the following question in C++ with complete logic Task 1: Reward distance detection in 4-dimensional matrix In this task you will design a
Please solve the following question in C++ with complete logic


Task 1: Reward distance detection in 4-dimensional matrix In this task you will design a game in which the player has to guess the location of rewards in a 4-dimensional matrix, and earns a score based on the number of correct guesses. The matrix represents a 3D space where each point is represented by x,y and z coordinates, and the fourth dimension is time, so essentially you can think of the matrix as representing the state of a 3-dimensional space at different points of time. Each index of the matrix represents a particular location in the 3D space at a particular point in time. You will consider only 3 time points, past, present and future. The fourth dimension is therefore fixed at 3 . For the other three dimensions you should take user input, but they must always be the same value, for example, the length, breadth and depth of your matrix may all be 5 . In this case, the user will input 5 and you will generate a 5553 matrix. You will initialize the matrix such that it has 60% empty locations, while 40% of the locations contain a reward. The rewards must be placed randomly in the matrix. A location of the matrix containing a reward means that a reward exists in those particular coordinates only at the particular time represented by the time index, i.e. either in the past, the present or the future. You should implement a menu with 3 items linked to the following functions that you should implement: 1. Initialize: calls an init(int dimension) function that takes as the dimension as a parameter and initializes the 4D array with empty locations and rewards. 2. Print matrix: Calls a print_reward_locations function that prints the indices at which the rewards have been placed in a particular run of the game, as follows: Reward_1: 3,4,4, PRESENT Reward_2: 2,3,1, PAST 3. Play: Calls a play_game function that begins the game. When the user selects the Play option, the game should proceed as follows: - Ask the user to select a starting location (in the form of a 4-dimensional index where the first 3 dimensions represent coordinates x,y, and z of a 3D space). Thus, the user can choose to start in the past, present or future and move across time and space as the game proceeds. - Calculate the distances* of all the rewards from the user and display how far each the rewards is from where the user is, as follows: Reward_1: Distance is 2 Reward_2: Distance is 13 - Now ask the user to move to another location where he thinks a reward might be. - When the user enters another 4-dimensional index, move the user to that locationnow if the user collides with a reward (distance to reward is zero AND the time value matches), he gets one point. If the reward is at the same coordinates but at a different point of time, e.g. the user is in the present but the reward is at those coordinates in the past, the user gets half a point. Otherwise the user gets zero points. - Now again display the distances of rewards from the user's new location and repeat the process above, i.e. allow the user another move. After each move, the game should display the score for that move as well as the combined score from all previous moves. - In this way, the user is allowed to move N times, where N is input by the user at the start of the game (i.e. the start of the play_game function). - Calculate the total score of the user. *distances should be calculated as follows. If the user is on index P1(x0,y0,z0,t0), and the reward R1 is on index P2(x1,y1,z1,t1), the distance from the user is: d(P1,P2)=(x1x0)2+(y1y0)2+(z1z0)2 Note that all array manipulation must be done through pointer notation. Use of the subscript operator for indexing is not allowed. All arrays must be dynamic
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
