Java 目标到源:路径是否存在?

Java 目标到源:路径是否存在?,java,path,grid,src,Java,Path,Grid,Src,这个代码有什么问题?它尝试将访问的坐标标记为1,以便不重新访问这些坐标,然后从水平或垂直目标点添加或减去一个坐标,并重复该过程 public static boolean pathExists(int destX, int destY, int sourceX, int sourceY) { if (sourceY == destY && sourceX == destX) { return true; } if ((coordi

这个代码有什么问题?它尝试将访问的坐标标记为1,以便不重新访问这些坐标,然后从水平或垂直目标点添加或减去一个坐标,并重复该过程

public static boolean pathExists(int destX,
        int destY, int sourceX, int sourceY) {
    if (sourceY == destY && sourceX == destX) {
        return true;
    }

if ((coordinates[destX][destY] == 0) && isMoveableTo(destX, destY)) {

                coordinates[destX][destY] = 1;          
                return ((pathExists(destX + 1, destY, sourceX, sourceY) && isMoveableTo(destX + 1, destY))
                        || (pathExists(destX, destY + 1, sourceX, sourceY) && isMoveableTo(destX, destY + 1))
                        || (pathExists(destX - 1, destY, sourceX, sourceY) && isMoveableTo(destX - 1, destY))
                        || (pathExists(destX, destY - 1, sourceX, sourceY) && isMoveableTo(destX, destY - 1))); 
}
return false;
}
问题在于,它可以同时从destX减去1,从destY减去1(?),试图沿对角线移动,这是它不可能做到的


谢谢。

此代码不会从destX和destY中减去1,因此问题在别处。问题似乎在别处,顺便说一句,最后一个条件中的按位and运算符是一个输入错误?是的。现在已经修好了,但我也有同样的问题。会对代码的其他部分做更多的挖掘,明白了。必须移除底部的isMoveableTo。