• 154

## Learning Opportunities

This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.

## Goal

Find the winner (W or B) for the given chess board. If there isn't a King in checkmate position output N.

You have to make several assumptions:
- The given boards are legal and are assuming the official Chess rules: https://en.wikipedia.org/wiki/Rules_of_chess
- In every board there is a winner (no draws) or the board is not terminal (the game could be continued)
- An attacked King could be saved only by moving himself to a safe square (not by using another piece from the King's team)
- White pawns are moving upwards, while black pawns are moving downwards

Example board:
`...............k..............................R..K.....R........`

In this example the white rooks (uppercase R letters) are attacking all the squares the black king (lowercase k letter) could move onto, so the black king is in checkmate position and the white (W) player wins.
Input
8 lines: Each line contains 8 characters, which are representing a row on the board to analyze.

Characters can be:
`. - Not occupied square on the boardR - White RookN - White KnightB - White BishopQ - White QueenK - White KingP - White Pawnr - Black Rookn - Black Knightb - Black Bishopq - Black Queenk - Black Kingp - Black Pawn`
Output
W or B for the winning player or N if the game could be continued.
Constraints
Example
Input
```........
.......k
........
........
........
......R.
.K.....R
........```
Output
`W`

A higher resolution is required to access the IDE