[Community Puzzle] Chess board analyzer

https://www.codingame.com/training/hard/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

:thinking:
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

2 Likes

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.

w[i]=wt
belegering[i]=wt

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).

2 Likes

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]

2 Likes

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

1 Like

Hello,
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.

1 Like

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.