Esempio n. 1
0
        private void SquareSimulation()
        {
            var squareMap = _mapFactory.GetSquareMap();

            _vehicle.CurrentSquareCell = squareMap.StartingCell;
            var optimalPath = _pathPlanner.GenerateOptimalSquarePath(squareMap, _vehicle);
            var finished    = false;

            while (!finished)
            {
                _simulationResults.SquareTotalMoves++;
                _simulationResults.SquarePath.Add(_vehicle.CurrentSquareCell);
                var detector  = squareMap.GetRange(_vehicle.CurrentSquareCell, _vehicle.DetectorRadius);
                var detection = CheckForMines(detector);
                //Mark cells as covered.
                foreach (var cell in detector)
                {
                    cell.Coverage = Coverage.Covered;
                }
                if (detection)
                {
                    _reactivePathPlanner.GenerateReactiveSquarePath(squareMap, optimalPath, _vehicle.CurrentSquareCell);
                }
                if (_reactivePathPlanner.ReactiveSquarePath.TryDequeue(out var next))
                {
                    _vehicle.CurrentSquareCell = (Cell)next;
                }
                else
                {
                    if (!optimalPath.TryDequeue(out var current))
                    {
                        finished = true;
                        continue;
                    }

                    if (current.Blocked)
                    {
                        _reactivePathPlanner.GenerateReactiveSquarePath(squareMap, optimalPath, current);
                    }
                    else
                    {
                        _vehicle.CurrentSquareCell = (Cell)current;
                    }
                }
            }

            //Debugging information
            var(cleared, uncleared) = CoveredSquareCells();
            _simulationResults.SquareCellsCleared   = cleared;
            _simulationResults.SquareCellsUncleared = uncleared;
            _simulationResults.SquareBombsFound     = squareBombsFound.Count;
            _simulationResults.SquareMappedBombs    = squareBombsFound.ToList();

            foreach (var cell in squareMap.Map)
            {
                if (cell.Coverage == Coverage.Covered)
                {
                    _simulationResults.SquareCoveredCells.Add(cell);
                }
            }
        }