路径生成算法的困惑 [英] Path generation algorithm confusion

查看:147
本文介绍了路径生成算法的困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问在这里创建路径生成算法一些帮助,在这里Taekahn是亲切足以帮助我。我理解他的所有code除了一节中, IsNotMarked 功能。

FIDDLE

function IsNotMarked(row, column) {
    //if row is out of bounds, it is not marked
    if (row < 0 || row >= matrix.length) return true;

    //if column is out of bounds, it is not marked
    if (column < 0 || column >= matrix[row].length) return true;

    //if ahead node (east of East Node) is not part of path... it's not marked
    return matrix[row][column].data('partOfPath') != true;
}

即:<!code>返回矩阵[行] [列]的.data('partOfPath')= TRUE;

上面的函数 IsNotMarked() CreateNewFrontier(),应该检查每个方向上的相邻节点(北,东,南,西)首先检查,如果他们在边界...

The function above IsNotMarked(), CreateNewFrontier(), is supposed to check the neighboring nodes in each direction (north, east, south, west) to first check if they are in bounds...

然后 AddToFrontier()应该检查节点周边的这些的节点(节点东临节点)进行检查,如果他们不标记(路径的一部分),因为要保持单一路径,一个节点只能有一个邻居。

Then AddToFrontier() is supposed to check the nodes neighboring those nodes (node east of the East Node) to check if they are not marked (part of path), because to maintain the single path, a node can only have one neighbor.

问题:

1)我试图取代

return matrix[row][column].data('partOfPath') != true;

if (matrix[row][column].data('partOfPath') == false) return true;

我认为这意味着同样的事情,但它只是标志着根节点并不起作用。如何在这两个有什么不同?是不是真的,如果该节点不可路径的一部分,然后返回 IsNotMarked 为真?

2)我也试图通过消除简化IT IsNotMarked()通过简单的检查,如果该节点是直接在 AddToFrontier路径的一部分(共),但现在没有平局都:

2) I also tried simplifying it by removing IsNotMarked() altogether by simply checking if the node is part of the path directly in AddToFrontier(), but now nothing draws at all:

    if (row - 1 >= 0 && matrix[row-1][column].data('partOfPath') == true) { //check if it IS marked... 
        markedNeighbors++;
    }

任何帮助将是真棒!

Any help would be awesome!

推荐答案

的差异发生在矩阵[行] [列]的.data('partOfPath')既不是真也不假(如未定义)。

The difference happens when matrix[row][column].data('partOfPath') is neither true nor false (e.g. null or undefined).

在这种情况下,下面的语句返回

In this case, the following statement returns true:

return matrix[row][column].data('partOfPath') != true;

但下面为假(注意,您怎么还需要else语句):

But the following returns false (note how you also need the else statement):

if (matrix[row][column].data('partOfPath') == false)
    return true;
else
    return false;

这篇关于路径生成算法的困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆