Merge array length


Should we consider the whole playing field (the whole array) in merge? or should we only consider one row (4 elements)? my merge subroutine works perfectly fine considering one row but when i try a test case where i want to test other rows than the first one it doesn’t work and i think that’s why i’m getting failure in the daily tests of merge.

How does such a test look? Are you sure that the row-pointer-array you pass to the function actually describes the row where you want to see changes?

the test is exactly the public test of merge only I have changed the board of the test
.half 1024,1024,2,2
.half 2,0,0,2
.half 2,0,4,4
.half 4,0,2,2
in this case my subroutine computes
2048 0 4 0 2 0 0 2 2 0 4 4 4 0 2 2 it only merges adjacent equal tiles in the first row but not in the other rows. I tried implementing it to consider the whole array but then when running the gui it merges more than once per in a move.

I can’t really see a case in which my merge doesn’t work in as i tried the 32 possibilities in the first row with the numbers 2 and 0 considering also the first tile in the next row and it worked in all of them. Do you have any advice about what can I do ?

Well, if you take a further look at that test, you can see this code:

	la $t0 board
	la $t1 buf

   	sw $t0 0($t1)
	addiu $t0 $t0 2
	sw $t0 4($t1)
	addiu $t0 $t0 2
	sw $t0 8($t1)
	addiu $t0 $t0 2
	sw $t0 12($t1)

	la $a0 buf
	la $a1 4
	jal merge

So the public test constructs a row-pointer-array corresponding to the first row, and then invokes your code on that row only. Any other row should not be changed.

So yes, your merge code should only modify one row (i.e. the row it is given in $a0$, $a1). The tests test that the other rows remain unmodified. In the actual game, your code is invoked 4 times, once for each row.

1 Like

same thing for me I can not find a test where my code fails, and my code only changes the given row, maybe in sheets merge is not defined correctly? or I miss a edge case that I cannot find for 2 days now.

1 Like