notnil / chesscode

MIT License
63 stars 0 forks source link

[Feature Request] Guarantee Legal Positions #1

Open bmgarness opened 2 years ago

bmgarness commented 2 years ago

So is there any way to guarantee a legal position, i.e. a position that could be played on the board including checkmate and stalemate from any encoded or decoded message. It would be suspicious if I left a bonkers position on the board for a secret message.

notnil commented 2 years ago

For a first pass, I couldn't figure that out using just the board position. The question is how do you index it so that it can be decoded in a reasonable time frame.

bmgarness commented 2 years ago

I looked at some similar issues where hashed values at the end have to have some rules. The best example was for things like product licenses where they wanted to stop things like curse words. I saw two paths for a solution.

  1. Limit the input a. They accomplished this by taking vowels out of the character set b. We could do the same by taking out pieces being in illegal positions and keeping normal Piece counts (for encoding?) i. pawns on first and eighth rank ii. Only let two knights, two bishops, etc iii. Don't let kings be in illegal positions
  2. Check the output a. They did this by checking for strings against a known set, performance wasn't an issue b. We could do the same especially if we figure out a indexing method

Thoughts on potential indexing methods

Again I think encoding might be the solution, We can always Decode legal and illegal positions but if we always encode legal positions then we get the desired effect.