notnil / chesscode

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] Guarantee Legal Positions

bmgarness opened this issue · comments

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.

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.

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

  • Thinking through encoding, maybe index legal positions per piece and then check the each piece

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.