@JWinslow23:
In this thread you have not explained what you want, just shown us a code segment. I don't know what 2048 nor "sliding code" are, but you posted this expected output:
JWinslow23 wrote:Sample starting configuration (determined randomly):
0 2 0 0
0 0 0 0
0 0 0 4
0 0 0 0
Expected output:
0 0 0 0
0 0 0 0
0 0 0 0
0 2 0 4
Sample starting configuration:
0 0 2 0
0 0 0 0
0 0 0 0
0 0 2 0
Expected output:
0 0 0 0
0 0 0 0
0 0 0 0
0 0 4 0
So I
assumed (perhaps incorrectly) that your ":movedown" routine must accumulate in last row the values of previous rows and reset they to zero after, so I wrote a code that do that. Also, I changed the letters in CHOICE command so X=movedown (because it is down in the keyboard), but this point is clearly marked in my code: ":label-3 EXIT", ":label-5 DOWN". If you want that S be down and X exit, just reorder the string in CHOICE command...
This is an output example of my program:
Code: Select all
2 0 0 0
4 0 0 0
0 0 0 0
0 0 0 0
[W,A,S,D,X]?X
0 0 0 0
0 0 0 0
0 0 0 0
6 0 0 0
[W,A,S,D,X]?S
-----------------
2 0 0 0
0 0 2 0
0 0 0 0
0 0 0 0
[W,A,S,D,X]?X
0 0 0 0
0 0 0 0
0 0 0 0
2 0 2 0
[W,A,S,D,X]?S
-----------------
0 0 0 0
2 0 0 0
0 0 0 0
0 0 0 2
[W,A,S,D,X]?X
0 0 0 0
0 0 0 0
0 0 0 0
2 0 0 2
[W,A,S,D,X]?S
The board is a two-dimensional arrangement of numbers, so the "natural" way to implement it is via a two-dimensional array. Of course, you may manage it via a one-dimensional array and perform conversions of the required two-dimensional indices into a single index that map the equivalent position, but this method is more difficult to implement...
Antonio