2048 Game: How to overcome this bug?

Feb 6, 2019 at 11:30pm


I am testing it using:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

int main(){

    std::vector<int> v{1,1,1,1};

    bool c = game_over(v);

    if(c){
        std::cout << "true" << std::endl;
    }

    if(!c){
        std::cout << "false" << std::endl;
    }

    return 0;
}
Last edited on Feb 7, 2019 at 8:12pm
Feb 6, 2019 at 11:36pm
What's 2048 game?
Post runnable code.
Feb 6, 2019 at 11:41pm
Hi dutch.

This here is an example of the 2048 game: http://2048game.com/

The code I have above and the test do run and do compile It's just that it only returns false.
Last edited on Feb 6, 2019 at 11:41pm
Feb 6, 2019 at 11:56pm
The code doesn't compile. It's missing headers and twod_to_oned.
The 2048 game is not entirely comprehensible to me.
In particular, I have no idea what a "game over" situation would be, and I have no idea what your initial setup in main, {1, 1, 1, 1} would mean. Is that game over? Why? Is your grid 4 x 4 or not?

One thing I notice is that your i < length should be i < length - 1. Same with j < length.
Last edited on Feb 7, 2019 at 12:08am
Feb 7, 2019 at 12:32am
In particular, I have no idea what a "game over" situation would be
When there are no more possible moves. I.e. There are no empty spaces in the board and there are no adjacent pieces of the same value.
Feb 7, 2019 at 11:01am
I do not see why it should be length -1. For example. If we consider a 4 by 4 square, the length would equal 4. now this means that the maximium i values should be 3 and so if it was i < length max value would be 3 whereas if we put length -1 max value would be 2 which is incorrect.
Feb 7, 2019 at 11:05am
The problem isn't i, it's i+1 (see line 19).

Post compileable code if you wish for assistance.
Feb 7, 2019 at 11:16am
Ah! I have solved it thank you.
Topic archived. No new replies allowed.