Exemple #1
0
        public void CustomMaze1()
        {
            // Arrange
            var maze = new List <string>()
            {
                "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                "A.....x........x..............x",
                "x..x..x..xxxx..x..xxxxxxx..xxxx",
                "x..x..x.....x..x.....x........x",
                "x..x..xxxxxxx..xxxxxxx..xxxx..x",
                "x..x..x.....x..x.....x.....x..x",
                "x..x..x..x..x..x..x..xxxxxxx..x",
                "x..x..x..x..x.....x...........x",
                "x..x..x..x..x..xxxxxxxxxx..xxxx",
                "x..x..x..x.....x..............x",
                "x..x..x..xxxxxxxxxxxxxxxx..x..x",
                "x..x.....x........x..x.....x..x",
                "x..xxxxxxx..xxxx..x..x..xxxx..x",
                "x.....x.....x.....x.....x.....x",
                "xxxx..xxxx..xxxxxxxxxxxxx..x..x",
                "x..x.....x........x..x.....x..x",
                "x..xxxx..xxxxxxx..x..x..xxxx..x",
                "x..x.....x........x.....x.....x",
                "x..x..x..x..xxxxxxxxxxxxx..xxxx",
                "x.....x.................x.....B",
                "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
            };
            var expected = "Maze Directions from Start(A) to End(B): EEEESSSSSSSSSSEEEENNNNNNEESSSSEEEENNEEENNEESSEEEEEESSEEESSSSSSSSWWSSEEEE";

            // Assert
            var actual = AStarAlgorithm.AStarSearch(maze);

            Assert.AreEqual(expected, actual);
        }
Exemple #2
0
    private void FindPathDone(AStarAlgorithm aStar, bool found)
    {
        int id    = -1;
        int serId = -1;

        r_new_pos.GetField(ref id, "ID");
        r_new_pos.GetField(ref serId, "Server_ID");

        if (found)
        {
            string data = ResponseMessage(
                clientPath: aStar.Path,
                separateTime: GetTimes(aStar.Path, agentRemote.transform.position),
                curCellPosition: agentRemote.CurrentPosition,
                id: id,
                serId: serId);

            JSONObject moveObject = new JSONObject(JSONObject.Type.BAKED)
            {
                str = data
            };

            Emit("S_MOVE", moveObject);
        }
        else
        {
            Debugger.Log("Path not found");
        }
    }
Exemple #3
0
 private void FindPathDoneCallback(AStarAlgorithm aStar, bool found)
 {
     ThreadHelper.MainThreadInvoke(() =>
     {
         FindPathDone(aStar, found);
     });
 }
        public void AStarAlgorithmExecuteTest()
        {
            Func <IGraphEdge, Double> weightFunction = edge => Convert.ToDouble(edge["Weight"]);

            IDictionary <OperationParameter, Object> parameters = new Dictionary <OperationParameter, Object>();

            parameters[GraphOperationParameters.SourceVertex] = _sourceVertex;
            parameters[GraphOperationParameters.TargetVertex] = _targetVertex;
            parameters[GraphOperationParameters.WeightMetric] = weightFunction;

            AStarAlgorithm operation = new AStarAlgorithm(_sourceGraph, parameters);

            operation.Execute();

            Assert.AreEqual(_resultGraph.VertexCount, operation.Result.VertexCount);
            Assert.AreEqual(_resultGraph.EdgeCount, operation.Result.EdgeCount);

            foreach (IGraphVertex resultVertex in operation.Result.Vertices)
            {
                IGraphVertex vertex = _resultGraph.GetVertex(resultVertex.Coordinate);

                Assert.IsNotNull(vertex);
                Assert.AreEqual(vertex["Distance"], resultVertex["Distance"]);

                Assert.IsTrue(operation.Result.OutEdges(resultVertex).All(edge => _resultGraph.GetAllEdges(edge.Source.Coordinate, edge.Target.Coordinate).Count == 1));
            }
        }
    public void AStarEuclidian_CorrectPathFound_OneCorrectPath()
    {
        List <ILevelTile> expected = new List <ILevelTile>()
        {
            graphProvider.GetTileAtPos(new Vector2Int(2, 5)),
            graphProvider.GetTileAtPos(new Vector2Int(1, 5)),
            graphProvider.GetTileAtPos(new Vector2Int(1, 6)),
            graphProvider.GetTileAtPos(new Vector2Int(1, 7)),
            graphProvider.GetTileAtPos(new Vector2Int(2, 7)),
            graphProvider.GetTileAtPos(new Vector2Int(3, 7)),
            graphProvider.GetTileAtPos(new Vector2Int(4, 7)),
            graphProvider.GetTileAtPos(new Vector2Int(4, 6)),
            graphProvider.GetTileAtPos(new Vector2Int(4, 5)),
            graphProvider.GetTileAtPos(new Vector2Int(4, 4)),
            graphProvider.GetTileAtPos(new Vector2Int(5, 4)),
            graphProvider.GetTileAtPos(new Vector2Int(6, 4))
        };

        IPathFindingAlgorithm algo   = new AStarAlgorithm(graphProvider, new EuclidianHeuristic());
        ILevelTile            from   = graphProvider.GetTileAtPos(new Vector2Int(2, 5));
        ILevelTile            to     = graphProvider.GetTileAtPos(new Vector2Int(6, 4));
        IList <ILevelTile>    result = algo.CalculatePath(from, to);

        NUnit.Framework.Assert.IsTrue(result.Count == expected.Count);
        for (int i = 0; i < result.Count; ++i)
        {
            NUnit.Framework.Assert.IsTrue(result[i].Equals(expected[i]));
        }
    }
Exemple #6
0
        private void FindPathDone_Callback(AStarAlgorithm aStar, bool found)
        {
            path = aStar.Path;

            AgentController.ThreadHelper.MainThreadInvoke(() => InitalizeMove(found));
            AgentController.FindPathDone_OnlyMainThread(this, found);
        }
Exemple #7
0
        public void CalculatePaths(NeighbourMode neighbourMode, Action <object, int, int, int> onCellViewedCallback)
        {
            _pathMatrix = new IList <Vector2Int> [_transitionNodes.Count, _transitionNodes.Count];
            AStarAlgorithm aStarAlgorithm = new AStarAlgorithm();

            aStarAlgorithm.OnCellViewedEvent += onCellViewedCallback;
            CoordinateTransformer transformer = new CoordinateTransformer(this, LeftBottom);

            for (int i = 0; i < _transitionNodes.Count; i++)
            {
                for (int j = i + 1; j < _transitionNodes.Count; j++)
                {
                    var nodeA = _transitionNodes[i];
                    var nodeB = _transitionNodes[j];
                    IList <Vector2Int> path =
                        aStarAlgorithm.GetPath(transformer, nodeA.Position - LeftBottom, nodeB.Position - LeftBottom,
                                               neighbourMode);

                    _pathMatrix[i, j] = path;
                    _pathMatrix[j, i] = Utils.GetInvertedList(path);
                    if (path != null)
                    {
                        nodeA.SetWeight(nodeB, path.Count);
                        nodeB.SetWeight(nodeA, path.Count);
                    }
                }
            }
        }
Exemple #8
0
    private void Init()
    {
        InitalizeOffset();

        mapIns         = Singleton.Instance <HexMap>();
        breathFS       = Singleton.Instance <BreathFirstSearch>();
        aStarAlgorithm = new AStarAlgorithm(mapIns, maxDeep);
    }
Exemple #9
0
        private void InitASMap()
        {
            _aStarMap = new AStarAlgorithm();
            _aStarMap.SetMap(_tiles);
            hruns = new List <DoPlayer>();

            _ = SetHikeHero();
        }
Exemple #10
0
        public void SetUp()
        {
            var pq = new Mock <IPriorityQueueProvider <Point, IPriorityQueue <Point> > >();

            pq.Setup(x => x.Create())
            .Returns(() => new HeapPriorityQueue <Point>());
            algorithm = new AStarAlgorithm(new Mock <IRender>().Object, pq.Object);
        }
    public void AStarEuclidian_StartSameAsEnd()
    {
        IPathFindingAlgorithm algo   = new AStarAlgorithm(graphProvider, new EuclidianHeuristic());
        ILevelTile            from   = graphProvider.GetTileAtPos(new Vector2Int(1, 1));
        ILevelTile            to     = graphProvider.GetTileAtPos(new Vector2Int(1, 1));
        IList <ILevelTile>    result = algo.CalculatePath(from, to);

        NUnit.Framework.Assert.IsTrue(result.Count == 1);
    }
Exemple #12
0
        static void Main(string[] args)
        {
            Console.BufferWidth  = 300;
            Console.BufferHeight = 240;
            Console.WindowWidth  = 180;

            Console.WriteLine("Press any key to start...");
            Console.ReadKey();

            FileStream mapFileStream = File.Open("Maps/vadim_maze.cmap", FileMode.Open, FileAccess.Read);

            ConsoleMap map = ConsoleMapGenerator.FromText(mapFileStream, 'S', 'E', 'X', '.');

            _map = map;

            InitArrays(2);

            Vector2Int start = map.DefaultStart;
            Vector2Int stop  = map.DefaultStop;

            _start = start;
            _stop  = stop;
            Vector2Int scale   = new Vector2Int(4, 2);
            int        spacing = 4;


            InitConsoleDrawer(map, scale, spacing, start, stop, 0);
            InitConsoleDrawer(map, scale, spacing, start, stop, 1);

            Console.SetCursorPosition(0, map.Height * scale.Y);

            AStarAlgorithm aStarTest = new AStarAlgorithm();
            var            path      = aStarTest.GetPath(_map, start, stop, NeighbourMode.SideOnly);

            if (path != null)
            {
                Console.WriteLine("Path was found");
                DrawPath(path, 0);
            }

            _contestants[0] = new BestFirstSearch();
            _contestants[0].OnCellViewedEvent += OnCellUpdated;

            _contestants[1] = new AStarAlgorithm();
            _contestants[1].OnCellViewedEvent += OnCellUpdated;

            StartPathFinder(0);
            StartPathFinder(1);

            while (_runningTasks > 0)
            {
                Thread.Sleep(100);
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
    public void AStarEuclidian_NoPathExistent()
    {
        IPathFindingAlgorithm algo   = new AStarAlgorithm(graphProvider, new EuclidianHeuristic());
        ILevelTile            from   = graphProvider.GetTileAtPos(new Vector2Int(6, 7));
        ILevelTile            to     = graphProvider.GetTileAtPos(new Vector2Int(1, 1));
        IList <ILevelTile>    result = algo.CalculatePath(from, to);

        NUnit.Framework.Assert.IsNull(result);
    }
Exemple #14
0
 private void Awake()
 {
     astar            = GetComponent <AStarAlgorithm>();
     pacmanController = GameObject.FindGameObjectWithTag("Pacman").GetComponent <PacmanMove>();
     pacmanTransform  = GameObject.FindGameObjectWithTag("Pacman").transform;
     gameManager      = FindObjectOfType <GameManager>();
     movementMode     = MovementMode.Waiting;
     blinkyTransform  = GameObject.Find("Blinky").transform;
     animator         = GetComponent <Animator>();
 }
Exemple #15
0
        public void EmptyMaze()
        {
            // Arrange
            var maze     = new List <string>();
            var expected = "\nThe maze provided is empty, please input a valid Maze.\n";

            // Assert
            var actual = AStarAlgorithm.AStarSearch(maze);

            Assert.AreEqual(expected, actual);
        }
Exemple #16
0
        static public void Solve15PuzzleProblem(AStarAlgorithm algorithm, int[] initStates, HeuristicMethod heuristic)
        {
            var results = algorithm.Run(initStates, heuristic);

            Console.WriteLine($"Heuristic method selected: {heuristic}");
            foreach (var item in results)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("End");
        }
Exemple #17
0
        static void Main(string[] args)
        {
            AStarAlgorithm strategy = new AStarAlgorithm();

            int[] states = new int[] { 1, 4, 3, 2, 5, 8, 7, -1, 6 };

            Solve15PuzzleProblem(strategy, states, HeuristicMethod.ManhattanDistance);
            Solve15PuzzleProblem(strategy, states, HeuristicMethod.MisplacedTiles);

            Console.ReadKey();
        }
        private NodePath RunAstar(DefinitionNodeGrid definitionNodeGrid, Point2 gridStart, Point2 gridEnd, out bool succes)
        {
            var aStarAlgorithm = new AStarAlgorithm(definitionNodeGrid.NodeCount, new EuclideanDistance());

            var start = definitionNodeGrid.NodeGrid.ToIndex(gridStart.X, gridStart.Y);
            var end   = definitionNodeGrid.NodeGrid.ToIndex(gridEnd.X, gridEnd.Y);

            var pathfindingNetwork = new AstarNodeNetwork(definitionNodeGrid, new BrushfireClearanceGenerator(definitionNodeGrid, 5));
            var pathRequest        = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), start, end, PathfindaxCollisionCategory.Cat1);

            return(aStarAlgorithm.FindPath(pathfindingNetwork, pathRequest, out succes));
        }
Exemple #19
0
        public void Setup()
        {
            var factory  = new DefinitionNodeGridFactory();
            var nodeGrid = factory.GeneratePreFilledArray(GenerateNodeGridConnections.All, 320, 200);

            _definitionNodeGrid    = new DefinitionNodeGrid(nodeGrid, new Vector2(1, 1));
            _astarNodeNetwork      = new AstarNodeNetwork(_definitionNodeGrid, new BrushfireClearanceGenerator(_definitionNodeGrid, 1));
            _algorithm             = new AStarAlgorithm(_definitionNodeGrid.NodeCount, new ManhattanDistance());
            _longPathRequest       = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), _definitionNodeGrid.NodeGrid.ToIndex(0, 0), _definitionNodeGrid.NodeGrid.ToIndex(319, 199));
            _shortPathRequest      = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), _definitionNodeGrid.NodeGrid.ToIndex(0, 0), _definitionNodeGrid.NodeGrid.ToIndex(20, 20));
            _veryShortPathRequest  = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), _definitionNodeGrid.NodeGrid.ToIndex(0, 0), _definitionNodeGrid.NodeGrid.ToIndex(1, 0));
            _zeroLengthPathRequest = PathRequest.Create(Substitute.For <IPathfinder <IPath> >(), _definitionNodeGrid.NodeGrid.ToIndex(0, 0), _definitionNodeGrid.NodeGrid.ToIndex(0, 0));
        }
        public void SubgraphsSupergraphs(string name, IHeuristic <int, double> heuristic, Graph <int, int, double> graph1, Graph <int, int, double> graph2)
        {
            // Arrange
            var initialNode = new TemporalMatchingNode <int, int, double>(graph1, graph2, heuristic, false);
            var algorithm   = new AStarAlgorithm <TemporalMatchingNode <int, int, double> >(initialNode);

            // Act
            var temporalMatching = algorithm.ExpandRecursively();

            // Assert
            Assert.True(graph1.VertexCount <= graph2.VertexCount);
            Assert.Equal(graph1.VertexCount, -1 * temporalMatching.DistanceFromSource());
        }
Exemple #21
0
        public void FindPath_InitializedNodegrid_PathLengthIsNot0(DefinitionNodeGrid definitionNodeGrid, int x1, int y1, int x2, int y2)
        {
            var aStarAlgorithm = new AStarAlgorithm();

            var start = definitionNodeGrid.NodeGrid[x1, y1];
            var end   = definitionNodeGrid.NodeGrid[x1, y1];

            var pathfindingNetwork = new AstarNodeNetwork(definitionNodeGrid, new GridClearanceGenerator(definitionNodeGrid, 5));
            var pathRequest        = new PathRequest <IPath>(start, end);
            var path = aStarAlgorithm.FindPath(pathfindingNetwork, pathRequest, out var _);

            Assert.AreEqual(path.Path.Length > 0, true);
        }
Exemple #22
0
    // Start is called before the first frame update
    void Start()
    {
        path2D = new int[ROWS, COLS] {
            { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
            { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
            { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
            { 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1 },
            { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0 },
            { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0 },
            { 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1 },
            { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
            { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
            { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
            { 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
            { 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1 },
            { 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1 },
            { 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1 },
            { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
            { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
            { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
            { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
            { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
        };

        transform.position = new Vector3(blinky_start_col, blinky_start_row, 0.0f);

        blinky_move_col = blinky_start_col;
        blinky_move_row = blinky_start_row;

        blinky_current_row = blinky_start_row;
        blinky_current_col = blinky_start_col;

        //temp start destination
        int dest_row = 0;
        int dest_col = 0;

        astar_gen = new AStarAlgorithm();
        astar_gen.aStarSearch(blinky_path, path2D, blinky_start_row, blinky_start_col, dest_row, dest_col);
    }
Exemple #23
0
        public void MazeNoEndPointMaze()
        {
            // Arrange
            var maze = new List <string>()
            {
                "xxxxxxx",
                "xA....x",
                "xxxxxxx"
            };
            var expected = "\nThe maze provided is not valid, please input a valid Maze.\n";

            // Assert
            var actual = AStarAlgorithm.AStarSearch(maze);

            Assert.AreEqual(expected, actual);
        }
Exemple #24
0
        public void ImpossibleMaze()
        {
            // Arrange
            var maze = new List <string>()
            {
                "xxxxxxx",
                "xA.x.Bx",
                "xxxxxxx"
            };
            var expected = "\nThis maze cannot be escaped from...\n";

            // Assert
            var actual = AStarAlgorithm.AStarSearch(maze);

            Assert.AreEqual(expected, actual);
        }
    public void StratPathFindinAlgorithm()
    {
        pathFind.interactable         = false;
        resetCurrentPath.interactable = true;
        clearAll.interactable         = true;
        gridController.PathGridState  = PathGridState.PathFind;
        gridController.InitGraf();
        Vector2Int goalPosition  = new Vector2Int(gridController.GoalPos.x, gridController.GoalPos.y);
        Vector2Int startPosition = new Vector2Int(gridController.StartPos.x, gridController.StartPos.y);

        IHeuristicEstimate heuristic = HeuristicFactory.СreateHeuristic(heuristicType, breakerType, startPosition, float.Parse(heuristicCoeffField.text));
        float          timeDelay     = float.Parse(delayBeforeSteps.text);
        AStarAlgorithm algorithm     = new AStarAlgorithm(gridMarkerController, heuristic, timeDelay);

        pathFindingAlgorithmCoroutine = StartCoroutine(algorithm.FindPath(gridController.GetStartVertex(), gridController.GetGoalVertex()));
    }
        public static void TestAstar(string mesh_type)
        {
            int[] sizes_mesh = new int[21] {
                10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50
            };
            int[] final_positions = new int[21] {
                99, 143, 195, 255, 323, 399, 483, 575, 675, 783, 899, 1023, 1155, 1295, 1443, 1599, 1763, 1935, 2115, 2303, 2499
            };

            for (int i = 0; i < sizes_mesh.Length; i++)
            {
                string size      = "_" + sizes_mesh[i] + "x" + sizes_mesh[i] + ".txt";
                string file_name = mesh_type + size;

                Console.WriteLine("Init Execution -> " + file_name);

                //-------------------------------------------------------------------
                //Create the mesh environment
                MeshEnvironment env = new MeshEnvironment(_start: 0, _final: final_positions[i], _file_name: file_name, sizes_mesh[i]);
                env.InitEnviroment(type_mesh: mesh_type);

                //-------------------------------------------------------------------
                for (int j = 0; j < num_test; j++)
                {
                    AStarAlgorithm as1 = new AStarAlgorithm();
                    as1.Execute(ref env);

                    //Insert the obstacle in a middle zone of the current optimal solution
                    env.FillDistanceMatrix();
                    InsertSeveralObstacle(ref env, num_obstacle: 2, num_routes: 2);
                    env.FillDistanceMatrix();

                    AStarAlgorithm as2 = new AStarAlgorithm();
                    as2.Execute(ref env);

                    ////Store variables in a txt
                    Console.WriteLine("Execution {0} of " + file_name, j);
                    StoreVariable_AStar(mesh_type, ref env, ref as1, ref as2);

                    env.ClearObstacles();
                }


                Console.WriteLine("End Execution -> " + file_name);
                Console.WriteLine("---------------------------------------------");
            }
        }
Exemple #27
0
    public void Navigate(ShipRuntime targetShip, Vector2Int globalStartPos, Vector2Int globalEndPos)
    {
        Init();
        this.targetShip = targetShip;

        if (globalStartPos == globalEndPos)
        {
            StartCoroutine("DelaySearch");
            return;
        }

        nextIndex = 1;

        CellTemplate startCell = targetShip.GetCellByGlobalPos(globalStartPos);
        CellTemplate endCell   = targetShip.GetCellByGlobalPos(globalEndPos);

        // Invalid path supplied
        if (startCell == null || endCell == null || startCell.CellState == 0 || endCell.CellState == 0)
        {
            return;
        }

        ShipPiece startPiece = targetShip.GetPieceByGlobalCellPos(globalStartPos);
        ShipPiece endPiece   = targetShip.GetPieceByGlobalCellPos(globalEndPos);


        NavGrid startGrid = new NavGrid(startPiece);

        startGrid.Generate();

        NavGrid goalGrid = startGrid;

        if (startPiece != endPiece)
        {
            goalGrid = new NavGrid(endPiece);
            goalGrid.Generate();
        }

        AStarAlgorithm aStarAlgorithm = new AStarAlgorithm(startGrid, goalGrid, globalStartPos, globalEndPos);

        int newTTmp = 0;

        curPath = aStarAlgorithm.AStarSearch(ref newTTmp);

        wiggleTimer = Random.Range(0, 6.28318f);
    }
    public void AStarEuclidian_CorrectPathFound_MultipleCorrectPaths()
    {
        IPathFindingAlgorithm algo   = new AStarAlgorithm(graphProvider, new EuclidianHeuristic());
        ILevelTile            from   = graphProvider.GetTileAtPos(new Vector2Int(2, 5));
        ILevelTile            to     = graphProvider.GetTileAtPos(new Vector2Int(0, 1));
        IList <ILevelTile>    result = algo.CalculatePath(from, to);

        NUnit.Framework.Assert.IsTrue(result.Count == 23);

        float pathLength = 0f;

        for (int i = 1; i < result.Count; ++i)
        {
            pathLength += Vector2.Distance(result[i - 1].Pos, result[i].Pos);
        }
        NUnit.Framework.Assert.AreEqual(pathLength, 22f, 0.1f);
    }
Exemple #29
0
        public void TestUseStupidPath()
        {
            Game   game   = new Game();
            Player pacman = game.Player;
            Clyde  clyde  = (Clyde)game.Ghosts[3];

            clyde.SetX(4);
            clyde.SetY(4);
            pacman.SetX(28);
            pacman.SetY(3);
            IPathfindingAlgorithm algorithm = new AStarAlgorithm();
            List <Cell>           path      = algorithm.CalculatePath(clyde.CurrentCell(), pacman.CurrentCell(), game.Level.Map).GetRange(0, 3);

            clyde.UseStupidPath();

            Assert.AreEqual(clyde.ChasePath.Count, 3);
        }
Exemple #30
0
        public void TestUpdateChasePath2()
        {
            Game   game   = new Game();
            Blinky blinky = (Blinky)game.Ghosts[0];
            Player pacman = game.Player;

            pacman.IsPassedLeftTunnel = true;

            blinky.UpdateChasePath();

            IPathfindingAlgorithm algorithm = new AStarAlgorithm();
            List <Cell>           path      = algorithm.CalculatePath(blinky.CurrentCell(), game.Level.Map[0, 15], game.Level.Map);

            Assert.AreEqual(blinky.TargetCell, game.Level.Map[32, 15]);
            Assert.IsFalse(pacman.IsPassedLeftTunnel);
            CollectionAssert.AreEqual(blinky.ChasePath, path);
        }