drunken-bishop ( bytes -- board )


Vocabulary
drunken-bishop.private

Inputs
bytesan object


Outputs
boardan object


Definition


:: drunken-bishop ( bytes -- board )
board-width get :> w board-height get :> h h
[ w <byte-array> ] replicate
:> board h 2/ :> y! w 2/ :> x! 15 x y board nth set-nth
bytes [
{ 0 -2 -4 -6 } [
shift 2 bits {
{ 0 [ -1 -1 ] }
{ 1 [ -1 1 ] }
{ 2 [ 1 -1 ] }
{ 3 [ 1 1 ] }
} case :> ( dy dx ) dy y + 0 h 1 - clamp y! dx x +
0 w 1 - clamp x! x y board nth
[ dup 14 < [ 1 + ] when ] change-nth
] with each
] each 16 x y board nth set-nth board ;