为国际象棋游戏创建棋盘演示
我开始为国际象棋游戏作业制作一块 8 x 8 的方形棋盘。然而,我想知道是否有任何提示可以在 Java 中创建正方形而不是二维数组。
分配的限制之一不允许使用二维数组或任何类似的数组。没有人工智能,只有用户控制。
I am starting to make a 8 x 8 square board for Chess Game Assignment. However, I am wondering if there's anything hint to create the square rather than the 2D array in Java.
one of the restrictions for the assignment disallows to use 2D array or any similar. There's no AI but user control only.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用一维数组,例如
Figure [] board = new Figure[64]
并创建一个简单的 getter/setter 方法来模拟二维:You can use one-dimensional array, say
Figure [] board = new Figure[64]
and make a simple getter/setter method to emulate 2-dimensions:您可以使用一维数组或 ArrayList,然后除以 8,并使用结果和余数来了解您需要进入哪一列和哪一行。
然后,您可以反过来操作以获得相应棋盘部分在数组中的位置。
You could use a 1 dimensional array or
ArrayList
and then divide by 8 and use the result and the remainder to know in which column and row you need to go.You can then work the other way round to obtain the location in the array for the corresponding chess board section.
您还可以使用地图:
You also can use Map:
我没有 Java 的工作知识,我会下棋并做一些 Delphi 编程。我不知道 Java 的位操作功能。
但是,我建议您研究 Bitboard 数据结构并在网上搜索开源国际象棋引擎基于它。
这在 C++ 世界中很常见。
I have no working knowledge of Java, I play chess and do some Delphi programming. I have no idea of bit manipulation capabilities of Java.
But, I suggest you to investigate on Bitboard data structure and search on the net for open source chess engine based on it.
It's a commonplace in c++ world.
也许你甚至可以一开始就不创建一个正方形?
表示棋盘的另一种方法是棋子列表及其各自的坐标。
Perhaps yo ucan get away with not even creating a square in the first place?
An alternate way to represent a chess board would be just a list of pieces and their respective coordinates.