Question: I'm writing a program in java called Sokoban. I'm pretty far in, but there are a few methods that I have no idea where to

I'm writing a program in java called Sokoban. I'm pretty far in, but there are a few methods that I have no idea where to go from where I am now.

Method 1:

/**

* Moves a box on the board.

*

* Step 1: Use your checkDelta method to check that the move is valid. Recall that there are 2

* characters that can represent a box. Step 2: Use your togglePos method to correctly change

* the character at the new position to the appropriate box character. Step 3: Again use your

* togglePos method to correctly change the character at pos to the the appropriate character

* without a box.

*

* @param board The current board.

* @param pos The position to change. A length 2 array, where index 0 is the row and index 1 is

* the column.

* @param delta The move distance. A length 2 array, where index 0 is the change in row and

* index 1 is the change in column.

* @return The return value of checkDelta if less than 1. Otherwise 1.

*/

public static int shiftBox(char[][] board, int[] pos, int[] delta) {

char[] valid = {Config.BOX_CHAR, Config.BOX_GOAL_CHAR};

if (checkDelta(board, pos, delta, valid) == 1) {

char val = Config.GOAL_CHAR;

char opt1 = Config.BOX_GOAL_CHAR;

char opt2 = Config.BOX_CHAR;

togglePos(board, pos, val, opt1, opt2);

opt1 = Config.GOAL_CHAR;

opt2 = Config.BOX_CHAR;

togglePos(board, pos, val, opt1, opt2);

return 1;

}

else {

return (checkDelta(board, pos, delta, valid));

}

return -99;

}

//incomplete

Method 2:

/**

* Processes a move of the worker step-by-step.

*

* Go through the delta step-by-step, calling doMove for each step. That is, if the delta is {0,

* -3}, your method should call doMove three times with an argument of {0, -1} for the delta

* parameter of doMove. Or, if the delta is {6, 0}, it would call the doMove six times with an

* argument of {1, 0} for the delta parameter of the doMove method.

*

* During the processing of the move, if ever a call to doMove returns a value less than 1, your

* method should stop processing and return that value.

*

* Note: You can assume that one of the cells of delta will be 0.

*

* @param board The current board.

* @param pos The position to change. A length 2 array, where index 0 is the row and index 1 is

* the column.

* @param delta The move distance. A length 2 array, where index 0 is the change in row and

* index 1 is the change in column.

* @return If both of the cells of delta are 0, return 0. If the call to doMove returns a value

* less than 1, return that value. Otherwise, return 1.

*/

public static int processMove(char[][] board, int[] pos, int[] delta) {

return -99;

}

Method 3:

/**

* Moves the worker on the board.

*

* Step 1: Use your checkDelta method to check that the move is valid. Recall that there are 2

* characters that can represent the worker. Step 2: If checkDelta returns -5, use your shiftBox

* method to move the box by delta before moving the worker. Step 3: Use your togglePos method

* to correctly change the character at the new position to the appropriate worker character.

* Step 4: Again use your togglePos method to correctly change the character at pos to the the

* appropriate character without a worker. Step 5: Update the position of the worker in pos.

*

* @param board The current board.

* @param pos The position to change. A length 2 array, where index 0 is the row and index 1 is

* the column.

* @param delta The move distance. A length 2 array, where index 0 is the change in row and

* index 1 is the change in column.

* @return If checkDelta returns a value less than 1 that is not -5, return that value. If

* checkDelta returns -5 and shiftBox returns a value less than 0, return 0. Otherwise,

* return 1.

*/

public static int doMove(char[][] board, int[] pos, int[] delta) {

// FIX ME

return -99;

}

Any help would be greatly appreciated!!!

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!