16 puzzle game: Difference between revisions
Content added Content deleted
m (added a related task.) |
m (→{{header|REXX}}: changed quote styles.) |
||
Line 25: | Line 25: | ||
<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. |
||
<lang rexx>/*REXX pgm implements the 16 game; displays game grid, prompts for a move, game won? */ |
<lang rexx>/*REXX pgm implements the 16 game; displays game grid, prompts for a move, game won? */ |
||
sep= copies( |
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*/ |
||
er= '***error***' /*literal used to indicate an error msg*/ |
er= '***error***' /*literal used to indicate an error msg*/ |
||
Line 42: | Line 42: | ||
do hard; row= random(1) /*scramble the grid HARD # of times.*/ |
do hard; row= random(1) /*scramble the grid HARD # of times.*/ |
||
if row then call move random(1,N)substr('LR', random(1, 2), 1) /* ◄── move row. */ |
if row then call move random(1,N)substr('LR', random(1, 2), 1) /* ◄── move row. */ |
||
else call move substr('abcdefghi',random(1,N), 1)substr( |
else call move substr('abcdefghi',random(1,N), 1)substr("+-",random(1,2),1) |
||
end /*hard*/ /* [↓] move col.*/ |
end /*hard*/ /* [↓] move col.*/ |
||
/*play 16─game until solved or quit.*/ |
/*play 16─game until solved or quit.*/ |
||
Line 97: | Line 97: | ||
bot= '╚'copies( copies("═", 2)'╩', N); bot= left( bot, length(bot) - 1)"╝" |
bot= '╚'copies( copies("═", 2)'╩', N); bot= left( bot, length(bot) - 1)"╝" |
||
ind= left('', 3 + length(N) ) /*compute indentation.*/ |
ind= left('', 3 + length(N) ) /*compute indentation.*/ |
||
col= ind ind ind' ' subword( |
col= ind ind ind' ' subword("a- b- c- d- e- f- g- h- i-", 1, n) |
||
HI= substr('abcdefghi', N, 1); upper HI |
HI= substr('abcdefghi', N, 1); upper HI |
||
say col ind ind ind '- means shift a column down'; say pad ind top |
say col ind ind ind '- means shift a column down'; say pad ind top |
||
Line 109: | Line 109: | ||
end /*r*/ |
end /*r*/ |
||
say pad ind bot; say; |
say pad ind bot; say; |
||
say translate(col, '+', "-") ind ind ind |
say translate(col, '+', "-") ind ind ind "+ means shift a column up"; say |
||
return</lang> |
return</lang> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |