#2048 Tilt method not working correctly

63 messages · Page 1 of 1 (latest)

pulsar tideBOT
#

This post has been reserved for your question.

Hey @dire knoll! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

fierce stirrup
#

the first thing you do is changing the viewing perspective. How does that transform the board ? Should all tiles now be moved to the top or to the bottom ?

dire knoll
#

the Board
class has a setViewingPerspective(Side s) function that will change the
behavior of the tile and move classes so that they behave as if the given side was
NORTH

#

From the specs ^

#

Basically it makes it so that no matter what side it is, it behaves as if it were the north side

#

That way we only have to worry about moving the tile in one direction as opposed to 4

fierce stirrup
#

so we move all items up to the very top

dire knoll
#

not necessarily

#

it just saves me from code redundency

fierce stirrup
#

yeah but we move all items up since we changed our perspective.

dire knoll
#

sure

#

it just makes it a little easier to work with the board

fierce stirrup
#

you are iterating over the area you are manipulating I don't like that.

dire knoll
#

also we can assume that .tile() .move() and .value() work correctly

#

uh

#

its fine

#

we dont need to make a copy of the board or anything

fierce stirrup
#

yeah but you are actively moving tiles around.
I must correct myself you are moving all tiles to the bottom not the top. I'd actually work with two Indices in this case. One that keeps track where the next tile you encounter should be placed and the other for iterating.

#

that will replace the while loop

#

and invert the first if so you don't have to nest that much

#

and I just noticed but you are actually not looking at the first row.

dire knoll
#

im not too worried about how its structuted, i just wanna fix the logic. The tile that was merged is still on the board for some reason

fierce stirrup
#

we'll get to that. It's easier to follow what's happening when the code isn't cluttered

dire knoll
#

ok

fierce stirrup
#

And move() does also move the tile if the space is already occupied ?

#

does merge remove the tile ?

#

otherwise you found your error

dire knoll
#

I have been told that move is supposed to take care of the tile after the function is called

#

It will mark the old space as empty after the function has been called

fierce stirrup
#

oh yeah I just say it, sorry.

dire knoll
#

youre good

#

i just cannot figure out why the output is wrong

fierce stirrup
#

from the snippets you sent all looks to be correct. I can't tell you why it would not work.

dire knoll
#

i gave it the old college try

#

I give up

#

thank you

#

lol

pulsar tideBOT
# dire knoll thank you

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

fierce stirrup
#

were these other methods given ?

dire knoll
#

which ones

fierce stirrup
#

move merge setViewingPerspective

dire knoll
#

yes

#

they work

fierce stirrup
#

and you should move tiles from your repective viewing perspective to the last row and not to the top ?

dire knoll
#

all that function does act like your turning your head 90 or 180 degrees whichever direction

#

it just helps so that you dont have to account for every side

fierce stirrup
#

Honestly, try this code and tell if that worked:

for(int row = size-1, nextPos = size-1; row >= 0; row--) {
    Tile currentTile = _board.tile(col,row);
    if(currentTile == null) {
        continue;
    }
    if(row != nextPos) {
        _board.move(col,nextPos,currentTile);  
        merged = false;
    }
    nextPos--;
    if(nextPos < size-1 && !merged) {
        Tile tileBelow = _board.tile(col,newRow+1);
        if(tileBelow.value() == currentTile.value()) {
            int mergedValue = currentTile.value()*2;
            _score += mergedValue;
            _board.move(col,newRow+1,currentTile);
            merged = true;
            nextPos++;
        }
    }
}
dire knoll
#

it did not

#

rip

fierce stirrup
#

same issue or something else entirely ?

dire knoll
#

same issue

fierce stirrup
#

can you delete on the board manually ?

dire knoll
#

unfortunately no

#

i tried

fierce stirrup
#

do you have access to the underlying array ?

dire knoll
#

i do

#

but i will not get credit if i alter it

#

it is okay

#

ill just call it here

#

i appreciate the help

fierce stirrup
#

maybe someone else can help you. Maybe I didn't spot something extremly obvious. I'd like to get pinged if it does get solved in the end though.

dire knoll
#

i will ask around this week and see if i can get it to work