Jump to content

16 puzzle game: Difference between revisions

m
→‎{{header|REXX}}: changed quote styles.
m (added a related task.)
m (→‎{{header|REXX}}: changed quote styles.)
Line 25:
<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? */
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*/
er= '***error***' /*literal used to indicate an error msg*/
Line 42:
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. */
else call move substr('abcdefghi',random(1,N), 1)substr('"+-'",random(1,2),1)
end /*hard*/ /* [↓] move col.*/
/*play 16─game until solved or quit.*/
Line 97:
bot= '╚'copies( copies("═", 2)'╩', N); bot= left( bot, length(bot) - 1)"╝"
ind= left('', 3 + length(N) ) /*compute indentation.*/
col= ind ind ind' ' subword('"a- b- c- d- e- f- g- h- i-'", 1, n)
HI= substr('abcdefghi', N, 1); upper HI
say col ind ind ind '- means shift a column down'; say pad ind top
Line 109:
end /*r*/
say pad ind bot; say;
say translate(col, '+', "-") ind ind ind '"+ means shift a column up'"; say
return</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
Cookies help us deliver our services. By using our services, you agree to our use of cookies.