JavaScript (ES8), 173 bytes
Expects an array of characters and returns a matrix of characters.
a=>a.map(c=>~a?1/c?m[y][x]=" ░▒▓█"[c]||a:c<{}?a=c>"!"?-1:m[y][x]:c>"s"?y-=!!y:c>"d"?y+=y<24:x+=c>"a"?x<79:-!!x:a=c,m=[...1e9+{}].map(_=>[..."".padEnd(80)]),x=y=0)&&m
Commented
a => a.map(c => // for each character c in the input array a[]:
~a ? // if a is not -1:
1 / c ? // if c is a digit:
m[y][x] = // update m[y][x]:
" ░▒▓█"[c] // with either a 'grayscale' character
|| a // or a (if c = 5)
: // else:
c < {} ? // if c is not a letter:
a = // update a:
c > "!" ? // if c = "?":
-1 // use -1
: // else (c = "!"):
m[y][x] // use the character at the current position
: // else (c is a letter):
c > "s" ? // if c = "w":
y -= !!y // decrement y if it's not 0
: // else:
c > "d" ? // if c = "s":
y += y < 24 // increment y if it's less than 24
: // else:
x += // update x:
c > "a" ? // if c = "d":
x < 79 // increment x if it's less than 79
: // else (c = "a"):
-!!x // decrement x if it's not 0
: // else (a = -1):
a = c, // copy c in a
m = [...1e9 + {}] // start with a matrix m[] made of 25 rows ...
.map(_ => //
[..."".padEnd(80)] // ... of 80 columns, filled with spaces
), //
x = y = 0 // start with x = 0 and y = 0
) && m // end of map() -> return m[]
Arnauld
- 205.5k
- 21
- 187
- 670