我正在尝试编写一个解决迷宫问题的算法,但我正面临一些难以正确应用它.
算法在墙壁上运行,而不是在找到有效点后改变方向.
我不清楚如何检查previousPoint然后从那一点检查下一个有效的移动.
有人可以帮我提一些关于我可以去哪个方向的提示吗?
class MapPathFinder
{
public bool[,] correctPath = new bool[12,12];
public int[,] previousPoint = new int[12, 12];
public bool startPointFound = false;
public bool nextValidMove(MapFile map, int y, int x)
{
if ((y == map.width) && (x == map.height)) {
return false; //Checks if at the edge and terminates the method
}
if ((map.Matrix[y, x]) == 1 ) {
return true; // check if at a wall and terminate the method
}
if (y != 0) …Run Code Online (Sandbox Code Playgroud) 我有以下这段代码
new Promise((resolve, reject) => {
resolve(apiRequest(data))
reject(console.log('Error'))
}).then(response)
Run Code Online (Sandbox Code Playgroud)
两种方法(解决和拒绝)都被触发,但我只想在出现问题时调用拒绝。如果在这种情况下出现问题,我该如何抛出错误?
我检查过,但似乎我不能使用 If 语句来进行检查。
new Promise((resolve, reject) => {
const printResult = apiRequest(data)
console.log(printResult) //Outputs Promise {<pending>}
resolve(printResult) //Then it works
reject(console.log('Error'))
}).then(response)
Run Code Online (Sandbox Code Playgroud)
拒绝承诺的正确方法是什么?