Jack and Jane decided to play a game of chess to while away time. Unfortunately, Jack is rather bad at visualizing. He finds it tough to figure the moves possible for a given piece other than a pawn, of course!
Your challenge is to help find Jack the possible options for a given piece (other than a pawn).
In case one has forgotten, the various pieces are denoted by:
- K: King
- Q: Queen
- N: Knight
- B: Bishop
- R: Rook
As an example, in the following image the Knight is located at d4
and can move to c2
, b3
, b5
, c6
, e6
, f5
, f3
, e2
. For a given input:
Nd4
you would produce:
Nc2 Nb3 Nb5 Nc6 Ne6 Nf5 Nf3 Ne2
Rules:
- The order of the output doesn't matter as long as all the possible moves are listed
- The possible moves can be separated by whitespaces, newlines or any other delimiter
- The input can be passed to the program as a parameter or via
STDIN
- Whitespace in the program shall be counted, so make optimum use of it
This is code golf. (Please avoid making use of any tools/utilities specifically designed for the purpose.) The shortest answer wins!
f(x)... case "Q": {f("B");f("R")}
If the function requires any #includes these should be part of the byte count. \$\endgroup\$