How do I model a chessboard when programming a computer to play chess?

后端 未结 14 2287
夕颜
夕颜 2021-01-31 10:13

What data structures would you use to represent a chessboard for a computer chess program?

14条回答
  •  粉色の甜心
    2021-01-31 10:31

    Array of 120 bytes.

    This is a chessboard of 8x8 surrounded by sentinel squares (e.g. a 255 to indicate that a piece can't move to this square). The sentinels have a depth of two so that a knight can't jump over.

    To move right add 1. To move left add -1. Up 10, down -10, up and right diagonal 11 etc. Square A1 is index 21. H1 is index 29. H8 is index 99.

    All designed for simplicity. But it's never going to be as fast as bitboards.

提交回复
热议问题