小编EAz*_*edo的帖子

如何检查在迷宫C#上搜索的上一个路径

我正在尝试编写一个解决迷宫问题的算法,但我正面临一些难以正确应用它.

算法在墙壁上运行,而不是在找到有效点后改变方向.

Github上的完整代码

我不清楚如何检查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)

c# console-application

26
推荐指数
2
解决办法
794
查看次数

使用 Promise.reject 和 javascript 的正确方法是什么

我有以下这段代码

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)

拒绝承诺的正确方法是什么?

javascript node.js

0
推荐指数
1
解决办法
533
查看次数

标签 统计

c# ×1

console-application ×1

javascript ×1

node.js ×1