Пример #1
0
    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);
    }
Пример #2
0
    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);
    }
Пример #6
0
	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);
	}
Пример #7
0
	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);
	}