public AStarUtils(byte[] bytes, bool isFourWay = false)
    {
        ByteArray.StartRead(bytes);
        this.numCols = ByteArray.ReadInt();
        this.numRows = ByteArray.ReadInt();

        this.isFourWay       = isFourWay;
        this.iAStarHeuristic = new AStarManhattanHeuristic();

        AStarNode node = null;

        this.nodes = new Dictionary <int, AStarNode> ();
        int i, j;

        for (i = 0; i < this.numCols; i++)
        {
            for (j = 0; j < this.numRows; j++)
            {
                node          = new AStarNode(i, j);
                node.walkable = ByteArray.ReadByte() == 0 ? true : false;
                node.AddHeuristic(this.RefreshLinksOfAdjacentNodes, node);
                this.nodes.Add(this.GetNodeKey(i, j), node);
            }
        }
        this.RefreshLinksOfAllNodes();
        this.binaryHeapUtils = new BinaryHeapUtils(numCols * numRows / 2);
    }
    public AStarUtils(int numCols, int numRows, bool isFourWay = false)
    {
        this.numCols         = numCols;
        this.numRows         = numRows;
        this.isFourWay       = isFourWay;
        this.iAStarHeuristic = new AStarManhattanHeuristic();

        AStarNode node = null;

        this.nodes = new Dictionary <int, AStarNode> ();
        int i, j;

        for (i = 0; i < this.numCols; i++)
        {
            for (j = 0; j < this.numRows; j++)
            {
                node = new AStarNode(i, j);
                node.AddHeuristic(this.RefreshLinksOfAdjacentNodes, node);
                this.nodes.Add(this.GetNodeKey(i, j), node);
            }
        }
        long startTime = GlobalTime.currentTimeMillis;

        this.RefreshLinksOfAllNodes();
        this.binaryHeapUtils = new BinaryHeapUtils(numCols * numRows / 2);
        Debug.Log(GlobalTime.currentTimeMillis - startTime);
    }
Beispiel #3
0
    public AStarUtils(int numCols, int numRows, bool isFourWay = false)
    {
        Debug.Log("AStarUtils: " + numCols + ", " + numRows);
        this.numCols         = numCols;
        this.numRows         = numRows;
        this.isFourWay       = isFourWay;
        this.iAStarHeuristic = new AStarManhattanHeuristic();
        //this.iAStarHeuristic = new AStarDiagonalHeuristic ();

        AStarNode node = null;

        this.nodes = new Dictionary <string, AStarNode>();
        for (int i = 0; i < this.numCols; i++)
        {
            for (int j = 0; j < this.numRows; j++)
            {
                node = new AStarNode(i, j);
                node.AddHeuristic(this.RefreshLinksOfAdjacentNodes, node);
                this.nodes.Add(this.GetNodeKey(i, j), node);
            }
        }
        this.RefreshLinksOfAllNodes();
        //numCols * numRows / 2 只需要判断节点,不需要叶节点
        this.binaryHeapUtils = new BinaryHeapUtils(numCols * numRows / 2);
    }
Beispiel #4
0
    ///// <summary>
    ///// 返回节点在指定的代价内可移动的范围
    ///// </summary>
    ///// <returns>The range.</returns>
    ///// <param name="startNode">Start node.</param>
    ///// <param name="costLimit">Cost limit.</param>
    //public IList<AStarNode> WalkableRange(AStarNode startNode, int costLimit)
    //{
    //    this.walkableRangeCheckNum++;

    //    int maxStep = (int)(costLimit / STRAIGHT_COST);

    //    int startX = Mathf.Max(startNode.nodeX - maxStep, 0);
    //    int endX = Mathf.Min(startNode.nodeX + maxStep, this.numCols - 1);


    //    int startY = Mathf.Max(startNode.nodeY - maxStep, 0);
    //    int endY = Mathf.Min(startNode.nodeY + maxStep, this.numRows - 1);

    //    IList<AStarNode> rangeList = new List<AStarNode>();
    //    for (int i = startX; i <= endX; i++)
    //    {
    //        for (int j = startY; j <= endY; j++)
    //        {
    //            AStarNode nodeItem = this.nodes[this.GetNodeKey(i, j)];
    //            if (nodeItem.walkable && nodeItem.walkableRangeCheckNum != walkableRangeCheckNum)
    //            {
    //                IList<AStarNode> pathList = this.FindPath(startNode, nodeItem);
    //                if (pathList != null && pathList[pathList.Count - 1].f <= costLimit)
    //                {
    //                    foreach (AStarNode node in pathList)
    //                    {
    //                        if (node.walkableRangeCheckNum != walkableRangeCheckNum)
    //                        {
    //                            node.walkableRangeCheckNum = walkableRangeCheckNum;
    //                            rangeList.Add(node);
    //                        }
    //                    }
    //                }
    //            }
    //        }
    //    }
    //    return rangeList;
    //}

    //public AStarUtils(int numCols, int numRows, bool isFourWay = false)
    //{
    //    this.numCols = numCols;
    //    this.numRows = numRows;
    //    this.isFourWay = isFourWay;
    //    this.iAStarHeuristic = new AStarManhattanHeuristic();
    //    //this.iAStarHeuristic = new AStarDiagonalHeuristic ();

    //    AStarNode node = null;
    //    this.nodes = new Dictionary<int, AStarNode>();
    //    for (int i = 0; i < this.numCols; i++)
    //    {
    //        for (int j = 0; j < this.numRows; j++)
    //        {
    //            node = new AStarNode(i, j);
    //            node.AddHeuristic(this.RefreshLinksOfAdjacentNodes, node);
    //            this.nodes.Add(this.GetNodeKey(i, j), node);
    //        }
    //    }
    //    this.RefreshLinksOfAllNodes();
    //    this.binaryHeapUtils = new BinaryHeapUtils(numCols * numRows / 2);
    //}

    public AStarNode Insert(int _x, int _y)
    {
        AStarNode node = new AStarNode(_x, _y);

        node.AddHeuristic(this.RefreshLinksOfAdjacentNodes, node);
        this.nodes.Add(this.GetNodeKey(_x, _y), node);
        return(node);
    }
Beispiel #5
0
    public AStarUtils(int numCols, int numRows, bool isFourWay = false)
    {
        _numCols         = numCols;
        _numRows         = numRows;
        _isFourWay       = isFourWay;
        _iAStarHeuristic = new AStarManhattanHeuristic();
        //_iAStarHeuristic = new AStarDiagonalHeuristic ();

        _nodes = new Dictionary <string, AStarNode>();
        for (var i = 0; i < _numCols; i++)
        {
            for (var j = 0; j < _numRows; j++)
            {
                var node = new AStarNode(i, j);
                node.AddHeuristic(RefreshLinksOfAdjacentNodes, node);
                _nodes.Add(GetNodeKey(i, j), node);
            }
        }
        RefreshLinksOfAllNodes();
        _binaryHeapUtils = new BinaryHeapUtils(numCols * numRows / 2);
    }
	public AStarUtils(byte[] bytes,bool isFourWay = false)
	{
		ByteArray.StartRead(bytes);
		this.numCols = ByteArray.ReadInt ();
		this.numRows = ByteArray.ReadInt ();

		this.isFourWay = isFourWay;
		this.iAStarHeuristic = new AStarManhattanHeuristic ();

		AStarNode node = null;
		this.nodes = new Dictionary<int, AStarNode> ();
		int i, j;
		for(i = 0; i < this.numCols; i++)
		{
			for(j = 0; j < this.numRows; j++)
			{
				node = new AStarNode(i, j);
				node.walkable =  ByteArray.ReadByte() == 0 ? true : false;
				node.AddHeuristic(this.RefreshLinksOfAdjacentNodes, node);
				this.nodes.Add(this.GetNodeKey(i, j), node);
			}
		}
		this.RefreshLinksOfAllNodes();
		this.binaryHeapUtils = new BinaryHeapUtils(numCols * numRows / 2);
	}
	public AStarUtils(int numCols, int numRows, bool isFourWay = false)
	{
		this.numCols = numCols;
		this.numRows = numRows;
		this.isFourWay = isFourWay;
		this.iAStarHeuristic = new AStarManhattanHeuristic ();

		AStarNode node = null;
		this.nodes = new Dictionary<int, AStarNode> ();
		int i, j;
		for(i = 0; i < this.numCols; i++)
		{
			for(j = 0; j < this.numRows; j++)
			{
				node = new AStarNode(i, j);
				node.AddHeuristic(this.RefreshLinksOfAdjacentNodes, node);
				this.nodes.Add(this.GetNodeKey(i, j), node);
			}
		}
		long startTime = GlobalTime.currentTimeMillis;
		this.RefreshLinksOfAllNodes();
		this.binaryHeapUtils = new BinaryHeapUtils(numCols * numRows / 2);
		Debug.Log (GlobalTime.currentTimeMillis-startTime);
	}
	public AStarUtils(int numCols, int numRows, bool isFourWay = false)
	{
		this.numCols = numCols;
		this.numRows = numRows;
		this.isFourWay = isFourWay;
		this.iAStarHeuristic = new AStarManhattanHeuristic ();
		//this.iAStarHeuristic = new AStarDiagonalHeuristic ();
		
		AStarNode node = null;
		this.nodes = new Dictionary<string, AStarNode> ();
		for(int i = 0; i < this.numCols; i++)
		{
			for(int j = 0; j < this.numRows; j++)
			{
				node = new AStarNode(i, j);
				node.AddHeuristic(this.RefreshLinksOfAdjacentNodes, node);
				this.nodes.Add(this.GetNodeKey(i, j), node);
			}
		}
		this.RefreshLinksOfAllNodes();
		this.binaryHeapUtils = new BinaryHeapUtils(numCols * numRows / 2);
	}