예제 #1
0
    /// <summary>
    /// Creates a New Node.
    /// </summary>
    /// <returns>The nearby block.</returns>
    /// <param name="x">The x coordinate of new node.</param>
    /// <param name="y">The y coordinate of new node.</param>
    /// <param name="originalNode">The original node, which is a nearby node to this new node.</param>
    private BlNode CreateNewNode(float x, float y, BlNode originalNode)
    {
        BlNode t = new BlNode(new Vector3(x, y, 0));

        t.distanceScore = t.GetDistanceScore(dest);
        t.stepScore     = originalNode.stepScore + 1;

        return(t);
    }
예제 #2
0
    private bool _solved = false;                       // a flag indicating whether the problem is solved



    // Use this for initialization
    void Start()
    {
        // initializate the block information and gamObject arrays
        _mapInformation = new BlockType[NUMBER, NUMBER];
        _blockArray     = new GameObject[NUMBER, NUMBER];

        // initializate the priority queue
        pqueue = new PriorityQueue <BlNode>();

        initializeArray();

        for (int i = 0; i < NUMBER; i++)                        // initialize that all the surrounding
        {
            _mapInformation[0, i]          = BlockType.blockingblock;
            _mapInformation[NUMBER - 1, i] = BlockType.blockingblock;
            _mapInformation[i, 0]          = BlockType.blockingblock;
            _mapInformation[i, NUMBER - 1] = BlockType.blockingblock;
        }

        // relocate the cached camera
        myCamera.transform.position = new Vector3(NUMBER / 2, NUMBER / 2, -10);
        myCamera.orthographicSize   = NUMBER / 2;

        // show all blocks
        ShowBlocks();

        // initialize the BlNode for the source and saved into the priority queue
        BlNode st = new BlNode(sour);

        st.stepScore     = 0;
        st.distanceScore = st.GetDistanceScore(dest);
        pqueue.Enqueue(st);

        // start the solve coroutine (show details for each step)
        StartCoroutine(Solve());
    }