[Community Puzzle] Where Was This Knight Before? - Puzzle discussion

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @Chris27,validated by @N3l,@EnjoyLife and @TBali.
If you have any issues, feel free to ping them.

I found the description about the first line of input confusing. At first I thought the knight was always going to be the second character in that list or an ‘N’. Not so.

Thank you for your feedback. I hope you had nevertheless fun solving it.

First an important clarification for everyone else trying to solve it: The puzzle does not assume any specific encoding for the pieces neither regarding letters used nor their order). The goal of the game is to identify which piece moves and detect a specific movement pattern. But it does not require any verification of the validity of the move nor predefined knowledge on the mapping of the letters. The only thing for sure is that there is at least one piece (the minimalistic chess configuration requires a king on each side, so 1 letter appearing in upper and lower case on the board).

Typical chess encodings use 6 letters. For example in English K, Q, B, N, R, P (King, Queen, Bishop, kNight, Rook and Pawn). But the letters depend ont the language (in France they use R, D, F, C, T, P - Roi Dame Fou Cavalier Tour Pion). Nothing prevents less pieces (because not all the pieces might remain on the input boards). Nothing prevents the use of a more fine graded encoding (Since each side has 16 pieces at the start, one could imagine at most 16 different letters). The difficulty here is to consider only the letters that need to be tracked, and to ignore the noise that might be caused by irrelevant letters.

Regarding the confusing description that lead you to think the knight would always comeq second, can you help me ? Is it the sentence “A string pieces containing the uppercase letters (A-Z) that represent the white pieces. (The corresponding lowercase letters represent the black pieces.)” ? Or is it another sentence ? Or did you get the narrative in another language than English ?

1 Like

Thanks for your answer and the very clear explanation. I think my confusion was caused mostly by the example that was given which caused me to make a false assumption. Also my own ignorance about chess encodings (in different languages) didn’t help. It became clear when figuring out why some test cases failed. Perhaps if I was given the example about the French chess encoding in the description I would have understood it earlier. Nevertheless, I liked your puzzle and learned something new again. Thank you.

1 Like

I have to mention one issue (and solution!) with the board notation that is bugging me. The board square notation is backwards.

The game states:

  • Line 1 : A string pieces containing the uppercase letters (A-Z) that represent the white pieces. (The corresponding lowercase letters represent the black pieces.)
  • Each coordinate is made of one lowercase letter (from a to h for the horizontal position on the board, from left to right) and one digit (from 1 to 8 for the vertical position, from bottom to top), the top left square being a8.

This notation stating that the top left square is a8 is correct from white’s perspective on a standard board.

However, the first test case flips the board, and white (uppercase) is on top. This means we are looking at the board from black’s perspective.

RNBQKBNR
PPPPPPPP
........
........
........
........
pppppppp
rnbqkbnr

The board is laid out wrong (the king and queen are in the incorrect places), and the square at the top left is actually h1. The board is rotated 180 degrees because that is the side the white pieces are on.

That also means that the solution is incorrect.

RNBQKBNR
PPPPPPPP
........
........
........
....p...
pppp.ppp
rnbqkbnr

The solution should be d7-d6, not e2-e3.

But, black should never move first anyways. So, in a proper chess sense, d7-d6 wouldn’t make sense as a first move.

I get it. This is a coding challenge, not a chess challenge. The coding solution to the problem is not affected by chess rules. But, I feel like since you are using chess notation as the basis for the rules of the game, you should follow proper chess rules.

Fortunately there is a very easy solution. Just switch the description of the problem so that white pieces are designated by the lowercase letters, and black pieces by the uppercase letters. That would flip the board into the correct notation, and correct the starting piece layout, without needing to make any other changes.

2 Likes

Thank you very much for your kind and useful feedback. You are of course fully right!
I realised the mismatch between the colours at a late stage, just before the last vote and only a few days before the acceptance deadline. Correcting it at that moment would have reset the votes and might have caused the puzzle to fail its timely approval.

On the other side, the puzzle is fully solvable following strictly the narrative. And thanks to your comment, there is now a warning about the inconsistency in the colour conventions for advanced chess-players that could be confused :slight_smile:

I thank you for your suggestion. I will wait a bit before correcting it, just in case other improvements would be need. (Correcting the puzzle is not straightforward , as its approval would be reset and a new reviewing/approval cycle would be required, so I prefer to do it only once).

1 Like

You’re welcome! Thanks for taking the time to put together a great and interesting puzzle. Still enjoyed the challenge of solving it.

Once a contribution has been approved by three people, its approval status becomes permanent and won’t be reset by later edits. In other words, no change will trigger a new reviewing or approval cycle.

However, either trivial fixes (such as correcting typos) or absolutely necessary corrections or improvements should be applied to an approved contribution. It’s generally undesirable to keep editing an approved contribution, as frequent or unnecessary changes can make forum discussions harder to follow and may alter the version that reviewers originally evaluated.