[Community Puzzle] Chess board analyzer


Send your feedback or ask for help here!

Created by @Di_Masta,validated by @selenae,@DepartmentOfRedundan and @KodeMonkey.
If you have any issues, feel free to ping them.

1 Like

You should have added the pat case, where the king is not in check position but can’t move either.

1 Like

pat is no move can be played … not only king …

I thought to propose that but (imho) it complicate so much the puzzle for nothing


I’m planning a second part of the puzzle, in which I’ll incorporate every rule of the game.

1 Like

Make a chess multiplayer game :slight_smile:

1 Like

It’s on my TODO list :slight_smile:

1 Like

Somehow I am stuck, challenge 7 or when the board is quite full my variables are changing. Any clue on how to prevent this? Seems some sort of overload on my 3 lists.


if you change w[0][0], the belegering[0][0] will change as well.

Seems like a bug to me.

Hi @hem123 maybe if you give some more context, we’ll help you better, like which language you are using, what exactly w; wt; belegering are representing.

The problem you’re describing sounds like pointers mismatch.

Also have you tried to “visually” debug the structures you’re using, you could print the board or arrays you are manipulating. Or you could use your local IDE for to track the structures without printing.

If you wrote before w=belegering in Python, it’s not a bug, it’s a feature. In fact, w and belegering are two pointers of the same data. If you don’t want this, create w with w=list(belegering).


There are many ways to do a copy of a list, on the benchmark the more efficient is:
L2 = [*L1]
With older version of python, it might not work so you can use L2 = L1[:] or L2 = list(L1) instead.
Note that you can do the same with sets:
S2 = {*S1}
If you have to copy a list of list (a matrix), a shallow copy like this won’t work, you need to deepcopy like that:
M2 = [[*row] for row in M1]


oke this seems to explain it. thanks didnt know that.

1 Like

It is not blocking, but the test case 14 (Escape by overtaking) seems strange. Is it really a legal position?
Otherwise thanks for the puzzle, it was funny to do.


Good to hear that :slight_smile:
Yeap, you’re right test 14 looks strange, I remember that I’ve got the board for the validator from a real professional game, but when modified it for the test apparently I’ve missed the fact that is not legal position.

I got all testcases right, but I’m failing validation 14 when I submit :frowning:

Are you sure you’ve implemented right the overtaking, a not guarded piece, by the king. That’s the validation test, the King must take one of its opponent adjacent piece.

1 Like

Quite a nice puzzle but I don’t know if it should belong to the Hard difficulty ^^

Hi, i’m having some trouble with the “N” case without doing some hardcoding.
My check function is working well, but i dont know how to “get legal moves of king”.
I guess if “check” is true, it should "try to move to legalmove(), and recheck if check is true, but i have no idea on how to do it. Can someone give me some guidance

You could iterate the adjacent King’s squares and check if the King could move there.
Something like:

arr kingMoves;
for (row = kingRow -1; row <= kingRow + 1; ++row) {
        for (col= kingCol -1; col <= kingCol + 1; ++col) {
            if (row != kingRow && col != kingCol && inBoard(row, col) && kingCouldMoveOn(row, col)) {
                kingMoves.add(row, col); 
1 Like

Thanks, i’ll work towards that ! =)

1 Like