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)
o
s to.
s, or changing them to spaces and adding a border. It's kinda unreadable at the moment. \$\endgroup\$