Help Sam understand chess For this challenge, you will be writing a program or function which outputs (or prints) (in a reasonable format, i.e single string or an array of lines) a chess board which indicates all the possible moves of a piece given an empty board.



There are 5 chess pieces (for this challenge a pawn may be ignored):


Bishop (Moves diagonally any number of squares)
Rook (Moves orthogonally any number of squares)
Queen (Moves diagonally or orthogonally any number of squares)
KNight (Moves in an L shape, i.e. two in one dimension, and one in the other)
King (Moves one step orthogonally or diagonally)




Your submission will take in three inputs: the row of the chess piece, the column of the chess piece, and the type of piece (as a character or integer).

Say we call drawBoard(4,4,'N') for the Knight using 0-indexing, the output will be as follows:

........
........
...M.M..
..M...M.
....N...
..M...M.
...M.M..
........


where the '.' and 'M' can be replaced accordingly with printable ascii characters of your choice.  

Sample outputs as follows for other piece types. (Note all of these are called with input of 4,4 and are 0-indexed).

King:

........
........
........
...mmm..
...mKm..
...mmm..
........
........


Rook:

....m...
....m...
....m...
....m...
mmmmRmmm
....m...
....m...
....m...




Sam does not mind 1-based indexing, or even indexing following chess algebraic notation. However, your code must be as small as possible so Sam has enough space to think about his chess with the code next to him.

Sam has also realized that outputs will be accepted regardless of trailing or preceding whitespace (before and after input and each line)
Ruby, 125
anonymous function, prints to stdout.
RevB: golfed, but a bug fix brought it back to the same length as before.
-&gt;x,y,z{72.times{|i|v=y-i/9;u=x-i%=9
e=u*u+v*v
$&gt;&lt;&lt;(i&lt;8?e&lt;1?z:[r=0==v*u,b=u*u==v*v,b|r,3&gt;e,5==e][&quot;RBQKN&quot;=~/#{z}/]??*:?.:$/)}}

Prints each of the 64 squares + 8 newlines = 72 characters individually.
Relies on e, the square of the Euclidean distance between the current square and the given coordinates for checking king moves and knight moves (and also for printing the piece value z when the Euclidean distance is zero.)
Ungolfed in test program
f=-&gt;x,y,z{                         #x,y,character
  72.times{|i|                     #8 rows of (8 chars + newline) = 72 chars
    v=y-i/9;                       #vertical diff between y coord and current square
    u=x-i%=9                       #horizontal diff between x coord and current square. note i%=8
    e=u*u+v*v                      #square of euclidean distance
    $&gt;&lt;&lt;(                          #$&gt; is stdout. send to it....
      i&lt;8?                         #if not the newline column,
        e&lt;1?z:                       #if the euclidean distance is 0, print the symbol for the piece, else
        [r=0==v*u,                   #TRUE if v or u is 0 (rook)
        b=u*u==v*v,                  #TRUE if abs(u)==abs(v) (bishop)
        b|r,                         #TRUE if either of the above are true (queen)
        3&gt;e,                         #TRUE if e == 1 or 2 (king)
        5==e                         #TRUE if e == 5 (knight)
        ][&quot;RBQKN&quot;=~/#{z}/]??*:?.:    #select value from array corresponding to piece and print * or . accordingly
      $/                           #if newline column, print a newline
    )
  }
}

x=gets.to_i
y=gets.to_i
z=gets.chomp
f[x,y,z]