Hey! I've been working on a hybrid basic version of 2048 for the monochrome calcs.

It's winnable too! Here's a screenshot of me winning (graphic errors on 1024/2048 have been fixed).


And if you'd like to download it right now, here you go: http://www.cemetech.net/programs/index.php?mode=file&id=1053

But I want to know if it can run faster, and seeing as I'm not really the best basic programmer in the world, I'd like some help. If you want to help optimize it, here's the code (written for TokenIDE).

Code:
#define RAMFILE "rowSwap(UK\L2048"
#define ARCHFILE "rowSwap(UK\L2048A"
:DCS6
"FFFE80028C4282A284A288A28E42800288E28AA28EE282A282E28002FFFE0000
ClrHome
If 1337!=DetectDCS(:Then
Disp "THIS PROGRAM","REQUIRES DOORSCS","DOWNLOAD FROM","DCS.CEMETECH.NET"
Return
End
RunIndicator(0
ClearScreen(,1
"LOADING...
Text(96/2-StringWidth(,Ans)/2,30,Ans
ClearScreen(,0
//Generate the sprites for the tiles
For(B,1,11)
NumToString(2^B)->Str1
iPart(B/6)->A
Ans16->Y
(B-6A)16->X
//Don't draw text for 1024/2048
If B<=9:Then
DrawText(0,Ans+8-StringWidth(,Str1)/2,Y+4,Str1
End
DrawShape(3,X,Y,X+14,Y+14,0
End
//Special cases for 1024/2048 text
DrawText(0,68,17,"10
DrawText(0,68,23,"24
DrawText(0,84,17,"20
DrawText(0,84,23,"48
//Store sprites to Pic1
StorePic 1
//Could be done differently, but basically just
//set [A] to 4x4 and zero it
{4,4->dim([A]
//Ensures L1 and L2 exist for ClrList
0->dim(L1
0->dim(L2

//The following code will set N to 1
//if we loaded from a file
0->N
//If ram file exists load from that.
//Else create ram, if arch file exists load from that.
LineRead(RAMFILE,1,1
If Ans=".7":Then
LineRead(ARCHFILE,1,1
If Ans!=".7":Then
expr(Ans->[A]
1->N
End
ToggleSet(RAMFILE,5
LineWrite(RAMFILE,NumToString([A]),1
Else
expr(Ans->[A]
1->N
ToggleSet(RAMFILE,7
If "A"=sub(ToggleSet(RAMFILE,7),1,1:Then
//Ensure it's not archived
ToggleSet(RAMFILE,0
End
End

If N:Then
0->N
Menu("==Load Game?==","Yes",LD,"No",NW
Lbl NW
1->N
Lbl LD
Else
1->N
End

//N is 1 for new game, 0 for load
If N:Then
Fill(0,[A]
//Generate first piece
randInt(1,4->S
randInt(1,4->T
(randInt(1,8)<=2)+1->[A](S,T
End

ClearScreen(,0
//Line on the right side of the screen marking the
//game board border
DrawShape(0,64,0,64,63,0

//Draw board and update lcd
DrawTileMap(0,0,0,64,64,0,4,0,4,1,0,16,1


0->K
Repeat Ans=15
If Ans:Then

(Ans=2)-(Ans=3)->X
(K=4)-(K=1)->Y
If X or Ans:Then
//F will be set to 1 if we moved.
0->F
Text(29,66,"Loading...

//If we moved on the x axis, run this code. Comments here also apply
//to the y axis code.
If X:Then
//These are used to switch which wall searching starts from
(X=~1)4+(X=1)1->S
Ans+3X->E
For(A,S,Ans-X,X)
For(B,1,4)
//The tile we will merge other tiles in to
[A](B,A->|N
For(C,A+X,E,X)
[A](B,C

//Only do checks if [A](B,C is occupied
If Ans:Then
//We have to check if |N isn't 0 each loop
//because, it can potentially be set to in the loop
If |N:Then
//What this does: If |N=Ans, increment [A](B,A. Otherwise, don't
//modify anything. Finally, exit the loop
(|N!=Ans)Ans->[A](B,C
//Set F to 1 if we moved a piece
|N+not(Ans->[A](B,A
//Inc F if we moved a piece
F+Ans-|N->F
E->C
Else
//[A](B,A is 0, just move the tile to it. Set |N so we can merge
//other tiles as well
Ans->|N
Ans->[A](B,A
0->[A](B,C
1->F
End
End

End
End
End

//If we moved on the y axis, run this code
Else
(Y=~1)4+(Y=1)1->S
Ans+3Y->E
For(A,S,Ans-Y,Y)
For(B,1,4)
[A](A,B->|N
For(C,A+Y,E,Y)
[A](C,B

If Ans:Then
If |N:Then
(|N!=Ans)Ans->[A](C,B
|N+not(Ans->[A](A,B
//Inc F if we moved a piece
F+Ans-|N->F
E->C
Else
Ans->|N
Ans->[A](A,B
0->[A](C,B
//Set F to 1 if we moved a piece
1->F
End
End

End
End
End

End


//Only generate a piece if others were moved
If F:Then
//Try 5 times to generate a spot
For(A,1,5)
randInt(1,4->S
randInt(1,4->T
If not([A](S,Ans:Then
//We found a spot! break out of the loop
5->A
End
End
//If we picked a filled spot 5 times, just do a search
//for all the empty ones and pick from those.
//This can be faster than continually guessing.
If [A](S,T:Then
ClrList L1
ClrList L2

//Generate lists of all empty row/column pairs
For(A,1,4)
For(B,1,4)
If not([A](B,A:Then
B->L1(1+dim(L1
A->L2(1+dim(L2
End
End
End
randInt(1,dim(L1
(randInt(1,8)<=2)+1->[A](L1(Ans),L2(Ans
Else
//Hooray we picked an empty spot, we can just put a piece there
(randInt(1,8)<=2)+1->[A](S,T
End
End

//Save to ram save file
LineReplace(RAMFILE,NumToString([A]),1,1

//Draw the tiles. screen is cleared to remove the
//"Loading" text
ClearScreen(,0
DrawShape(0,64,0,64,63,0
DrawTileMap(0,0,0,64,64,0,4,0,4,1,0,16,1
End
End
GetKey(->K
End
//If archive file doesnt exist, create it, otherwise unarchive it. Save to it, rearchive
ToggleSet(ARCHFILE,7
If Ans=".7":Then
ToggleSet(ARCHFILE,5
LineWrite(ARCHFILE,NumToString([A]),1
Else
If "A"=sub(Ans,1,1
ToggleSet(ARCHFILE,0
LineReplace(ARCHFILE,NumToString([A]),1,1
End
ToggleSet(ARCHFILE,0
ClrHome
Disp "Calc2048","By Unknownloner"
Nice work! I would guess that if you're using DoorsCS for graphics you should even be able to animate the tiles while the "thinking" phase is taking place.
Not worth the slow down, it's slow enough as it is.
It's Awesome!
Please include score and high score.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement