Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: JWinslow23 on April 03, 2014, 02:02:53 pm

Title: Axe 2048 help?
Post by: JWinslow23 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?
Title: Re: Axe 2048 help?
Post by: Caustic 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!
Title: Re: Axe 2048 help?
Post by: TIfanx1999 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. :)
Title: Re: Axe 2048 help?
Post by: JWinslow23 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.).
Title: Re: Axe 2048 help?
Post by: DJ Omnimaga 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
Title: Re: Axe 2048 help?
Post by: JWinslow23 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.
Title: Re: Axe 2048 help?
Post by: TheCoder1998 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
Title: Re: Axe 2048 help?
Post by: JWinslow23 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}.
Title: Re: Axe 2048 help?
Post by: Soulthym 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^^
Title: Re: Axe 2048 help?
Post by: TheCoder1998 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)
Title: Re: Axe 2048 help?
Post by: Soulthym on April 12, 2014, 08:47:43 am
Sorry I thought I already did it last year^^'
Fully functionnal version soon!
Title: Re: Axe 2048 help?
Post by: JWinslow23 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.
Title: Re: Axe 2048 help?
Post by: JWinslow23 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 .
Title: Re: Axe 2048 help?
Post by: Toctave 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?
Title: Re: Axe 2048 help?
Post by: ClrDraw 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).
Title: Re: Axe 2048 help?
Post by: JWinslow23 on April 17, 2014, 06:38:54 pm
I actually tried what ClrDraw said, only my implementation didn't work.

Toctave, I'll do what you said.


EDIT: I did what Toctave said, and all possible test conditions work properly! :D


ThankyouthankyouTHANK you! ;)


Oh, and I saw your game. The only two things I could think to add are animations, and graphics that actually show me what the tiles are. I'm confused; is a dot a 2 or a 4? :/
Title: Re: Axe 2048 help?
Post by: Toctave on April 18, 2014, 08:23:22 am
You're welcome for the help (didn't do much :D). And about my game, you can press 2nd to display the numbers that go with each tile. And I'm working on animations, tho it doesn't work well for now.
Title: Re: Axe 2048 help?
Post by: Eiyeron on April 18, 2014, 08:28:58 am
I saw that you didn't want the game to keep its grid intact after you quit and started again the game. That can be easily explained : you're using a part of your program as a buffer (the map), thus you edit on the fly the program's content. That explain what the grid isn't reset each time you launch the game. Fill the buffer with zeroes before editiing it! ;)
Title: Re: Axe 2048 help?
Post by: Hayleia on April 18, 2014, 11:17:16 am
Or use "external" safe RAM like the one pointed by L1, or L2, etc.
Title: Re: Axe 2048 help?
Post by: JWinslow23 on April 18, 2014, 01:07:50 pm
OK, it turns out I forgot to do a small check. My bad. :/


Fix coming soon!
Title: Re: Axe 2048 help?
Post by: JWinslow23 on May 01, 2014, 06:22:54 pm
Bump.

I just wanna say that my port is going along smoothly, and I already have most of the game mechanics coded! :D Here is a screenie:
(http://img.ourl.ca/2048AnimationsWorking.gif)

All I need is a Game Over check, and some sidebar graphics...

Source coming when the Game Over check does!
Title: Re: Axe 2048 help?
Post by: DJ Omnimaga on May 03, 2014, 11:29:29 pm
Nice so far :D
Title: Re: Axe 2048 help?
Post by: Streetwalrus on May 04, 2014, 02:33:29 am
For the game over check here's a nice algorithm : loop through all the tiles from the bottom left one moving up then right and perform the following checks :
-If the tile is empty, the game's not over. Stop the loop. You could also keep a counter for empty tiles, that would be faster because one less check in the loop which only gets executed if this counter hits 0. Every move would decrease it by 1 for the new random tile and every merge would increment it by 1.
-If not, check the tile to the right and above. If either is the same as the current tile, you can still do something. End the loop here.
-If both checks fail keep going.
-If you are on the last tile and it's not empty you can't make any move => you lost THE GAME.

Hope it helps and yes it looks pretty nice.
Title: Re: Axe 2048 help?
Post by: Hayleia on May 04, 2014, 04:36:03 am
Or something else you can do to detect a game over is to virtually run a left shift (as if the player pressed the left arrow), a right shift, an up shift and a down shift (of course you do it virtually, you don't show animations and you keep the original board intact) and you check if they are all the same as the original board.
Title: Re: Axe 2048 help?
Post by: Streetwalrus on May 04, 2014, 05:05:11 am
Yeah that works too. I take it that you meant "you keep the original board intact" though. :P
Title: Re: Axe 2048 help?
Post by: Hayleia on May 04, 2014, 05:16:20 am
What do you mean ? That's what I wrote :P
Title: Re: Axe 2048 help?
Post by: Streetwalrus on May 04, 2014, 05:31:56 am
Should have quoted the post before you edited it. :trollface:
Title: Re: Axe 2048 help?
Post by: TheCoder1998 on May 04, 2014, 05:55:46 am
this is looking really nice jwinslow :D
keep up the great work!
Title: Re: Axe 2048 help?
Post by: JWinslow23 on May 05, 2014, 04:50:57 pm
Streetwalrus and Hayleia, I already have a GAME OVER check (and I still want more :P ). What I did:
And Hayleia, I actually considered making a move LEFT, then UP, and doing a check as to if any tiles moved. This proved problematic, however. :P

TheCoder, thank you! I have new graphics coming soon (courtesy of Hayleia and me), but in the meantime, enjoy this (not quite so) new screenie of my sidebar graphics and score system:
(http://img.ourl.ca/2048Scoring.gif)

Download coming within the week!
Title: Re: Axe 2048 help?
Post by: Sorunome on May 06, 2014, 06:34:42 am
Looking nice, but IMO the animations are a bit slow >.>
Title: Re: Axe 2048 help?
Post by: TheCoder1998 on May 06, 2014, 08:20:58 am
hmm, the animations are slow, but they look good
Title: Re: Axe 2048 help?
Post by: JWinslow23 on May 06, 2014, 11:53:04 am
I'll make them twice as fast. :P

Also, I have a new screenie:
(http://img.ourl.ca/2048Tiles.gif)
Title: Re: Axe 2048 help?
Post by: Sorunome on May 06, 2014, 12:01:02 pm
To be honest, I would still speed it up some :P
Title: Re: Axe 2048 help?
Post by: JWinslow23 on May 06, 2014, 12:01:27 pm
To be honest, I would still speed it up some :P
So, get rid of animations? :P
Title: Re: Axe 2048 help?
Post by: Sorunome on May 06, 2014, 12:02:05 pm
To be honest, I would still speed it up some :P
So, get rid of animations? :P
No, just speeding up animatins, so that it takes like 1/4th of a second or something :P
Title: Re: Axe 2048 help?
Post by: JWinslow23 on May 06, 2014, 12:03:52 pm
To be honest, I would still speed it up some :P
So, get rid of animations? :P
No, just speeding up animatins, so that it takes like 1/4th of a second or something :P
When I try, it looks too choppy to be considered "animations". But that's just me; I can show you the code, and you can change it to make it as fast and smooth as you want. :P
Title: Re: Axe 2048 help?
Post by: Hayleia on May 06, 2014, 02:23:18 pm
When I try, it looks too choppy to be considered "animations". But that's just me; I can show you the code, and you can change it to make it as fast and smooth as you want. :P
Or just make it an option. Let the user choose in the "option" menu a value that would make animations more or less fast ;)

Also, you'll say "they are not grid lines" but I still think those are grid lines :P
Where's what I designed ? :P

Here, two moickups in attachement. Which one looks better in your opinion (asking that to everyone, not just JWinslow).
Title: Re: Axe 2048 help?
Post by: JWinslow23 on May 06, 2014, 06:04:04 pm
When I try, it looks too choppy to be considered "animations". But that's just me; I can show you the code, and you can change it to make it as fast and smooth as you want. :P
Or just make it an option. Let the user choose in the "option" menu a value that would make animations more or less fast ;)

Also, you'll say "they are not grid lines" but I still think those are grid lines :P
Where's what I designed ? :P

Here, two moickups in attachement. Which one looks better in your opinion (asking that to everyone, not just JWinslow).

The first one, duh. :P Just tell me how animations won't look awkward. :P
Also, menus will be added after I release and bug-fix.
Title: Re: Axe 2048 help?
Post by: Hayleia on May 06, 2014, 06:45:32 pm
The first one, duh. :P Just tell me how animations won't look awkward. :P
True story bro. Well as long as those are not real grid lines... :P

Also, if you are interested, here's a code to generate the background in 213 bytes when standalone (so less when incorporated in our program).
Code: [Select]
ClrDraw(L3)
L3-2→r1
For(4)
 65535-256→{r1+2->r1}^^r
End
L3+12-2→r1
For(4)
 128+512→{r1+2->r1}^^r
End
Copy(L3+12,L3+24,13*12)
Copy(L3,14*12+L3,12)
Copy(L3,16*12+L3,564)
Title: Re: Axe 2048 help?
Post by: DJ Omnimaga on May 06, 2014, 09:36:26 pm
I like the animations how they are now actually. On-calc it might be hard to see if it's too fast anyway.
Title: Re: Axe 2048 help?
Post by: bb010g on May 06, 2014, 10:34:15 pm
You'd still get a blur from the update speed, compensating for the lack of frames.