什么是最好的数据结构来重新present当速度是首要关注的一个跳棋板?跳棋、数据结构、首要、速度

2023-09-11 03:51:45 作者:從此灬葑芯

我目前正在实施的东西非常相似,跳棋。所以,我有这样的桌牌游戏,有白色和黑色两种件。哪里有没有白色或黑色的碎片,你dno't有件。

我目前做的 GetValidMoves()这将返回当前所有的动作之一可以与目前的主板做的方法。

我因此想知道什么可能是重新present板的最佳途径。天真的办法是与0的1和2的(无一块,白一块,黑一块)的矩阵。

其他的想法是不是一个矩阵重新董事会presentation,有2个表(或任何其他数据结构):一个是黑片,其余为白

我实现这个游戏来测试一些人工智能算法,所以我最关心的是速度。我基本上把2 AI玩家打对方,对每一个打开的每个球员都应该有他所有的有效动作的列表,然后他会选择什么样的动做,这总是在发生,直到比赛结束(部分玩家获胜或者有一个并列)。

PS:我不是问的AI算法,我只是想知道什么是最好的数据结构来处理板,以便它可以很容易地

查找所有有效举措为当前玩家 请移动 验证的比赛还没有结束(这是在当一个球员失去了他所有的作品或一个球员达到了主板的另一侧)。 解决方案

考虑使用位图:​​2个64位无符号整数,一个是白一黑。然后你就可以重新present移动和电路板位置为函数从(宽x B) - > (宽x B)其中的是W 的 B 的再present分别为一组可能的白色和可能的黑色位置。

那么大部分的板位置的东西可以和整数运算,这大约是一样快,你可以​​做到。

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 pieces, you dno't have pieces.

I'm currently doing the GetValidMoves() method that'll return all the current moves one can do with the current board.

债市反弹后,近期关注什么

I am thus wondering what might be the best way to represent the board. The naive approach would be to have a matrix with 0's 1's and 2's (for no piece, white piece and black piece).

Other idea would be to instead of a matrix representation of the board, have 2 lists(or any other data-structure): one for black pieces, other for white.

I am implementing this game to test some AI algorithms, so my main concern is speed. I will basically put 2 AI players playing each other, for each turn each player should have a list of all his valid moves and then he'll choose what move to do, this always happening until the game ends(some player wins or there's a tie).

PS: I am not asking about the AI algorithm, I just want to know what would be the best data-structure to handle the board, so that it makes it easy to

Look for all the valid moves for the current player Do a move Verify the game is not over (it is over when one player lost all his pieces or one player reached the other side of the board).

解决方案

Consider using a bitmap: two 64-bit unsigned ints, one for white and one for black. Then you can represent moves and board positions as a function from (W x B) -> (W x B) where W, B represent the set of possible white and possible black positions respectively.

Then most of the board position stuff can be done with integer arithmetic, which is about as fast as you can get.