Пример #1
0
        public void BlockClick(object sender, RoutedEventArgs e)
        {
            var        block = BlockList.Where(x => x.Block == sender as Button).FirstOrDefault();
            BlockModel findedObj;

            if (block == null)
            {
                return;
            }

            CheckAndRemoveItem(block);

            switch (SelectedMode)
            {
            case NodeType.Passable:
                block.NType = NodeType.Passable;
                break;

            case NodeType.Wall:
                block.NType = NodeType.Wall;
                break;

            case NodeType.Target:

                if (block.NType == NodeType.Target)
                {
                    break;
                }

                findedObj = BlockList.Where(x => x.NType == NodeType.Target).FirstOrDefault();
                if (findedObj != null)
                {
                    block.NType     = findedObj.NType;
                    findedObj.NType = NodeType.Passable;
                    TargetBlock     = block;
                }
                else
                {
                    block.NType = NodeType.Target;
                    TargetBlock = block;
                }

                break;

            case NodeType.Current:

                block.NType = NodeType.Current;
                CurrentBlockList.Add(block);

                break;

            default:
                break;
            }
        }
Пример #2
0
        private async Task <bool> ViewPass(List <Point> pointList, ASpeedModifier modifier)
        {
            if (pointList == null)
            {
                return(false);
            }

            var searchBlock = BlockList.Where((x) =>
            {
                return(ComparePoints(pointList, x.Position));
            });

            foreach (var item in searchBlock)
            {
                modifier.TimePassedForView += modifier.ViewDelayInMilliseconds;
                await Task.Delay(modifier.ViewDelayInMilliseconds);

                item.NType = NodeType.Path;
            }

            return(await Task.FromResult(true));
        }
Пример #3
0
        private async void FindPathButton_Click(object sender, RoutedEventArgs e)
        {
            Point        startPosition  = new Point(-1, -1);
            Point        targetPosition = new Point(-1, -1);
            var          field          = new int[MATRIX_SIZE, MATRIX_SIZE * 2];
            List <Point> wallList       = new List <Point>();

            targetPosition = BlockList.Where(x => x.NType == NodeType.Target).Select(x => x.Position).FirstOrDefault();

            if (targetPosition == null)
            {
                return;
            }

            var searchWall = BlockList.Where(x => x.NType == NodeType.Wall).Select(x => x.Position);

            foreach (var item in searchWall)
            {
                wallList.Add(item);
            }

            int countPaths = CurrentBlockList.Count;

            List <Point>[] PathsList = new List <Point> [countPaths];

            ASpeedModifier speedModifier = new ASpeedModifier()
            {
                SearchDelayInMilliseconds = 10,
                ViewDelayInMilliseconds   = 20
            };

            List <List <Point> > pathListArray = new List <List <Point> >();

            long timeElapseWithDisplay    = 0;
            long timeElapseWithoutDisplay = 0;

            var tasks = CurrentBlockList.Select(async(x) =>
            {
                var watchWithDisplay    = Stopwatch.StartNew();
                var watchWithoutDisplay = Stopwatch.StartNew();

                await aSCore.FindPathWithoutDisplayAsync(field, startPosition, targetPosition, wallList)
                .ContinueWith(t => watchWithoutDisplay.Stop());

                pathListArray.Add(await aSCore.FindPathAsync(field, x.Position, targetPosition, wallList, BlockList, speedModifier));

                watchWithDisplay.Stop();

                timeElapseWithDisplay    += watchWithDisplay.ElapsedMilliseconds;
                timeElapseWithoutDisplay += watchWithoutDisplay.ElapsedMilliseconds;
            });

            await Task.WhenAll(tasks);

            //Тест
            BlockList.ForEach((x) =>
            {
                if (x.NType == NodeType.SearchPath)
                {
                    x.NType = NodeType.Passable;
                }
            });

            pathListArray.ForEach(async x => await ViewPass(x, speedModifier));

            elapsedTimeLabel.Content = " Скорость: " + Math.Round((double)timeElapseWithoutDisplay / timeElapseWithDisplay, 4)
                                       + " Всего: " + timeElapseWithDisplay
                                       + " мс. | Всего за поиск: " + timeElapseWithoutDisplay
                                       + " мс.";
        }