What is the best data-structure to represent a checkers board when speed is the primary concern?

后端 未结 6 1753
陌清茗
陌清茗 2020-12-31 18:23

I am currently implementing something quite similar to checkers. So, I have this table game and there are both white and black pieces. Where there are neither white or black

6条回答
  •  爱一瞬间的悲伤
    2020-12-31 19:13

    A common way of doing that is with a long type's binary representation for each player.
    (since there are 64 squares on the board).. As Charlie already said..
    Here's a very good (but reather general) wiki article.

    The usage is simple - for example, if you want to check if all pieces can move say up and right, shift the player's pieces represntation 7 bits to the left, and check if there are opponent pieces there, then shift them 7 bits left again, and check if those squares are clear...
    I used it in a Reversi competition once, and can say the implementation wasn't too hard.
    HTH.

提交回复
热议问题