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

后端 未结 6 1769
陌清茗
陌清茗 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:09

    In terms of lists, I would highly recommend against using a structure that uses linked lists in this situation. You'll likely already know the positions that you want to investigate (x-y coordinates), and so a linked list would require O(n) time to simply grab the value of the checkerboard space. As other answers have mentioned, a bitmap or long approach would be ideal.

    In terms of how to organize the data, I would imagine that an implementation where both the black and white are stored in the same structure would be ideal. You'll have some overhead since storing 2 and 3 in binary require the same amount of memory, though if you're writing checkers, you'll likely need to stored "kinged" data anyway. Having the ability to check if a space is open by performing a single lookup should provide a significant performance benefit.

    Hope this helps.

提交回复
热议问题