16 puzzle game: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
Thundergnat (talk | contribs) m (Automated syntax highlighting fixup (second round - minor fixes)) |
||
Line 43: | Line 43: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
<syntaxhighlight lang=go>package main |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 293: | Line 293: | ||
=={{header|J}}== |
=={{header|J}}== |
||
Assumes a recent release of jqt:<syntaxhighlight lang= |
Assumes a recent release of jqt:<syntaxhighlight lang="j">require'ide/qt/gl2' |
||
coinsert'jgl2' |
coinsert'jgl2' |
||
Line 460: | Line 460: | ||
} |
} |
||
</pre> |
</pre> |
||
<syntaxhighlight lang=javascript> |
<syntaxhighlight lang="javascript"> |
||
class Puzzle { |
class Puzzle { |
||
constructor() { |
constructor() { |
||
Line 617: | Line 617: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
<syntaxhighlight lang=julia>using Gtk, Random |
<syntaxhighlight lang="julia">using Gtk, Random |
||
function puzzle16app(bsize) |
function puzzle16app(bsize) |
||
Line 733: | Line 733: | ||
{{libheader|gintro}} |
{{libheader|gintro}} |
||
Not a direct translation as there are a lot of differences, but, at least, the graphical interface is similar and the logic is the same. |
Not a direct translation as there are a lot of differences, but, at least, the graphical interface is similar and the logic is the same. |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="nim">import random, sequtils, strutils |
||
import gintro/[glib, gobject, gtk, gio] |
import gintro/[glib, gobject, gtk, gio] |
||
Line 929: | Line 929: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
<syntaxhighlight lang=perl>#!/usr/bin/perl |
<syntaxhighlight lang="perl">#!/usr/bin/perl |
||
use strict; # http://www.rosettacode.org/wiki/16_Puzzle_Game |
use strict; # http://www.rosettacode.org/wiki/16_Puzzle_Game |
||
Line 1,021: | Line 1,021: | ||
NB arrow keys not tested on linux, but "UDLR" should work... |
NB arrow keys not tested on linux, but "UDLR" should work... |
||
<!--<syntaxhighlight lang= |
<!--<syntaxhighlight lang="phix">--> |
||
<span style="color: #008080;">constant</span> <span style="color: #000000;">level</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">5<span style="color: #0000FF;">,</span> |
<span style="color: #008080;">constant</span> <span style="color: #000000;">level</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">5<span style="color: #0000FF;">,</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;">DOWN<span style="color: #0000FF;">=<span style="color: #000000;">336<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> |
<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;">DOWN<span style="color: #0000FF;">=<span style="color: #000000;">336<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> |
||
Line 1,123: | Line 1,123: | ||
For brevity, changed to zero-based and skipped some error handling. |
For brevity, changed to zero-based and skipped some error handling. |
||
{{trans|Go}} |
{{trans|Go}} |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="raku" line># 20210914 Raku programming solution |
||
my (\easy,\hard) = 1,4 ; my @n = ^16; my \level = $ = easy ; my \moves = $ = 0; |
my (\easy,\hard) = 1,4 ; my @n = ^16; my \level = $ = easy ; my \moves = $ = 0; |
||
Line 1,192: | Line 1,192: | ||
and the answer can be in any case (lower or uppercase). |
and the answer can be in any case (lower or uppercase). |
||
<br>Not all errors are checked so as to keep the program simpler. |
<br>Not all errors are checked so as to keep the program simpler. |
||
<syntaxhighlight lang=rexx>/*REXX pgm implements the 16 game; displays game grid, prompts for a move, game won? */ |
<syntaxhighlight lang="rexx">/*REXX pgm implements the 16 game; displays game grid, prompts for a move, game won? */ |
||
sep= copies("─",8); pad=left('',1+length(sep) ) /*pad=9 blanks. SEP is used for msgs.*/ |
sep= copies("─",8); pad=left('',1+length(sep) ) /*pad=9 blanks. SEP is used for msgs.*/ |
||
parse arg N hard seed . /*obtain optional arguments from the CL*/ |
parse arg N hard seed . /*obtain optional arguments from the CL*/ |
||
Line 1,333: | Line 1,333: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
<syntaxhighlight lang=ring> |
<syntaxhighlight lang="ring"> |
||
# Project : Sixteen Puzzle Game |
# Project : Sixteen Puzzle Game |
||
Line 1,872: | Line 1,872: | ||
{{libheader|Wren-ioutil}} |
{{libheader|Wren-ioutil}} |
||
{{libheader|Wren-str}} |
{{libheader|Wren-str}} |
||
<syntaxhighlight lang=ecmascript>import "random" for Random |
<syntaxhighlight lang="ecmascript">import "random" for Random |
||
import "/trait" for Stepped |
import "/trait" for Stepped |
||
import "/fmt" for Fmt |
import "/fmt" for Fmt |