Programmer Puzzle: Encoding a chess board state throughout a game

前端 未结 30 1536
闹比i
闹比i 2021-01-29 17:16

Not strictly a question, more of a puzzle...

Over the years, I\'ve been involved in a few technical interviews of new employees. Other than asking the standard \"do you

30条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-29 17:47

    I've thought about that one for a long time (+- 2hours). And there is no obvious answers.

    Assuming:

    1. Ignoring time state (A player didn't use to have a time limit therefore could force a draw by not playing)
    2. When was the game played?!? It's important because the rules have changed over time (so will assume a modern game in the subsequent point a modern game...) Please refer to dead pawn rule for example (wikipedia has a very famous problem showing it), and if you want to go back in time good luck bishop used to only move slowly and dice used to be used. lol.

    ... so up to date modern rules it is. First irrespective of repetition and move repitition limit.

    -C 25 bytes rounded ( 64b+32*4b+5b= 325b)

    =64 bits (something/nothing) +32*4 bits [ 1bit=color{black/withe} +3bit=type of piece{King,Queen,Bishop,kNight,Rook,Pawn,MovedPawn} NB:Moved pawn... e.g if it was the last moved pawn in the previous turn indicating that an 'en passant' is feasible. ] +5bit for the actual state (who's turn, en passant, possibility of rooking or not on each sides)

    So far so good. Probably can be enhanced but then there would be variable length and promotion to take in consideration!?

    Now, following rules are only applicable WHEN a player apllies for a draw, IT IS NOT automatic! So consider this 90 moves without a capture or a a pawn move is feasible if no player calls for a draw! Meaning that all moves need to be recorded... and available.

    -D repetion of position... e.g. state of board as mentioned above (see C) or not... (see following regarding the FIDE rules) -E That leaves the complex problem of 50 move allowance without capture or pawn move there a counter is necessary... However.

    So how do you deal with that?... Well really there is no way. Because neither player may want to draw, or realize that it has occurred. Now in case E a counter might suffice... but here is the trick and even reading the FIDE rules (http://www.fide.com/component/handbook/?id=124&view=article) I can't find an answer... what about loss of ability of rooking. Is that a repetition? I think not but then this is a blurred subject not addressed, not clarified.

    So here is two rules that are two complex or undefined even to try to encode... Cheers.

    So the only way to truly encode a game is to record all from start... which then conflict (or not?) with the "board state" question.

    Hope this help... not too much math :-) Just to show that some question are not as easy, too open for interpretation or pre-knowledge to be a correct and efficient. Not one I would consider for interviewing as it open too much of a can of worm.

提交回复
热议问题