我正在尝试编写九人莫里斯(https://en.wikipedia.org/wiki/Nine_men%27s_morris)游戏的程序。但我不知道集合库的哪种数据结构最适合保存棋子及其在棋盘上的位置。我对数据结构的第一个想法是: Board = arrayList =arrayList,但是很难检查是否有3个连续的数据结构。
发布于 2021-07-01 16:13:19
我会列出三个列表:
每个“环”对应一个:假设你从左下角开始每个列表,然后顺时针方向继续。
-> List#1 contains A1, A4, A7, D7, G7, G4, G1, D1 // outer ring
-> List#2 contains B2, B4, B6, D6, F6, F4, F2, D2 // middle ring
-> List#3 contains C3, C4, C5, D5, E5, E4, E3, D3 // inner ring要检查环中是否有三个列表:对于每个列表,请检查listitems
0 == 1 == 2 (lower left to upper left) or
2 == 3 == 4 (upper left to upper right) or
4 == 5 == 6 (upper right to lower right) or
6 == 7 == 0 (lower right to lower left)对于环之间的“连接”,你必须检查每个列表的奇数项是否匹配,例如
list1[1] == list2[1] == list3[1]
list1[3] == list2[3] == list3[3]
...
list1[7] == list2[7] == list3[7]这应该很容易在java中实现。
https://stackoverflow.com/questions/68205970
复制相似问题