gpt4 book ai didi

java - 获取所有受马影响的字段作为点数组

转载 作者:太空宇宙 更新时间:2023-11-04 07:09:17 25 4
gpt4 key购买 nike

我就是想不通这件事。我正在制作一款国际象棋游戏,我需要获得人物的影响...

我从一匹马开始,甚至在把它画在纸上之后也陷入了困境。我希望将其作为数组:

class Horse extends Figure {
public int[][] getRadius() {
//Allocate a max possible count of fields
int [][] return = new int[8][2];
//Now what?
???
}
}

这是我在纸上为自己制作的,用 Ms-paint 重新绘制的,希望它能对其他人有所帮助,因为它让我无助。
enter image description here
马坐在广场上,我想我画的是他所有可能的 Action 。听起来像是 {1,-1,2,-2} 与 2 个成员的组合且没有重复,不是吗?但如何以编程方式做到这一点呢? (数组中的列表必须相对于马匹的实际位置!)感谢您的任何提示。如果也有一篇关于其他人物的文章,那就会节省我很多时间!

如果图片给您带来愚蠢的想法,请保留它们,谢谢。

最佳答案

你想从 getRadius() 得到的是 (x,y) 的每个排列,其中 x, y ∈ {-2, -1, 1, 2} 和​​ |x| ≠ |y|。

int[][] ret = new int[8][2];
int[] set = {-2, -1, 1, 2};
int i = 0;
for(int x : set)
for(int y : set)
if(Math.abs(x) != Math.abs(y)){
ret[i][0] = x;
ret[i][1] = y;
i++;
}

关于java - 获取所有受马影响的字段作为点数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20894885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com