Programmer Puzzle: Encoding a chess board state throughout a game

前端 未结 30 1525
闹比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:54

    The really big lookup table approach

    Position - 18 bytes
    Estimated number of legal positions is 1043
    Simply enumerate them all and the position can be stored in just 143 bits. 1 more bit is required to indicate which side is to play next

    The enumeration is not practical of course, but this shows that at least 144 bits are required.

    Moves - 1 byte
    There are usually around 30-40 legal moves for each position but the number may be as high as 218 Lets enumerate all the legal moves for each position. Now each move can be encoded into one byte.

    We still have plenty of room for special moves such as 0xFF to represent resigning.

提交回复
热议问题