Author Topic: Axe 2048 help?  (Read 17818 times)

0 Members and 1 Guest are viewing this topic.

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Axe 2048 help?
« on: April 03, 2014, 02:02:53 pm »
This code apparently has an error, in sliding. I don't know what's wrong, and I hope anyone can extract the bad code and replace it with good code.
Code: [Select]
.J2048
Fix 5
.I WILL ADD RANDOM BLOCKS ONCE I GET THE ACTUAL ENGINE WORKING
Data(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 RESET
DRAW()
While 1
If getKey->K?<5
.START OF BAD CODE
For(3)
(K=1?11)+(K=2?13)+(K=3?14)+(K=4?4)->X
For(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}
End
X+(K=4?1)+(K=3?4)-(K=2?4)-(K=1?1)^17->
End
End
.END OF BAD CODE. PLEASE FIX!
End
DRAW()
EndIf getKey(15)
Fix 4
Return
Lbl DRAW
ClrDraw
0->r1
For(4)
 and 0->r2
For(4)
If {r1/16*4+(r2/19)+GDB1}->r3
Text(r3<10+(r3<7)+(r3<4)*2+r2+2,r1+4,e^(r3)>Dec)
End
RectI(r2,r1,19,16)
RectI(r2+1,r1+1,17,14)
r2+19->r2
End
r1+16->r1
End
DispGraph
Anyone, help?
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline Caustic

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 9
  • Rating: +0/-0
    • View Profile
Re: Axe 2048 help?
« Reply #1 on: April 04, 2014, 03:10:09 am »
Alright, I'll try. I'm not too good myself, but I can offer a quick take on 2048
Then 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 5
DiagnosticOff
ClrHome:ClrDraw
1 -> 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)
.Input
If getKey<5
    1 -> Z
    If getKey(1)
        UP()
   ElseIf getKey(2)
        LEFT()
   ElseIf getKey(3)
        RIGHT()
   ElseIf getKey(4)
        DOWN()
   End
End

If Z
   0 -> Z
   UPDATE()
End

RENDER()
End
Return
........................
..Functions!
........................
..
Lbl UP
Return
Lbl CUP
Return

Lbl LEFT
Return
Lbl CLEFT
Return


Lbl RIGHT
Return
Lbl CRIGHT
Return
..
. !!! Just look at DOWN/CDOWN; Same concept. But you'll have to deal with rows/columns being transposed.
. *Omited for brevity


Lbl DOWN
    For(I, 0, 11)
       If {I * 2 + L1)r -> A
            CDOWN()
        End
    End
Return

Lbl 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}r
Return

.Creates an array of every
.free address with a sum
.Writes '2' to a random free address
Lbl UPDATE
For(I, 0, 15)
    -1 -> A
    !If{I * 2 + L1}r
         I * 2 + L1 -> {A * 2 + L2}r
         A++
    End
End
If A = -1
    Return
End
2 -> {{rand^A * 2 + L2}r}r
Return

Lbl RENDER
ClrDraw
For(I, 0, 15)
    Text(I / 4 * 32, I ^ 4 * 8, {I * 2 + L1}r
End
DispGraph

Edit: I can see why I shouldn't have used quotes now :P (It's huge!). I hope the moderators are fine with this once in a while.
Edi2: Spoiler tags save the screen!
« Last Edit: April 04, 2014, 11:33:44 am by Caustic »

Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Axe 2048 help?
« Reply #2 on: April 04, 2014, 07:34:52 am »
It's alright I guess. You can always use a spoiler tag to auto hide it though. :)

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Axe 2048 help?
« Reply #3 on: April 04, 2014, 12:40:03 pm »
Alright, I'll try. I'm not too good myself, but I can offer a quick take on 2048
Then 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 5
DiagnosticOff
ClrHome:ClrDraw
1 -> 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)
.Input
If getKey<5
    1 -> Z
    If getKey(1)
        UP()
ElseIf getKey(2)
LEFT()
ElseIf getKey(3)
        RIGHT()
ElseIf getKey(4)
DOWN()
End
End

If Z
0 -> Z
UPDATE()
End

RENDER()
End
Return
........................
..Functions!
........................
..
Lbl UP
Return
Lbl CUP
Return

Lbl LEFT
Return
Lbl CLEFT
Return


Lbl RIGHT
Return
Lbl CRIGHT
Return
..
. !!! Just look at DOWN/CDOWN; Same concept. But you'll have to deal with rows/columns being transposed.
. *Omited for brevity


Lbl DOWN
    For(I, 0, 11)
If {I * 2 + L1)r -> A
            CDOWN()
        End
    End
Return

Lbl 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}r
Return

.Creates an array of every
.free address with a sum
.Writes '2' to a random free address
Lbl UPDATE
For(I, 0, 15)
    -1 -> A
    !If{I * 2 + L1}r
         I * 2 + L1 -> {A * 2 + L2}r
         A++
    End
End
If A = -1
    Return
End
2 -> {{rand^A * 2 + L2}r}r
Return

Lbl RENDER
ClrDraw
For(I, 0, 15)
    Text(I / 4 * 32, I ^ 4 * 8, {I * 2 + L1}r
End
DispGraph

Edit: I can see why I shouldn't have used quotes now :P (It's huge!). I hope the moderators are fine with this once in a while.
Edi2: Spoiler tags save the screen!

Well, do you think I (or you) could change your algorithm a bit? I store the board as one-byte numbers that are THE powers of two that the blocks are (i.e. 2 is stored as 1, 4 as 2, 8 as 3, etc.).
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Axe 2048 help?
« Reply #4 on: April 08, 2014, 01:09:33 am »
Quote for code is fine when you want formatting. Just make sure to disable emoticons since sometimes code turns into smileys. :P

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Axe 2048 help?
« Reply #5 on: April 08, 2014, 11:56:07 am »
I only ask Caustic: did you compile and test the code before giving it to me? Because no matter how I use it, it doesn't work.
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline TheCoder1998

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 434
  • Rating: +20/-2
  • my art is written in code, not in graphite
    • View Profile
    • My website :D
Re: Axe 2048 help?
« Reply #6 on: April 10, 2014, 02:12:52 pm »
Are you still working on this?
I would love to have a stable version of 2048 on my calc :D
my ticalc acc:

http://www.ticalc.org/archives/files/authors/113/11365.html

Spoiler For The Best Song Ever:


follow me on tumblr :)
www.rickdepizza.tumblr.com

check out my anilist :D
http://anilist.co/animelist/29701/Rickdepizza

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Axe 2048 help?
« Reply #7 on: April 11, 2014, 10:18:24 am »
I am honestly trying SO hard figuring out where the fault in my code is. Honestly, so hard. :\


I don't know if I'll be able to finish it (let alone get it off the ground), so hopefully someone can help.


My board data is stored as the power of 2 that the tile is (1 is 2, 2 is 4, 3 is 8, etc.). It starts at {L1} and ends at {L1+15}.
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline Soulthym

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 17
  • Rating: +1/-0
    • View Profile
Re: Axe 2048 help?
« Reply #8 on: April 12, 2014, 08:30:05 am »
I' m actually doing an unoptimized version of 2048 in Axe, ill post it soon if it can help^^

Offline TheCoder1998

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 434
  • Rating: +20/-2
  • my art is written in code, not in graphite
    • View Profile
    • My website :D
Re: Axe 2048 help?
« Reply #9 on: April 12, 2014, 08:31:55 am »
hey soulthym, you should introduce yourself here http://www.omnimaga.org/introduce-yourself!/
i forgot to do that when i was a noob (i eventually did it)
my ticalc acc:

http://www.ticalc.org/archives/files/authors/113/11365.html

Spoiler For The Best Song Ever:


follow me on tumblr :)
www.rickdepizza.tumblr.com

check out my anilist :D
http://anilist.co/animelist/29701/Rickdepizza

Offline Soulthym

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 17
  • Rating: +1/-0
    • View Profile
Re: Axe 2048 help?
« Reply #10 on: April 12, 2014, 08:47:43 am »
Sorry I thought I already did it last year^^'
Fully functionnal version soon!

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Axe 2048 help?
« Reply #11 on: April 13, 2014, 08:49:07 pm »
And test it? :P
But yeah, I really have been waiting for a working implementation. The sliding, for some reason, DOES NOT WORK, no matter how I try.
« Last Edit: April 13, 2014, 08:54:47 pm by JWinslow23 »
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Axe 2048 help?
« Reply #12 on: April 16, 2014, 04:56:33 pm »
Bump.

I have some code with sliding, yet it STILL doesn't work.

Could someone give me some help? Basically, with making sure that tiles don't merge with tiles that have already been merged in that same slide.

The pastebin is at http://pastebin.com/ffrFGSjM .
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline Toctave

  • LV2 Member (Next: 40)
  • **
  • Posts: 22
  • Rating: +2/-0
    • View Profile
Re: Axe 2048 help?
« Reply #13 on: April 17, 2014, 02:38:40 am »
Hi!
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). Basically you should have a variable pointing to the position before the last merge, where the blocks should stop.


Btw I can't really understand how your code works, could you add comments to it?

Offline ClrDraw

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 627
  • Rating: +61/-2
    • View Profile
    • GitHub
Re: Axe 2048 help?
« Reply #14 on: April 17, 2014, 09:50:52 am »
Quote
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).
I just fixed that yesterday in my version, I stored in the memory whether the block had been combined with another block already and wouldn't let it combine twice (if thats confusing, let me know).
Visit my GitHub for all my TI programs as well as other projects.
Also check out my website.