#2048 Tilt method not working correctly
63 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @dire knoll! Please use
/closeor theClose Postbutton 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.
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 ?
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
so we move all items up to the very top
yeah but we move all items up since we changed our perspective.
you are iterating over the area you are manipulating I don't like that.
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
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.
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
we'll get to that. It's easier to follow what's happening when the code isn't cluttered
ok
And move() does also move the tile if the space is already occupied ?
does merge remove the tile ?
otherwise you found your error
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
oh yeah I just say it, sorry.
from the snippets you sent all looks to be correct. I can't tell you why it would not work.
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.
were these other methods given ?
which ones
move merge setViewingPerspective
and you should move tiles from your repective viewing perspective to the last row and not to the top ?
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
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++;
}
}
}
same issue or something else entirely ?
same issue
can you delete on the board manually ?
do you have access to the underlying array ?
i do
but i will not get credit if i alter it
it is okay
ill just call it here
i appreciate the help
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.
i will ask around this week and see if i can get it to work