Пример #1
0
    private List<Vector2> GetRouteTo(Vector3 target)
    {
        List<Vector2> ret = new List<Vector2>();
        //Create the problem and the agent
        Problem prob = new Problem(heroList.First().Position, target, matrix, guiManagerInstance.GetComponent<GuiManager>());
        SearchAgent agent = new SearchAgent(prob);
        //Get the selected 
        Node goalNode = null;
        switch (alg)
        {
            case AlgorithmsEnum.DFS:
                goalNode = agent.DFGS();
                break;
            case AlgorithmsEnum.BFS:
                goalNode = agent.BFGS();
                break;
            case AlgorithmsEnum.UCS:
                goalNode = agent.UCGS();
                break;
            case AlgorithmsEnum.AStar:
                goalNode = agent.AstarGS();
                break;
            default:
               goalNode = agent.DFGS();
                break;
        }
        var nodeRoute = goalNode.Path();
        nodeRoute.Reverse();
        foreach (var node in nodeRoute)
        {
            if (node.Action.HasValue)
            { 
                ret.Add(node.Action.Value);
                var pos = node.State.GetPosition();
                guiManagerInstance.GetComponent<GuiManager>().MarkMoveCell(new Vector3(pos.x, pos.y));
            }
        }

        return ret;
    }