If max(Ans={[A](X,Y),0:Then

also, on the line 1->tetha, what is tetha? ]]>

Ive a question. The algorithm you described after the code is a possible algorithm to be applied, or is it correspondent to the piece of code you posted?

I tested your piece of code, and it works quite well and quite fast. Yet, ive spotted at least two errors.

1st - Imagine you have the tiles in the following configuration (actually tested):

8 0 0 4

8 0 0 0

2 0 0 0

4 0 0 0

I pressed the up key. It was supposed to become like this:

16 0 0 4

2 0 0 0

4 0 0 0

0 0 0 0 (with a random number somewhere)

But it got like this:

16 0 0 4

0 0 0 0

2 0 0 0

4 2 0 0 (the random number being 2 at (4,2))

After that, i pressed the right key and it got like this:

0 0 16 4

0 0 0 0

4 0 0 2

4 0 0 2 (the random number being 4 at (3,1))

2nd - imagine you have the tiles like this:

8 0 2 0

4 0 0 0

4 0 0 0

4 0 0 0

I pressed the up key and it was supposed to become like this:

8 0 2 0

8 0 0 0

4 0 0 0

0 0 0 0 (with a random number somewhere)

But it got like this:

8 0 2 0

4 0 0 0

8 0 0 0

2 0 0 0 (the random number being 2 at (4,1))

Mine is a bit slower than yours, but i guess it has all the features included already. Could u take a look? It is quite messy, and the logical part works like this: i test a certain set of conditions outside the condition-testing areas following the If commands and then i recall the logical value. So all youre gonna see is propositions being tested and the corresponding letters being logically tested at If conditionals. That makes it easier to understand the meaning of each proposition. The code goes as follows (only the main loop):

`... Ive kept the entire K= part outside the testing area, so if you'd like o see just scroll up. Yet that's not the most important part. That is the one inside the innermost For( loop ... Fill(0,[B] //this matrix will store the tiles that have already suffered from summing up. This is a way to make sure no tiles are added up more than once. [A]->[C] //to become the undo option ... For(Y,A,B,E For(X,C,D,F [A](X,Y->tetha If Ans:Then //skip if zero, obvious 0->P 0->Q 0->R 0->S //zeroing all variables. I guess i could take the zeroing at P and R. X->I Y->J // I and J will become the "possible coordinates" of the number being checked Repeat Ans //this loop will detect what limit values can I and J be I+G->I J+H->J max(1.5<{abs(I-2,5),abs(J-2,5->P // P=1 if I or J get outside the matrix dim If not(Ans [A](I,J // testing if there is an obstacle. But only testing if I and J are inside the matrix, otherwise it woule return ERR End If not(P:Then //Q and S can only be tested if I and J are inside the matrix, otherwise returns ERR tetha=[A](I,J->Q //Q=1 if they are equal not([B](I,J->S // S=1 if the tile at (I,J) has already been summed up once End I-G=/=X or J-H=/=Y->R // equivalent to not(I-G=X and J-H=Y). It indicates if the tile should even be moved. If R=1, the tile should be moved, as otherwise it would be stored at the same coordinates, which is a lost of time If not(P) and Q and S:Then // quite difficult to find this condition, but it defines when the tiles should sum up 2tetha->[A](I,J 0->[A](X,Y 1->[B](I,J // this will indicate for further sums that (I,J) has alreadybeen summed up End If R and (P or not(Q and S:Then //even more difficult to find. It defines when should a tile be moved and where to. tetha->[A](I-G,J-H 0->[A](X,Y End End End End ...`

(I guess it might be easier to understsnd without any comments at all xD

// Edited: could u point out possible improvements or optimizations? That would be rly helpful

// Edited: in a previous post, u said For( loops would only calculate the minimum and maximum values once. Does that also apply to step?

]]>Uff!…

All the code i posted so far was manually entered by me from my calculator. So now ill just connect it to the PC and post it here. I would be very grateful if you could take a look at the code, try it on and inform me about possible improvements. Ill be sending the kinda-final version, displaying the tiles in the graph screen. See you later ]]>

It would start checking on the opposite direction of the movement. As a way to better explain it, imagine you press the left key. Let the tile being checked be named as tile A. Other tiles will also be "renamed".

It would first check if tile A is non-zero.

If so, the algorithm would check where is the left-most zero tile in that line, and store the coordinates of that tile (tile B). Then, it would check if the tile at the left of tile B (renamed tile C) is equal to tile A. If so, add them up and store it at tile C, and store zero at tile A.

But i just think it would take a bit more of knowledge, which i lack of. It would be great if you could give me your opinion on this option, evaluate how good would it be and how to program it. Ive already tried to do it, but it is so messy i think it's not worth posting it.

I guess there is in fact no problem with the K= part, as it avoids getting stuff inside the for loops, so i see no big advantage to remove the K= part and put it inside the loops instead. Besides that, i must recognize your suggestion comes from great knowledge of yours, but is essencially equal to the version ive been posting, just without the outermost For( loop. Yet, i

//Edited: I guess the extreme change in the content of the innermost For( loop would work as described below:

It would start checking as described above, by starting to check on the opposite direction of the movement. As a way to better explain it, imagine you press the left key. Let the tile being checked be named as tile A. Other tiles will also be "renamed".

It would first check if tile A is non-zero.

If so, the algorithm would check where is the left-most zero tile in that line, and store the coordinates of that tile (tile B). Then, it would check if the tile at the left of tile A (renamed tile C) is equal to tile A. If so, add them up and store it at tile C, and store zero at tile A.

But i just think it would take a bit more of knowledge, which i lack of. It would be great if you could give your opinion on this option, evaluate how good would it be and how to program it. (I think this option requires a new innermost For( or While loop )

I guess there is in fact no problem with the K= part, as it avoids getting stuff inside the for loops, so i see no big advantage to remove the K= part and put it inside the loops instead. Besides that, i must recognize your suggestion comes from great knowledge of yours, but is essencially equal to the version ive been posting, just without the outermost For( loop. Yet, the outermost loop does have a really specific and important task: to allow wide tile-moving, not being limited by 1 tile moves.

]]>//Edited: ive in fact tried it, and ive concluded that not only it doesnt move the tiles to the desired place, but it doesnt even seem to correctly move the tiles. Could you test the algorithm in a calculator of yours? Ive doble-checked the algorithm, and it is exacly the same as you posted. In the meanwhile, ill try to work on the algorith ive described earlier.

]]>@Silver Phantom, i tried to test your suggestion for M refreshing, but it returns a ERR:DATA TYPE when performing not([A]

@earthnite, i dont rly understand what do u mean by "using R&C instead of A&D".

Ill try do do some changes to your suggestion and implement it, although i might take a while.

But just by looking at yor code, i have 1 question:

Imagine a situation in which i only have a '2' tile at (1,3) and a '4' tile at (1,4).

Imagine i press the left arrow; If i start by checking the tiles from the right to the left, the '4' tile will remain in the same place as it was blocked by the '2' tile, and then the '2' tile will move to (1,1). But the '4' tile should move to (1,2), and not staying at (1,4). You could apply the same principle if you pressed the right arrow and you were checking from left to right and the '2' tile was at (1,2) and the '4' tile was at (1,1).

Thats the tricky part i guess

//Edited: I may in fact take quite a bit to understand your suggestion, so this situation might in fact be already ensured (i may confess i dont understand it at all, but give me some time :)

@earthnite, i fully agree as for your last sentence. My main problem is that im making 36 comparisons, so it would be great if i could somehow take out the outer For( loop, even if i had to expand the code being repeated. Reducing on the overall code is only important when dealing with parts that dont require speed, and thus can be reduced to save memory.

The thing is that i think i can not remove the outer For( loop without making some extreme change on the content of the innermost For( loop. This assumption is based on the above-explained situation.

Thanks for all the help. I'm wainting for feedback to my questions.

PS: im not an english native speaker, so any small sign of what might be arrogance is just because of my current linguistic condition xD

As for display lag, you dont have to worry at all, as im in fact using Text(, which seems to take about 2/3 (or less) of the time Output( takes.

If he already has a display function in the works, we can ignore display lag for the moment.

` 0->M For(X,1,4 // refreshing M For(X,1,4 If not([A](X,Y:Then M+1->M End End End`

can be

`0->M dim([A] Matrâ–ºlist(cumSum(not([A]))^^T^^,Ans(1),L1 sum(L1->M`

adapted from http://tibasicdev.wikidot.com/sum-of-matrix

this should be just slightly faster

]]>As for displayin the board, i guess i would have to do this:

`[A]->[B] ... Make all the updates to [A] ... ClrDraw For(X,1,4 For(Y,1,4 [A](X,Y If Ans and Ans=/=[B](X,Y Output(2X-1,4Y-3,Ans End End`

(untested). Yet, i dont know how much more efficient would it be.

As for your 1st suggestion, i cant rly understand what u mean by 'moving the movement code into the getkey loop'. Could u explain it better, or post a piece of code explaining it?

Thanks for the answer, i thought my thread would just stay abandoned with no answers.

BTW, I should just make clear that the main aspect of the versions ive been posting is the underlying code, meaning that the output is just a way to check if the underlying code is running well, as ive already been working on a quite atractive graphic display.

Im asking your help to accomplish one of the very few, if not the only one, 2048 game programmed in pure TI-BASIC, as ive observed that not one of all 2048 games in the archive of this website are written in pure TI-BASIC. I guess the main goal of this website, under the name of "TI-BASIC developer", should be teaching and help programming at TI-BASIC, maybe with a few asm routines. That would be rly important to promote the 'holy language' of TI calculators.

]]>Why hasnt anyone replied my thread? Cmon, please

Ive now done some stuff, and ive corrected the game-ending condition. I still need to implement the 'undo' and 'exit' options, but the most important is to optimize the code, as it still runs quite slowly. The code goes as follows:

`//[A] - Current board storing //M - Important at finding empty squares to insert a new random 2 or 4 square. M corresponds to the number of empty squares (in fact, they are not empty. They have a zero) //N - N=1 if there is at least a pair of neighbouring numbers that are equal, and thus can be summed up. N=0 if not. Meaning that, even when all squares are filled up, the game will only finish if: 1st - there are no empty spaces; and 2nd - there is no playing possibility that unlocks the game. Delvar [A] {4,4->dim([A] For(C,1,2 // for creating the innitial two '2'-squares Repeat not([A](A,B randInt(1,4->A randInt(1,4->B End 2->[A](A,B End ClrHome For(X,1,4 // Outputting the matrix for the 1st time For(Y,1,4 Output(2X-1,4X-3,[A](X,Y End End Repeat not(M+N // equivalent to the final sentence of the comment on N Repeat max(Ans={24,25,26,34 getkey->K End 1+(K=24)+2(K=26->A // start of some boring checking-limitation stuff. If i wasnt doing this, the calculator would try to recall numbers outside the matrix :) 4-3(K=26->B 1-2(K=26->E (K=24)-(K=26->G 1+(K=25)+2(K=34->C 4-3(K=34->D 1-2(K=34->F (K=25)-(K=34->H For(Z,1,4 // this is the most important loop, the one that slows it all down. It makes the summing and moving stuff For(Y,A,B,E For(X,C,D,F [A](X,Y->I [A](X-H,Y-G->J If max(J={I,0:Then I+J->[A](X-H,Y-G 0->[A](X,Y End End End End 0->M For(X,1,4 // refreshing M For(X,1,4 If not([A](X,Y:Then M+1->M End End End Repeat not(M[A](A,B // If M=/=0 (meaning, when there is at least 1 empty space), creates a new value randInt(1,4->A randInt(1,4->B End If M:Then 2randInt(1,2->[A](A,B M-1->M // if a new value is introduced, M will obviously decrease by 1 End 0->N // refreshing N For(X,1,4 For(Y,1,4 // in this loop there are two If conditionals 'wrapped' inside two If:Then conditionals, to avoid checking numbers outside the matrix [A](X,Y->C Output(2X-1,4Y-3,C If X<=3:Then // <= means 'lower or equal to' If C=[A](X+1,Y 1->N End If Y<=3:Then If C=[A](X,Y+1 1->N End End End End`

As ive said, the problem is most likely optimization, so it would be gr8 if you could help me.

]]>For now, ive only written the underlying code. It goes as follows:

`Delvar [A] {4,4->dim([A] randInt(1,4->A randInt(1,4->B 2->[A](A,B Repeat Z Repeat not([A](A,B randInt(1,4->A randInt(1,4->B End 2randInt(1,2->[A](A,B ClrHome For(X,1,4 For(Y,1,4 Output(2X-1,4Y-3,[A](X,Y End End Repeat max(Ans={24,25,26,34 getkey->K End 1+(K=24)+2(K=26->A 4-3(K=26->B 1-2(K=26->E (K=24)-(K=26->G 1+(K=25)+2(K=34->C 4-3(K=34->D 1-2(K=34->F (K=25)-(K=34->H For(Z,1,3 For(Y,A,B,E For(X,C,D,F [A](X-H,Y-G If max(Ans={[A](X,Y),0:Then // The big problem [A](X,Y)+Ans->[A](X-H,Y-G 0->[A](X,Y End End End End 1->tetha For(X,1,4 For(X,1,4 If not([A](X,Y:Then 5->X 5->Y End End End End`

It still has some things missing, like checking if the player still has any possible move before quitting instead of quitting when finding no place to put the new tile; score; aesthetical aspects; quitting button; etc., but i guess that these dont present a problem as big as the current speed. It takes quite alot to refresh the matrix.

It would be rly helpful if you could post optimization solutions.

PS: i think this code is quite flawless as ive tested it up to a 128 record (yey! xD

]]>