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);
    }
示例#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);
    }
示例#4
0
 public void CompleteInsert()
 {
     if (iAStarHeuristic == null)
     {
         iAStarHeuristic = new AStarManhattanHeuristic();
     }
     this.RefreshLinksOfAllNodes();
     if (binaryHeapUtils == null)
     {
         binaryHeapUtils = new BinaryHeapUtils(nodes.Count / 2);
     }
     else
     {
         binaryHeapUtils.Reset();
     }
 }
示例#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);
	}
示例#8
0
	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);
	}