コード例 #1
0
        private void StartPathFinder()
        {
            try
            {
                _stepsEstimate = Math.Abs(_stopPoint.Y - _startPoint.Y) + Math.Abs(_stopPoint.X - _startPoint.X);

                ICellPathFinder pathFinder = _currentPathFinder;
                pathFinder.OnCellViewedEvent += OnCellViewed;

                _viewedCellsTable.Add(pathFinder, 0);

                IList <Vector2Int> path =
                    pathFinder.GetPath(_cellMap, _startPoint, _stopPoint, NeighbourMode.SidesAndDiagonals);
                if (path == null)
                {
                    MessageBox.Show("Path not found!", "Path finder", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    DrawPath(path);
                }

                SetViewedCellsCount((int)_viewedCellsTable[pathFinder]);
                _viewedCellsTable.Remove(pathFinder);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Debug.WriteLine(ex.StackTrace);
                throw;
            }

            SetUiEnabled(true);
        }
コード例 #2
0
        private void InitHpaStar()
        {
            _pathFinder = new CellPathFinderFactory(CellPathFinderAlgorithms.HpaStarAlgorithm);

            SetUiActive(false);

            _backgroundTask = new Task(PreBuildGraphJob, TaskCreationOptions.LongRunning);
            _backgroundTask.Start();
        }
コード例 #3
0
        public CellPathFinderFactory(CellPathFinderAlgorithms algorithm)
        {
            switch (algorithm)
            {
            case CellPathFinderAlgorithms.LeeAlgorithm:
                _instance = new LeeAlgorithm();
                break;

            case CellPathFinderAlgorithms.BestFirstSearchAlgorithm:
                _instance = new BestFirstSearch();
                break;

            case CellPathFinderAlgorithms.AStarAlgorithm:
                _instance = new AStarAlgorithm();
                break;

            case CellPathFinderAlgorithms.HpaStarAlgorithm:
                _instance = new HpaStarAlgorithm();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(algorithm), algorithm, null);
            }
        }
コード例 #4
0
 private void AlgorithmSelectorBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     _currentPathFinder = InstantiatePathFinder();
 }