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 Q lights R's square. The squares labelled - would be lit except that R is between them and 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.

White Pawn

 * *

Black Pawn

 * *

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: KQRNBP and kqrnbp, where Nn are kNights.

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!


Beginner (1)

|        |
|  #     |
|  #     |
|  #  #  |
| ###### |
|  #  #  |
|     #  |
|        |

RR are the pieces to be placed on the board.

Solution C4, F4

Class B (19)

|        |
|  r     |
|        |
|  ### b |
|  ###   |
|  ###   |
|  ###   |
|        |

PPPK are the pieces to be placed on the board. Solution 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.

  • \$\begingroup\$ Must all pieces be placed in a valid solution? Can pawns move in both directions or only one? \$\endgroup\$
    – feersum
    Commented Jan 26, 2015 at 19:56
  • \$\begingroup\$ @MartinBüttner Updated the challenge \$\endgroup\$ Commented Jan 26, 2015 at 20:11
  • \$\begingroup\$ Its still very unclear. What is the significance of lighting up * from the first example ? Can we place the pieces on any # . If yes, what challenge is it ? \$\endgroup\$
    – Optimizer
    Commented Jan 26, 2015 at 20:14
  • 1
    \$\begingroup\$ I've rewritten to put the goal at the start, so that the first half of the question has context. But there are some things which I'm unsure about. When you say that all of White's men must be placed on the board, is there an implicit statement that the men to place will only be white? Do you require the input to have the border, or can answers dispense with that? What choice of delimiters is there for the output? What about case sensitivity in the output? (Lower-case is more common than capitals in algebraic notation, but you use capitals in your examples). \$\endgroup\$ Commented Jan 26, 2015 at 22:57
  • 1
    \$\begingroup\$ An important one: do your two examples cover all of the corner cases (e.g. attacked men not lighting anything up, men not lighting their own squares)? And what should the output be if there is no solution, or may answers assume that this will never be the case? \$\endgroup\$ Commented Jan 26, 2015 at 22:59


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.