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.
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.