15 puzzle game: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|UNIX Shell}}: clean up final output) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 27:
{{trans|Python: Original, with output}}
<
position = 0
[Int = String] items
Line 140:
I g.game_over()
print(‘You WON’)
L.break</
{{out}}
Line 149:
This is an entire Sega Genesis game, tested in the Fusion emulator. Thanks to Keith S. of Chibiakumas for the cartridge header, font routines, and printing logic. I programmed the actual game logic. This code can be copied and pasted into a text file and assembled as-is using vasmm68k_mot_win32.exe, no includes or incbins necessary (even the bitmap font is here too.)
<
;Ram Variables
Cursor_X equ $00FF0000 ;Ram for Cursor Xpos
Line 805:
DC.B $80 ;23 DMA source address high (C=CMD) CCHHHHHH
VDPSettingsEnd:
even</
{{out}}[https://ibb.co/4MZpL4W Screenshot of emulator]
Line 811:
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program puzzle15_64.s */
Line 1,432:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
=={{header|Action!}}==
<
DEFINE X0="13"
DEFINE Y0="6"
Line 1,648:
FI
OD
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/15_puzzle_game.png Screenshot from Atari 8-bit computer]
Line 1,656:
We fist define a generic package Generic_Puzzle. Upon instantiation, it can take any number of rows, any number of columns for a rows*columns-1 game. Instead of plain numbers, the tiles on the board can have arbitrary names (but they should all be of the same length). The package user can request the name for the tile at a certain (row,column)-point, and the set of possible moves. The user can move the empty space up, down, left and right (if possible). If the user makes the attempt to perform an impossible move, a Constraint_Error is raised.
<
Rows, Cols: Positive;
with function Name(N: Natural) return String; -- with Pre => (N < Rows*Cols);
Line 1,671:
procedure Move(The_Move: Moves);
end Generic_Puzzle;</
The package implementation is as follows.
<
Field: array(Row_Type, Col_Type) of Natural;
Line 1,731:
end loop;
end;
end Generic_Puzzle;</
The main program reads the level from the command line. A larger level implies a more difficult instance. The default level is 10, which is fairly simple. After randomizing the board, the user can move the tiles.
<
Ada.Numerics.Discrete_Random, Ada.Command_Line;
Line 1,806:
end;
end loop;
end Puzzle_15;</
{{out}}
Line 1,848:
4 moves!</pre>
For other puzzles, one must just the single line with the package instantiation. E.g., for an 8-puzzle, we would write the following. <
=={{header|APL}}==
{{works with|Dyalog APL|16.0}}
<
⍺←4 4
(s∨.<0)∨2≠⍴s←⍺:'invalid shape:'s
Line 1,876:
(1↓⍺)∇ n
}z
}</
{{out}}
<pre> fpg 10
Line 1,925:
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<
/* ARM assembly Raspberry PI */
Line 2,563:
bx lr @return
</syntaxhighlight>
=={{header|Astro}}==
<
fun mainframe(puz):
Line 2,680:
print 'You WON'
break
</syntaxhighlight>
=={{header|AutoHotkey}}==
<
Grid := [], Deltas := ["-1,0","1,0","0,-1","0,1"], Width := Size * 2.5
Gui, font, S%Size%
Line 2,759:
if (Trim(gridCont, ",") = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16")
MsgBox, 262208, 15 Puzzle, You solved 15 Puzzle
}</
=={{header|BASIC}}==
==={{header|Commodore BASIC}}===
<
20 REM COMMODORE BASIC 2.0
30 REM ********************************
Line 2,878:
1130 FOR T=0 TO 400
1140 NEXT
1150 RETURN</
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}{{works with|ARM BBC BASIC}}{{works with|Brandy BASIC|Matrix Brandy}}
<
SIZE=4 : DIFFICULTY=3
Line 2,926:
COLOUR 0 : COLOUR 143
PRINT
ENDPROC</
=={{header|BQN}}==
{{trans|APL}}
<
FPG←{
𝕊𝕩: 4‿4𝕊𝕩;
Line 2,971:
} _while_ ⊢ 1
@
}</
<
FPG 10
┌─
Line 3,002:
↓
Out of bounds: ↓
...</
=={{header|C}}==
===C89, 22 lines version===
The task, as you can see, can be resolved in 22 lines of no more than 80 characters. Of course, the source code in C is not very readable. The second example works exactly the same way, but it was written in much more human readable way. The program also works correctly for non-standard number of rows and/or columns.
<
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
Line 3,028:
RIGHT;}}}void pause(void){getchar();}int main(void){srand((unsigned)time(NULL));
do setup();while(isEnd());show();while(!isEnd()){update(get());show();}disp(
"You win"); pause();return 0;}</
===C89, short version, TTY mode===
<
* RosettaCode: Fifteen puzle game, C89, plain vanillia TTY, MVC
*/
Line 3,154:
}
</syntaxhighlight>
{{Out}}
<pre>
Line 3,186:
===C89, long version, TTY/Winapi/ncurses modes===
<
* RosettaCode: Fifteen puzle game, C89, MS Windows Console API, MVC
*
Line 3,496:
return EXIT_SUCCESS;
}
</syntaxhighlight>
=={{header|C sharp|C#}}==
Line 3,502:
{{libheader|System.Drawing}}
{{works with|C sharp|6}}
<
using System.Drawing;
using System.Linq;
Line 3,661:
grid[positionOf[b]] = b;
}
}</
=={{header|C++}}==
<
#include <time.h>
#include <stdlib.h>
Line 3,759:
p15 p; p.play(); return 0;
}
</syntaxhighlight>
<pre>
+----+----+----+----+
Line 3,777:
Tested with GnuCOBOL
<
*> This code is dedicated to the public domain
*> This is GNUCOBOL 2.0
Line 3,927:
end-evaluate
.
end program fifteen.</
{{out}}
Line 3,946:
Credit to this post for help with the inversions-counting function: [http://www.lispforum.com/viewtopic.php?f=2&t=3422]
Run it (after loading the file) with <syntaxhighlight lang
<
(:use :common-lisp))
(in-package :15)
Line 4,046:
(rotatef (aref *board* (first pos) (second pos))
(aref *board* (first zpos) (second zpos))))))
(format t "You win!~%"))</
=={{header|EasyLang}}==
Line 4,133:
.
.
call init</
=={{header|F_Sharp|F#}}==
<
// 15 Puzzle Game. Nigel Galloway: August 9th., 2020
let Nr,Nc,RA,rnd=[|3;0;0;0;0;1;1;1;1;2;2;2;2;3;3;3|],[|3;0;1;2;3;0;1;2;3;0;1;2;3;0;1;2|],[|for n in [1..16]->n%16|],System.Random()
Line 4,152:
[<EntryPoint>]
let main n = fL(match n with [|n|]->let g=[|let g=uint64 n in for n in 60..-4..0->int((g>>>n)&&&15UL)|] in (Array.findIndex((=)0)g,g) |_->fE()) 0
</syntaxhighlight>
3 uses:
15 game with no parameters will generate a random game which may be solved.
Line 4,186:
</pre>
=={{header|Factor}}==
<
combinators.short-circuit grouping io kernel literals math
math.matrices math.order math.parser math.vectors prettyprint qw
Line 4,262:
drop ;
MAIN: main</
{{out}}
<pre>
Line 4,297:
See [[15_puzzle_solver#Forth]] for a solver based on the same code.
<
cell 8 <> [if] s" 64-bit system required" exception throw [then]
Line 4,366:
solution 1000 shuffle play
</syntaxhighlight>
=={{header|Fortran}}==
Line 4,379:
The game plan is to start with an ordered array so that each cell definitely has a unique code, then jumble them via "random" swaps. Possible arrangements turn out to have either odd or even parity based on the number of out-of-sequence squares, and as the allowed transformations do not change the parity and the solution state has even parity, odd parity starting states should not be presented except by those following Franz Kafka. The calculation is simplified by always having the blank square in the last position, thus in the last row. Once an even-parity starting state is floundered upon, the blank square is re-positioned using allowable moves so that the parity is not altered thereby. Then the game begins: single-square moves only are considered, though in practice groups of squares could be moved horizontally or vertically rather than one-step-at-a-time - a possible extension.
The source style uses F90 for its array arithmetic abilities, especially the functions ALL, ANY and COUNT. A statement <
INTEGER I,J,T !So, we're stuck with supplying the obvious.
T = I !And, only for one type at a go.
Line 4,495:
IF (ANY(BORED(1:N - 2) + 1 .NE. BORED(2:N - 1))) GO TO 20 !Are we there yet?
WRITE (MSG,*) TRY,"Steps to success!" !Yes!
END !That was fun.</
Output: Not so good. As ever, the character cell sizes are not square so a square game board comes out as a rectangle. Similarly, underlining is unavailable (no overprints!) so the layout is not pleasing. There are special "box-drawing" glyphs available, but they are not standardised and there is still no overprinting so that a flabby waste of space results. Further, there is no ability to re-write the display, even though one could easily regard the output to the screen as a random-access file: <code>WRITE (MSG,REC = 6) STUFF</code> would rewrite the sixth line of the display. Instead, output relentlessly rolls forwards, starting as follows:
Line 4,529:
=={{header|FreeBASIC}}==
<
dim as string outstr = ""
for i as ubyte = 0 to 15
Line 4,602:
print "Congratulations! You win!"
print
drawboard B()</
=={{header|Gambas}}==
<
'Inspiration came from: -
''http://rosettacode.org/wiki/15_Puzzle_Game
Line 4,903:
End
</syntaxhighlight>
[http://www.cogier.com/gambas/Copuzzle.png Click here for image of game in play]
=={{header|Go}}==
<
import (
Line 5,061:
return
}
}</
=={{header|Harbour}}==
<
#include "inkey.ch"
Line 5,249:
SetColor(" W/N, BG+/B")
RETURN fim
</syntaxhighlight>
=={{header|Haskell}}==
<
import System.Random
Line 5,324:
randomIndex <- randomRIO (0, length moves - 1)
let move = moves !! randomIndex
shufflePuzzle (numOfShuffels - 1) (applyMove move puzzle)</
Output:
<pre>Please enter the difficulty level: 0, 1 or 2
Line 5,354:
Implementation:
<
genboard=:3 :0
Line 5,418:
showboard board
echo 'You win.'
)</
Most of this is user interface code. We initially shuffle the numbers randomly, then check their parity and swap the first and last squares if needed. Then, for each move, we allow the user to pick one of the taxicab neighbors of the empty square.
Line 5,424:
A full game would be too big to be worth showing here, so for the purpose of giving a glimpse of what this looks like in action we replace the random number generator with a constant:
<
15 puzzle
h for help, q to quit
Line 5,461:
│13│14│15│ │
└──┴──┴──┴──┘
You win.</
=={{header|Java}}==
{{works with|Java|8}}
<
import java.awt.*;
Line 5,678:
});
}
}</
=={{header|Javascript}}==
Play it [http://paulo-jorente.de/webgames/15p/ here]
<
var board, zx, zy, clicks, possibles, clickCounter, oldzx = -1, oldzy = -1;
function getPossibles() {
Line 5,801:
restart();
}
</syntaxhighlight>
Html to test
<pre>
Line 5,820:
=={{header|Julia}}==
<
using Random
Line 5,928:
puzzle15play()
</
This puzzle is solvable.
+----+----+----+----+
Line 5,948:
=={{header|Kotlin}}==
{{trans|Java}}
<
import java.awt.BorderLayout
Line 6,096:
}
}
}</
=={{header|Liberty BASIC}}==
{{trans|Commodore BASIC}}
{{works with|Just BASIC}}
<syntaxhighlight lang=lb>
' 15-PUZZLE GAME
' ********************************
Line 6,235:
isPuzzleComplete = pc
end function
</syntaxhighlight>
=={{header|LiveCode}}==
<
#Please note that all this code can be performed in livecode with just few mouse clicks
#This is just a pure script exampe
Line 6,300:
end if
end checkDistance
</syntaxhighlight>
Screenshot:
[https://s24.postimg.org/uc6fx7kph/Livecode15_Puzzle_Game.png]
=={{header|Lua}}==
<
math.randomseed( os.time() )
local puz = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0 }
Line 6,402:
-- [ entry point ] --
beginGame()
</syntaxhighlight>
{{out}}
<pre>
Line 6,434:
Also the code is not the best, because we can move from 4 position to 5 (we can't do that with real puzzle)
<
Module Puzzle15 {
Line 6,547:
}
Puzzle15
</syntaxhighlight>
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
Move[x_] := (empty = Select[grid, #[[1]]==16 &][[1,2]];
Line 6,562:
CButton[{x_,loc_}] := If[x==16, Null, Button[x,Move @ loc]]
Dynamic @ Grid @ Partition[CButton /@ grid,4]</
=={{header|Mercury}}==
Line 6,568:
The ideal in Mercury is to have a declarative module that encodes the game logic, and then separate modules to implement a human player with text commands (here), or keyed commands, or some kind of AI player, and so on. fifteen.print/3 is a arguably a smudge on fifteen's interface:
<
:- interface.
:- use_module random, io.
Line 6,669:
move(I, right, !B) :-
not (I = 3 ; I = 7 ; I = 11 ; I = 15),
swap(I, I + 1, !B).</
As used:
<
:- interface.
:- import_module io.
Line 6,753:
"
Seed = time(NULL);
").</
=={{header|MUMPS}}==
Line 6,802:
=={{header|Nim}}==
<
type
Line 6,944:
draw board
echo "You win!"</
{{out}}
<pre>┌──┬──┬──┬──┐
Line 6,958:
=={{header|OCaml}}==
<
struct
type t = int array
Line 6,996:
print_string " > ";
Puzzle.move p (read_line () |> int_of_string)
done</
To move, input the number to slide into the blank. If you accidentally make an impossible move you can undo it by repeating the last input. A nice self-checked puzzle, the same as if you were physically moving the pieces around.
Line 7,046:
=={{header|Pascal}}==
This is Free Pascal(version >= 3.0.4) text mode implementation. To make a move, the user needs to enter the number of the selected tile.
<
program fifteen;
{$mode objfpc}
Line 7,336:
Run;
end.
</syntaxhighlight>
=={{header|Perl}}==
Line 7,345:
On verbosity shows how the solvability is calculated. The program has some extra feature like font size and color scheme but also the possibility to set the intial board disposition.
This program was originally posted by me at [http://www.perlmonks.org/?node_id=1192660 perlmonks]
<
use strict;
Line 7,596:
</syntaxhighlight>
===console version===
This short console program just poses solvable puzzles: it achieves this shuffling a solved board n times, where n defaults to 1000 but can be passed as first argument of the program in the command line. It was originally posted by me at [http://www.perlmonks.org/?node_id=1192865 perlmonks] but here a little modification was inserted to prevent wrong numbers to make the board messy.
<
use strict;
use warnings;
Line 7,632:
[$$e[0]-1,$$e[1]],[$$e[0]+1,$$e[1]],[$$e[0],$$e[1]-1],[$$e[0],$$e[1]+1]
}
</syntaxhighlight>
=={{header|Phix}}==
=== console only ===
Kept simple. Obviously, increase the 5 random moves for more of a challenge.
<!--<
<span style="color: #008080;">constant</span> <span style="color: #000000;">ESC<span style="color: #0000FF;">=<span style="color: #000000;">27<span style="color: #0000FF;">,</span> <span style="color: #000000;">UP<span style="color: #0000FF;">=<span style="color: #000000;">328<span style="color: #0000FF;">,</span> <span style="color: #000000;">LEFT<span style="color: #0000FF;">=<span style="color: #000000;">331<span style="color: #0000FF;">,</span> <span style="color: #000000;">RIGHT<span style="color: #0000FF;">=<span style="color: #000000;">333<span style="color: #0000FF;">,</span> <span style="color: #000000;">DOWN<span style="color: #0000FF;">=<span style="color: #000000;">336</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">board</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">tagset<span style="color: #0000FF;">(<span style="color: #000000;">15<span style="color: #0000FF;">)<span style="color: #0000FF;">&<span style="color: #000000;">0<span style="color: #0000FF;">,</span> <span style="color: #000000;">solve</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">board</span>
Line 7,669:
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #7060A8;">puts<span style="color: #0000FF;">(<span style="color: #000000;">1<span style="color: #0000FF;">,<span style="color: #008000;">"solved!\n"<span style="color: #0000FF;">)
<!--</
{{out}}
<pre>
Line 7,703:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/15game.htm here].
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\15_puzzle_game.exw
Line 7,828:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</
=={{header|PHP}}==
OOP and MVC design pattern has been used to facilitate any improvements, e.g. tiles with graphics instead of just numbers.
<
// Puzzle 15 Game - Rosseta Code - PHP 7 as the server-side script language.
Line 8,057:
?></p>
</body>
</html></
=={{header|Picat}}==
<
import util.
Line 8,125:
Board[R0,C0] := S,
Board[R,C] := 0.
</syntaxhighlight>
=={{header|Powershell}}==
Line 8,132:
Board is always scrambled from a solved board so it's always solvable.
Written in ISE with ISESteroids. I'm sure the code could be improved on.
<
#15 Puzzle Game
$Script:Neighbours = @{
Line 8,392:
# Show Window
$result = Show-WPFWindow -Window $window
</syntaxhighlight>
=={{header|Processing}}==
<
int number_of_grid_cells = 16; // Set the number of cells of the board here 9, 16, 25 etc
color piece_color = color(255, 175, 0);
Line 8,509:
}
}
}</
'''It can be played on line''' :<BR> [https://www.openprocessing.org/sketch/863055/ here.]
Line 8,515:
==={{header|Processing Python mode}}===
{{trans|Processing}}
<
num_grid_cells = 16
piece_color = color(255, 175, 0)
Line 8,625:
# Upper bright
line(self.x + 2, self.y + 1, self.x +
piece_side_length - 1, self.y + 1)</
=={{header|PureBasic}}==
Line 8,631:
Numbers are displayed in Hexadecimal (ie 1 to F)
Default controls are u,d,l,r
<
#difficulty=10 ;higher is harder
#up="u"
Line 8,701:
Print("Won !")
CloseConsole()
</syntaxhighlight>
<pre>
1234
Line 8,715:
{{works with|Python|3.X}}
'''unoptimized'''
<
''' Structural Game for 15 - Puzzle with different difficulty levels'''
from random import randint
Line 8,840:
print('You WON')
break
</syntaxhighlight>
<pre>
Enter the difficulty : 0 1 2
Line 8,874:
===Python: using tkinter===
<
''' Python 3.6.5 code using Tkinter graphical user interface.'''
Line 9,124:
g = Game(root)
root.mainloop()
</syntaxhighlight>
=={{header|QB64}}==
<
_TITLE "GUI Sliding Blocks Game "
RANDOMIZE TIMER
Line 9,211:
END IF
LOOP
</syntaxhighlight>
=={{header|Quackery}}==
The inputs are w,s,a,d and they refer to the direction in which the empty place "moves". After every prompt you can input a string of characters and submit them by pressing enter. Any characters other than w,s,a,d will be ignored, and moves will be performed according to the correct commands. Commands that would "move" the empty space off the edge of the puzzle are also ignored. For example, on a solved puzzle "asgw" would move 15 to the right, ignore 's' and 'g' and move 11 down.
<
( moves: 0 - up, 1 - down, 2 - left, 3 - right )
Line 9,305:
15-puzzle
</syntaxhighlight>
=={{header|R}}==
The inputs are w,a,s,d and they refer to the direction in which the adjacent piece moves into the empty space. For example, on a solved puzzle, "d" would move the 15 to the right.
<syntaxhighlight lang=R>
puz15<-function(scramble.length=100){
m=matrix(c(1:15,0),byrow=T,ncol=4)
Line 9,398:
}
}
</syntaxhighlight>
Sample output:
Line 9,445:
It uses the <code>2htdp/universe</code> package.
<
(require 2htdp/universe 2htdp/image racket/list racket/match)
Line 9,493:
(to-draw (fifteen->pict))
(stop-when solved-world? (fifteen->pict #t))
(on-key key-move-space))</
=={{header|Raku}}==
Line 9,499:
{{works with|Rakudo|2018.06}}
Most of this is interface code. Reused substantial portions from the [[2048#Raku|2048]] task. Use the arrow keys to slide tiles, press 'q' to quit or 'n' for a new puzzle. Requires a POSIX termios aware terminal. Ensures that the puzzle is solvable by shuffling the board with an even number of swaps, then checking for even taxicab parity for the empty space.
<
constant $saved = Term::termios.new(fd => 1).getattr;
Line 9,613:
last if $key eq 'q'; # (q)uit
new() if $key eq 'n';
}</
Sample screen shot:
<pre>
Line 9,632:
=={{header|Rebol}}==
<
if not find [0x108 108x0 0x-108 -108x0] face/offset - e/offset [exit]
x: face/offset face/offset: e/offset e/offset: x] across
] x: random repeat i 15 [append x:[] i] repeat i 15 [
repend g ['t mold x/:i random white] if find [4 8 12] i [append g 'return]
] append g [e: box] view layout g</
=={{header|Red}}==
<
Red [Needs: 'view]
system/view/screens/1/pane/-1/visible?: false ;; suppress console window
Line 9,706:
view lay
</syntaxhighlight>
=={{header|REXX}}==
Line 9,715:
Over half of the REXX program has to do with input validation and presentation of the puzzle (grid).
<
parse arg N seed . /*obtain optional arguments from the CL*/
if N=='' | N=="," then N=4 /*Not specified? Then use the default.*/
Line 9,778:
rm=holeRow-1; rp=holeRow+1; cm=holeCol-1; cp=holeCol+1 /*possible moves.*/
!=!.rm.holeCol !.rp.holeCol !.holeRow.cm !.holeRow.cp /* legal moves.*/
if show then say pad bot; return</
{{out|output|text= when using the default input:}}
<pre>
Line 9,824:
=={{header|Ring}}==
<
# Project : CalmoSoft Fifteen Puzzle Game
# Date : 2018/12/01
Line 10,591:
return
</syntaxhighlight>
'''Output:'''
Line 10,598:
=={{header|Ruby}}==
<
class Board
Line 10,687:
end
Board.new</
{{out}}
Line 10,707:
{{libheader|JRubyArt}}
Gui Version:-
<
SOLUTION = %w[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0].freeze
Line 10,810:
end
</syntaxhighlight>
=={{header|Run BASIC}}==
<
' ---- fill 15 squares with 1 to 15
dim sq(16)
Line 10,881:
Text-Align:Center;Font-Size:24pt;Font-Weight:Bold;Font-Family:Arial;
}"
END SUB</
Output:
[[File:KokengeGame15.jpg]]
Line 10,887:
=={{header|Rust}}==
{{libheader|rand}}
<
use std::collections::HashMap;
Line 11,091:
}
}
}</
=={{header|Scala}}==
<
import jline.console._
Line 11,170:
.foldLeft(Board.solveState) { case (state, mv) => state.move(mv) }
}
}</
=={{header|Scheme}}==
<
(import (scheme base)
(scheme read)
Line 11,260:
(play-game)
</syntaxhighlight>
{{out}}
Line 11,377:
end
disp("Solved in "+string(n_moves)+" moves.");</
{{out}}
Line 11,448:
=={{header|Simula}}==
<
BEGIN
CLASS FIFTEENPUZZLE(NUMTILES, SIDE, WIDTH, SEED);
Line 11,661:
P.REQUEST;
P.PRINTBOARD;
END.</
{{out}}
<pre>INPUT RANDOM SEED:
Line 11,703:
{{works with|SML/NJ}}
{{works with|Moscow ML}}
<
(* Load required Modules for Moscow ML *)
load "Int";
Line 11,954:
val () = Console.start()
</syntaxhighlight>
<b>Note:</b>
Line 11,971:
The window-title is used to show messages.
<
# http://wiki.tcl.tk/14403
Line 12,108:
# For some more versions, see: http://wiki.tcl.tk/15067 : Classic 15 Puzzle and http://wiki.tcl.tk/15085 : N-Puzzle
</syntaxhighlight>
=={{header|UNIX Shell}}==
Line 12,114:
This plays the game in an ANSI-compliant terminal using vi/nethack movement keys to slide the tiles.
<
main() {
local puzzle=({1..15} " ") blank moves_kv i key count total last
Line 12,210:
}
main "$@"</
{{Out}}
Line 12,228:
The last move is displayed on the input box, or an error message if an invalid move is attempted. When the puzzle is solved, the move count is displayed.
<syntaxhighlight lang=vb>
Public iSide As Integer
Public iSize As Integer
Line 12,409:
ShowGrid = s
End Function
</syntaxhighlight>
Sample output:
Line 12,424:
=={{header|Visual Basic .NET}}==
<
Inherits System.Windows.Forms.Form
Line 12,519:
End Function
End Class</
=={{header|Visual Prolog}}==
Line 12,526:
[https://youtu.be/rWy3AX5HjXM 15 Puzzle in Visual Prolog - video]
<
/* ------------------------------------------------------------------------------------------------------
Line 13,461:
% end of automatic code
end implement playDialog
</syntaxhighlight>
=={{header|VBScript}}==
<syntaxhighlight lang=VB>
'----------------15 game-------------------------------------
'WARNING: this script uses ANSI escape codes to position items on console so
Line 13,573:
usr= move(d)
end function
</syntaxhighlight>
=={{header|Wren}}==
{{trans|Go}}
Line 13,579:
{{libheader|Wren-ioutil}}
{{libheader|Wren-fmt}}
<
import "/dynamic" for Enum
import "/ioutil" for Input
Line 13,699:
var p = Puzzle.new()
p.play()</
{{out}}
Line 13,761:
=={{header|x86-64 Assembly}}==
<
; How to play ?.. Just press one of the arrow keys then [enter] to valid
; ( press [Ctrl+C] to escape )
Line 13,842:
xchg ax,word[puzzle+4+rbx*4]
mov word[puzzle+4+rdx*4],ax
ret</
=={{header|XBasic}}==
{{trans|Liberty BASIC}}
{{works with|Windows XBasic}}
<
PROGRAM "fifteenpuzzlegame"
VERSION "0.0001"
Line 14,003:
END PROGRAM
</syntaxhighlight>
=={{header|XPL0}}==
<
[Box:= [^ ,^F,^E,^D, \starting configuration
^C,^B,^A,^9, \slide digits into ascending order
Line 14,036:
other []; \ignore 0 scan code prefix etc.
];
]</
{{out}}
Line 14,047:
=={{header|Yabasic}}==
<
dim grid(dx, dy)
Line 14,124:
next y
next x
end sub</
Adaptation from Phix solution
<
solve$ = board$
pos = 16
Line 14,169:
loop
print "solved!\n"
</syntaxhighlight>
|