[Community Puzzle] Is the King In Check? (Part 1)

https://www.codingame.com/training/easy/is-the-king-in-check-part-1

Send your feedback or ask for help here!

Created by @DrQuarius,validated by @PaarthThePro,@1337_KD3R and @tuna_in_cream.
If you have any issues, feel free to ping them.

Good clean family fun. Thumbs up!

I recommend adding the tags 2D array and possibly Parsing and loops.

While you certainly could use a 2D array, this puzzle does not require it. Simply noting the positions of the two pieces is enough.

I do think a test should be added that checks for a knight that is across the board from the king (i.e. too far away too capture). My current solution would fail that case because, as the instructions point out, the knight basically hits the spots that the queen cannot (in a 5x5 grid), and all I’m doing when checking the knight is checking to see if the queen can capture from the same position.

Basically, I intentionally left my solution as such to see if it was covered in the validators when I submitted, but it wasn’t.

2 Likes

Thanks for pointing this out… That’s certainly worth modifying to protect against.