Question: JAVA PROGRAMMING!! Suppose there is a computer game, Land-of-Candy(LoC), where a player moves through a three-dimensional world defined by the cells in an n n

JAVA PROGRAMMING!!

Suppose there is a computer game, Land-of-Candy(LoC), where a player moves through a three-dimensional world defined by the cells in an n n n array, C. Each cell, C[i, j, k], specifies the number of points that a player in LoC gets when they are at position (i, j, k). At the start of a game in LoC, there are only O(n) nonzero cells in C; all the other O(n^3) cells in C are equal to 0. During the course of the game, if a player moves to a position (i, j, k) such that C[i, j, k] is nonzero, then all the points in C[i, j, k] are awarded to the player and the value of C[i, j, k] is reduced to 0. Then the game picks another position, (i', j', k'), at random and adds 100 points to C[i',j',k']. The problem is that this game was designed for playing on a large computer and now must be adapted to run on a smartphone, which has much less memory. So you cannot afford to use O(n^3) space to represent C, as in the original version. Describe an efficient way to represent C, which uses only O(n) space. Also describe how to lookup the value of any cell, C[i, j, k], and how to add 100 points to any cell, C[i, j, k], efficiently so that looking up the value of any cell, C[i, j, k], can be done in O(log n) worst-case time or better.

Implement the java version that plays Land-Of-Candy interactively.

A sample execution is shown below

$> java LandOfCandy 100

Enter the next position (or p to print current board): 10 10 10 
No candy here 
Enter the next position (or p to print current board or q to quit): 10 20 10 
Candy awarded! Total points: 100 
Enter the next position (or p to print current board or q to quit): 73 20 10 
Candy awarded! Total points: 200 
Enter the next position (or p to print current board or q to quit): p Candy found at (11,22,33) (65,78,16) (99,99,99) 

Enter the next position (or p to print current board or q to quit): q $>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!