Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: Geekboy1011 on April 10, 2010, 01:23:19 am

Title: 15 number tile game thing c3 editition
Post by: Geekboy1011 on April 10, 2010, 01:23:19 am
ok well to learn matrices for crimson i took on a hopefully small side project which is a 15 number slider game
but alas im having a few issues most notably with shuffling the board
Code: [Select]
:Disp "SIZE?"
:Input X // Adds a "?" but its your choice
:1→C
:DelVar ADelVar B{X,X→dim([J]
:For(A,1,X
:For(B,1,X
:C→[J](A,B
:C+1→C
:End:End
:1→B
:X+X/10^(1+int(log(X→l   // Make sure 10^( is one token
:Pause L
:0→[J](X,X
:ClrHome
:For(θ,B,100
:Output(1,1,B
:Output(6,6,C
:Output(4,4,det(4,0
:C→n
:0→C
:Repeat C≠n
:randInt(1,4→C
:End
:If C=1 and .1≠fPart(L:Then  // Rearranged second term
:‾1→M:Goto UD:End
:If C=2 and X≠iPart(L:Then
:1→M:Goto LR:End
:If C=3 and (X/10)≠fPart(L:Then
:1→M:Goto UD:End
:If C=4 and 1≠iPart(L:Then
:‾1→M:Goto LR:End
:End
:Lbl UD
:[J](iPart(L),10fPart(L→A
:[J](iPart(L),10fPart(L+M→[J](iPart(L),10fPart(L
:A→[J](iPart(L),M+10fPart(L
:L+M/10→L
:B+1→B
:End
:End
:Lbl LR
:[J](iPart(L),10fPart(L→A
:[J](iPart(L)+M,10fPart(L→[J](iPart(L),10fPart(L
:A→[J](iPart(L)+M,10fPart(L
:L+M→L
:B+1→B
:End
:End
:Disp [J]
/me thanks sirCmpwn for optimizations

well my problem with the current code is my shufle routine is  to slow and inaccurate to say the least not always providing a good shuffle :/

so yeah my question is any one know a better shuffle routine ??

restrictions on the routine

1 cant just be randomly placed as it will be a 50 50 chance of a unsolvable puzzle


i need some help please and thank you
Title: Re: 15 number tile game thing c3 editition
Post by: cooliojazz on April 10, 2010, 02:39:50 am
Well, I'm not sure how the heck yours works, and i got lots of syntax errors and stuffs, but after "fixing" it i think this runs faster:
Code: [Select]
:Input "?x? ",θ
:{θ,θ→dim([A]
:0→C
:For(A,1,θ
:For(B,1,θ
:C→[A](A,B
:C+1→C
:End
:End
:Disp [A]
:1→X:1→Y
:For(A,1,θ2
:randInt(1,4→B
:X→W:Y→Z
:Repeat X≠W or Y≠Z
:randInt(1,4→B
:X+(B=3)-(B=1→X
:Y+(B=4)-(B=2→Y
:X+(X=0)-(X=θ+1→X
:Y+(Y=0)-(Y=θ+1→Y
:End
:[A](Z,W→C
:[A](Y,X→[A](Z,W
:C→[A](Y,X
:End
:Disp [A]
thats what you want right?  It just shuffles it?  This does it only as many times as there are peices, cause past that it's a bit pointless... and i changed the first tile to "0" to represent the blank tile...
Title: Re: 15 number tile game thing c3 editition
Post by: SirCmpwn on April 10, 2010, 10:37:22 am
Here is an example of how to suffle L1 using the Fisher-Yates algorithm:
Code: (TI Basic) [Select]
dim(L1→N
For(I,1,N
randInt(I,N→A
L1(A→B
L1(I→L(A
B→L1(I
End

A faster method would be to do this (stolen from Weregoose):
Code: (TI Basic) [Select]
rand(dim(L1→L2
SortA(L2,L1
Title: Re: 15 number tile game thing c3 editition
Post by: DJ Omnimaga on April 10, 2010, 01:19:14 pm
Interesting it would remind me of the mini game in Final Fantasy 1.

I wonder if in future versions it could have support for bigger shuffle boards like 5x5 and 6x6?
Title: Re: 15 number tile game thing c3 editition
Post by: Builderboy on April 10, 2010, 01:56:20 pm
Here is an example of how to suffle L1 using the Fisher-Yates algorithm:
Code: (TI Basic) [Select]
dim(L1→N
For(I,1,N
randInt(I,N→A
L1(A→B
L1(I→L(A
B→L1(I
End

A faster method would be to do this (stolen from Weregoose):
Code: (TI Basic) [Select]
rand(dim(L1→L2
SortA(L2,L1

Remember to Sir, you cant just randomize the tiles around because exactly half of all combinations cannot be solved.
Title: Re: 15 number tile game thing c3 editition
Post by: SirCmpwn on April 10, 2010, 01:57:51 pm
Here, take a look at this thread:
http://www.unitedti.org/forum/index.php?showtopic=4685&st=0&p=134765&hl=shuffle&fromsearch=1&#entry134765 (http://www.unitedti.org/forum/index.php?showtopic=4685&st=0&p=134765&hl=shuffle&fromsearch=1&#entry134765)

They talk about how to shuffle only solvable shuffles.
Title: Re: 15 number tile game thing c3 editition
Post by: Geekboy1011 on April 10, 2010, 04:56:22 pm
hmm  ty all so much i havent tried coolio's methosd yet stil going to try

@sir im shuffling a matrix not a list X.x so im not sure how those routines would work X.x
Title: Re: 15 number tile game thing c3 editition
Post by: DJ Omnimaga on April 10, 2010, 11:42:33 pm
Mhmm, what would be the equivalent for matrices? I never actually messed around with shuffling. Else another method would be to switch to lists, but that means some more calculations in the code since a list is in one row
Title: Re: 15 number tile game thing c3 editition
Post by: Geekboy1011 on April 10, 2010, 11:44:45 pm
im thinking of fliiping over to a list actually found a nice and by the looks of it fast shuffle routine XD

http://omnimaga.pastebin.com/BzxgrEMr

although there has to be some kinnd of algoritm to it or if im real lazy just shuffle the list and then make it a matrix XD
Title: Re: 15 number tile game thing c3 editition
Post by: meishe91 on April 11, 2010, 12:02:24 am
Well if you need I could make you a list to matrix program.
Title: Re: 15 number tile game thing c3 editition
Post by: Geekboy1011 on April 11, 2010, 12:20:09 am
ty but no thanks a simpleish for loop will suffice ^_^

still need to test that on calc though for speed so yeah XD
Title: Re: 15 number tile game thing c3 editition
Post by: meishe91 on April 11, 2010, 12:48:49 am
Well ya I know :P I just meant I could write code to do it because it'd be similar to my list to string routine.
Title: Re: 15 number tile game thing c3 editition
Post by: willrandship on April 12, 2010, 11:36:53 pm
I think solvable algorithms would be a good idea. Otherwise, people would complain.

Eventually, made you could add picture support! If you used XLib or Celtic III I imagine a sprite could fit into each tile quite easily.
Title: Re: 15 number tile game thing c3 editition
Post by: Geekboy1011 on April 12, 2010, 11:39:00 pm
i am planning to add picture support ^_^

by algorithems i meant a way to check to see if the generated grid is valid at the start than using a shuffle