15 puzzle game: Difference between revisions

(→‎{{header|Go}}: Made a minor bug fix)
Line 205:
 
For other puzzles, one must just the single line with the package instantiation. E.g., for an 8-puzzle, we would write the following. <lang Ada> package Puzzle is new Generic_Puzzle(Rows => 3, Cols => 3, Name => Image);</lang>
=={{header|APL}}==
{{works with|Dyalog APL|16.0}}
<lang APL>fpg←{⎕IO←0
⍺←4 4
(s∨.<0)∨2≠⍴s←⍺:'invalid shape:'s
0≠⍴⍴⍵:'invalid shuffle count:'⍵
d←d,-d←↓2 2⍴3↑1
e←¯1+⍴c←'↑↓←→○'
b←w←s⍴w←1⌽⍳×/s
z←⊃{
z p←⍵
n←(?⍴p)⊃p←(p≡¨(⊂s)|p)/p←(d~p)+⊂z
b[z n]←b[n z]
-⍨\n z
}⍣⍵⊢(s-1)0
⎕←b
⍬{
b≡w:'win'
0=⍴⍺:⍞∇ ⍵
e=i←c⍳m←⊃⍺:'quit'
i>e:⍞∇ ⍵⊣⎕←'invalid direction:'m
n≢s|n←⍵+i⊃d:⍞∇ ⍵⊣'out of bounds:'m
b[⍵ n]←b[n ⍵]
⎕←(s×0≠⍴⍺)⍴b
(1↓⍺)∇ n
}z
}</lang>
{{out}}
<pre> fpg 10
1 3 0 4
5 2 6 8
9 10 7 12
13 14 11 15
1 0 3 4
5 2 6 8
9 10 7 12
13 14 11 15
1 2 3 4
5 0 6 8
9 10 7 12
13 14 11 15
1 2 3 4
5 6 0 8
9 10 7 12
13 14 11 15
↓↓
1 2 3 4
5 6 7 8
9 10 11 12
13 14 0 15
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 0
win
 
 
2 5 fpg 2
1 2 3 0 4
6 7 8 9 5
1 2 3 4 0
6 7 8 9 5
1 2 3 4 5
6 7 8 9 0
win
</pre>
 
=={{header|Astro}}==
Anonymous user