0 Members and 3 Guests are viewing this topic.
.J2048Fix 5.I WILL ADD RANDOM BLOCKS ONCE I GET THE ACTUAL ENGINE WORKINGData(0,0,0,0,0,2,1,1,6,5,4,3,7,8,9,10)->GDB1.THE DATA IS RECOVERED FROM LAST GAMEPLAY EVERY TIME FOR SOME REASON.I DON'T WANT THAT, I WANT IT RESETDRAW()While 1If getKey->K?<5.START OF BAD CODEFor(3)(K=1?11)+(K=2?13)+(K=3?14)+(K=4?4)->XFor(12)!If {X+(K=1?4)-(K=2?1)+(K=3?1)-(K=4?4)+GDB1->Z}^{X+GDB1}{Z}?1+{X+GDB1}->{Z} and 0->{X+GDB1}EndX+(K=4?1)+(K=3?4)-(K=2?4)-(K=1?1)^17->EndEnd.END OF BAD CODE. PLEASE FIX!EndDRAW()EndIf getKey(15)Fix 4ReturnLbl DRAWClrDraw0->r1For(4) and 0->r2For(4)If {r1/16*4+(r2/19)+GDB1}->r3Text(r3<10+(r3<7)+(r3<4)*2+r2+2,r1+4,e^(r3)>Dec)EndRectI(r2,r1,19,16)RectI(r2+1,r1+1,17,14)r2+19->r2Endr1+16->r1EndDispGraph
.Z2048B..........................Init........................Fix 5DiagnosticOffClrHome:ClrDraw1 -> Z.This 'resets' L1.(32 bytes because each element is 2 bytes,.and we have 16 elements.on a 4 by 4 array!)Fill(L1,32)..........................Main loop........................Repeat getKey(14).InputIf getKey<5 1 -> Z If getKey(1) UP() ElseIf getKey(2) LEFT() ElseIf getKey(3) RIGHT() ElseIf getKey(4) DOWN() EndEndIf Z 0 -> Z UPDATE()EndRENDER()EndReturn..........................Functions!..........................Lbl UPReturnLbl CUPReturnLbl LEFTReturnLbl CLEFTReturnLbl RIGHTReturnLbl CRIGHTReturn... !!! Just look at DOWN/CDOWN; Same concept. But you'll have to deal with rows/columns being transposed.. *Omited for brevityLbl DOWN For(I, 0, 11) If {I * 2 + L1)r -> A CDOWN() End EndReturnLbl CDOWN .For from one row past evaluated element until last row For(J, I / 4 + 1, 3) .Column I ^ 4 -> C .If value of next row element == value of evaluated cell If {J * 4 + C * 2 + L1}r -> V = A .Double of value is stored and evaluated cell is zero'd A * 2 -> {J * 4 + C * 2 + L1}r 0 -> {I * 2 + L1)r Return ElseIf V = 0 .If value of next row element != value of evaluated cell, but not equal to 0 ElseIf .Cell is zero'd, and its value, still in A, is moved to one row before the evaluated cell 0 -> {I * 2 + L1}r A -> {J * 4 + C * 2 - 8 + L1}r Return End End .If we're already here, that means none of the evaluated rows met our conditions. 0 -> {I * 2 + L1)r A -> {12 + C * 2 + L1}rReturn.Creates an array of every.free address with a sum.Writes '2' to a random free addressLbl UPDATEFor(I, 0, 15) -1 -> A !If{I * 2 + L1}r I * 2 + L1 -> {A * 2 + L2}r A++ EndEndIf A = -1 ReturnEnd2 -> {{rand^A * 2 + L2}r}rReturnLbl RENDERClrDrawFor(I, 0, 15) Text(I / 4 * 32, I ^ 4 * 8, {I * 2 + L1}rEndDispGraph
Alright, I'll try. I'm not too good myself, but I can offer a quick take on 2048Then you can try merging in parts you like.2048 is relatively simple, so I favour readability over optimization.Please pardon me if my schematics or writing conventions are off, I don't know how to write tokens properly on this forum. And maybe it isn't allowed to use quote tags instead of code tags for code? (These code tags don't allow for any syntax highlighting rules )Spoiler For Spoiler: Quote.Z2048B..........................Init........................Fix 5DiagnosticOffClrHome:ClrDraw1 -> Z.This 'resets' L1.(32 bytes because each element is 2 bytes,.and we have 16 elements.on a 4 by 4 array!)Fill(L1,32)..........................Main loop........................Repeat getKey(14).InputIf getKey<5 1 -> Z If getKey(1) UP()ElseIf getKey(2)LEFT()ElseIf getKey(3) RIGHT()ElseIf getKey(4)DOWN()EndEndIf Z0 -> ZUPDATE()EndRENDER()EndReturn..........................Functions!..........................Lbl UPReturnLbl CUPReturnLbl LEFTReturnLbl CLEFTReturnLbl RIGHTReturnLbl CRIGHTReturn... !!! Just look at DOWN/CDOWN; Same concept. But you'll have to deal with rows/columns being transposed.. *Omited for brevityLbl DOWN For(I, 0, 11)If {I * 2 + L1)r -> A CDOWN() End EndReturnLbl CDOWN .For from one row past evaluated element until last row For(J, I / 4 + 1, 3) .Column I ^ 4 -> C .If value of next row element == value of evaluated cell If {J * 4 + C * 2 + L1}r -> V = A .Double of value is stored and evaluated cell is zero'd A * 2 -> {J * 4 + C * 2 + L1}r 0 -> {I * 2 + L1)r Return ElseIf V = 0 .If value of next row element != value of evaluated cell, but not equal to 0 ElseIf .Cell is zero'd, and its value, still in A, is moved to one row before the evaluated cell 0 -> {I * 2 + L1}r A -> {J * 4 + C * 2 - 8 + L1}r Return End End .If we're already here, that means none of the evaluated rows met our conditions. 0 -> {I * 2 + L1)r A -> {12 + C * 2 + L1}rReturn.Creates an array of every.free address with a sum.Writes '2' to a random free addressLbl UPDATEFor(I, 0, 15) -1 -> A !If{I * 2 + L1}r I * 2 + L1 -> {A * 2 + L2}r A++ EndEndIf A = -1 ReturnEnd2 -> {{rand^A * 2 + L2}r}rReturnLbl RENDERClrDrawFor(I, 0, 15) Text(I / 4 * 32, I ^ 4 * 8, {I * 2 + L1}rEndDispGraphEdit: I can see why I shouldn't have used quotes now (It's huge!). I hope the moderators are fine with this once in a while.Edi2: Spoiler tags save the screen!
.Z2048B..........................Init........................Fix 5DiagnosticOffClrHome:ClrDraw1 -> Z.This 'resets' L1.(32 bytes because each element is 2 bytes,.and we have 16 elements.on a 4 by 4 array!)Fill(L1,32)..........................Main loop........................Repeat getKey(14).InputIf getKey<5 1 -> Z If getKey(1) UP()ElseIf getKey(2)LEFT()ElseIf getKey(3) RIGHT()ElseIf getKey(4)DOWN()EndEndIf Z0 -> ZUPDATE()EndRENDER()EndReturn..........................Functions!..........................Lbl UPReturnLbl CUPReturnLbl LEFTReturnLbl CLEFTReturnLbl RIGHTReturnLbl CRIGHTReturn... !!! Just look at DOWN/CDOWN; Same concept. But you'll have to deal with rows/columns being transposed.. *Omited for brevityLbl DOWN For(I, 0, 11)If {I * 2 + L1)r -> A CDOWN() End EndReturnLbl CDOWN .For from one row past evaluated element until last row For(J, I / 4 + 1, 3) .Column I ^ 4 -> C .If value of next row element == value of evaluated cell If {J * 4 + C * 2 + L1}r -> V = A .Double of value is stored and evaluated cell is zero'd A * 2 -> {J * 4 + C * 2 + L1}r 0 -> {I * 2 + L1)r Return ElseIf V = 0 .If value of next row element != value of evaluated cell, but not equal to 0 ElseIf .Cell is zero'd, and its value, still in A, is moved to one row before the evaluated cell 0 -> {I * 2 + L1}r A -> {J * 4 + C * 2 - 8 + L1}r Return End End .If we're already here, that means none of the evaluated rows met our conditions. 0 -> {I * 2 + L1)r A -> {12 + C * 2 + L1}rReturn.Creates an array of every.free address with a sum.Writes '2' to a random free addressLbl UPDATEFor(I, 0, 15) -1 -> A !If{I * 2 + L1}r I * 2 + L1 -> {A * 2 + L2}r A++ EndEndIf A = -1 ReturnEnd2 -> {{rand^A * 2 + L2}r}rReturnLbl RENDERClrDrawFor(I, 0, 15) Text(I / 4 * 32, I ^ 4 * 8, {I * 2 + L1}rEndDispGraph
I don't have enough time now to help you (I'll come back this afternoon) but you should check my topic about the 2048 I made, in the first post there's explanation about that (making it so that 8-4-4-0 changes to 0-0-8-8 and not 0-0-0-16).