Author Topic: 15 number tile game thing c3 editition  (Read 6282 times)

0 Members and 1 Guest are viewing this topic.

Offline Geekboy1011

  • The Oneironaut
  • Donator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2031
  • Rating: +119/-2
  • Dream that Awakening dream
    • View Profile
15 number tile game thing c3 editition
« 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]
* Geekboy1011 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
« Last Edit: April 10, 2010, 01:26:16 am by Geekboy1011 »

Offline cooliojazz

  • Support Staff
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 619
  • Rating: +66/-9
  • I omnoms on your soul
    • View Profile
    • Unreal Phantasies
Re: 15 number tile game thing c3 editition
« Reply #1 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...
Spoiler For Random signess:
You can not beat my skills.
Trust me.
So don't even try.
And remember never to trust someone who says, "Trust me."

TI File Editor Progress: Remade in java like a boss. 50% we'll call it? IDK =P
Java Libraries: JIRC - 90% JTIF - 5%
TI Projects: Unreal Notator - -5000%
Nomcraft, a Bukkit mod
Some of the music I write can be found here | The Rest Should Be Here (Bandcamp)

SirCmpwn

  • Guest
Re: 15 number tile game thing c3 editition
« Reply #2 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
« Last Edit: April 10, 2010, 10:42:15 am by SirCmpwn »

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: 15 number tile game thing c3 editition
« Reply #3 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?

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: 15 number tile game thing c3 editition
« Reply #4 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.

SirCmpwn

  • Guest
Re: 15 number tile game thing c3 editition
« Reply #5 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

They talk about how to shuffle only solvable shuffles.

Offline Geekboy1011

  • The Oneironaut
  • Donator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2031
  • Rating: +119/-2
  • Dream that Awakening dream
    • View Profile
Re: 15 number tile game thing c3 editition
« Reply #6 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
« Last Edit: April 10, 2010, 04:58:24 pm by Geekboy1011 »

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: 15 number tile game thing c3 editition
« Reply #7 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

Offline Geekboy1011

  • The Oneironaut
  • Donator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2031
  • Rating: +119/-2
  • Dream that Awakening dream
    • View Profile
Re: 15 number tile game thing c3 editition
« Reply #8 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

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: 15 number tile game thing c3 editition
« Reply #9 on: April 11, 2010, 12:02:24 am »
Well if you need I could make you a list to matrix program.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Geekboy1011

  • The Oneironaut
  • Donator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2031
  • Rating: +119/-2
  • Dream that Awakening dream
    • View Profile
Re: 15 number tile game thing c3 editition
« Reply #10 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

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: 15 number tile game thing c3 editition
« Reply #11 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.
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: 15 number tile game thing c3 editition
« Reply #12 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.

Offline Geekboy1011

  • The Oneironaut
  • Donator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2031
  • Rating: +119/-2
  • Dream that Awakening dream
    • View Profile
Re: 15 number tile game thing c3 editition
« Reply #13 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