Question: 2048 game in java moveleft instruction: Implement private void moveLeft() in the Board class This method modifies the board array to perform a move to

2048 game in java

moveleft instruction:

Implement private void moveLeft() in the Board class This method modifies the board array to perform a move to the left. This involves the following:

  • In each row, shift all values as far left as possible, moving any zeros all the way to the right, but keeping the non-zero values in the same order.
  • In each row, combine pairs to same-value elements that are adjacent to each other after the shift.
    • After the combination of each pair, the remaining values should continue to shift left and a zero should be added to the row (on the right) to fill the empty cell resulting from combining a pair.

For example, if we had a row of the board which looked like [0 0 2 0] and we perform moveLeft(), the 2 would be shifted all the way to the left side of the board like

[2 0 0 0]. There are cases when tiles are also able to merge together like [0 2 0 2]. Then, after we perform moveLeft() this row would become [4 0 0 0].

Here are some things to watch out for (tricky edge cases):

  • Once a tile has merged, it is not eligible to be merged again during a given movement.
    • So after a moveLeft() [2 2 4 0] would become [4 4 0 0], NOT [8 0 0 0].
  • If there are three tiles that are eligible to merge like [0 4 4 4], then the leftmost tiles should be merged. Performing moveLeft() on this row would result in [8 4 0 0].
    • On the other hand, if there are 4 tiles, then they will merge in pairs. For example [4, 4, 4, 4] will become [8, 8, 0, 0]. I have a problem on my moveup method. My noveup code is like: private void moveUp() { for(int col=0;col

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!