Write a solver for the Chess Light puzzle game, in the smallest amount of code.
The input will be a representation of a chessboard, how in yours is up to you. My examples below is textual, in which some squares may already be occupied by black peices. Some of the unoccupied squares are designated with a
#, along with a list of white men to be placed. The goal is to place those men within the designated squares in such a way that every designated square is lit.
A chess piece lights up the squares which it attacks, including those occupied by men of the same colour but not those which have an interposing man, and not the one which it occupies itself. For example queen diagnol attack stops at the square occuppied by another peice and no further.
E.g. with the following board, the
* show the squares which are lit.
Q's square is unlit, but
R's square. The squares labelled
- would be lit except that
R is between them and
+--------+ |* * -| |* *- | |*****R**| |* ** | |* * * | |* * * | |** * | |Q*******| +--------+
There is one important exception: a chess piece under attack by a man of the opposite colour doesn't light up any squares, it still block the light of others passing thru.
Note that pawns light up the following squares.
* * P
p * *
Thus there is no en passant.
- White is playing up the board.
- Only one man is allowed on a square.
- All pieces assigned to be placed must be placed on the board
- An attacked piece, even if defended, is still attacked, but the defender does light up that square.
- White's men are denoted with capital letters and black's with lower-case letters:
The output (of mine) consists of a list of squares in the same order as the men listed in the input, using algebraic notation. Yours is up to you. * There could be no answer!
+--------+ | | | # | | # | | # # | | ###### | | # # | | # | | | +--------+ RR
RR are the pieces to be placed on the board.
Class B (19)
+--------+ | | | r | | | | ### b | | ### | | ### | | ### | | | +--------+ PPPK
PPPK are the pieces to be placed on the board.
D4, E4, E2, D3
Since the output is in the same order as the men, the white king is placed on
d3 and the other three squares receive white pawns.