private void HexSimulation() { var hexMap = _mapFactory.GetHexMap(); _vehicle.CurrentHexCell = new Coordinate2D(0, 0, OffsetTypes.OddRowsRight); var optimalPath = _pathPlanner.GenerateOptimalHexPath(hexMap, _vehicle); var finished = false; var totalMoves = 0; while (!finished) { totalMoves += 1; _simulationResults.HexPath.Add(_vehicle.CurrentHexCell); var detectionCells = DetectionHead.GetCoveredCells(hexMap.Graph, _vehicle.CurrentHexCell, _vehicle.DetectorRadius, _vehicle.TurnRadius); //Check Cells for mine var detection = CheckCells(detectionCells); //mark as cleared hexMap.Graph.SetCellsTerrainType(detectionCells, hexMap.ClearedTerrain); //Handle any detections if (detection) { _reactivePathPlanner.GenerateReactiveHexPath(hexMap, optimalPath, _vehicle.CurrentHexCell); } //If the reactive Planner is not empty, empty it before the optimal. if (_reactivePathPlanner.ReactiveHexPath.TryDequeue(out var next)) { _vehicle.CurrentHexCell = next; } //Else we will work off of the optimal path else { //If the optimal path is empty we are done otherwise pop. if (!optimalPath.TryDequeue(out var nextOptimal)) { finished = true; continue; } if (hexMap.Graph.IsCellBlocked(nextOptimal)) { _reactivePathPlanner.GenerateReactiveHexPath(hexMap, optimalPath, _vehicle.CurrentHexCell); } else { _vehicle.CurrentHexCell = nextOptimal; } } } //Debugging information var(cleared, uncleared) = CoveredCells(); _simulationResults.HexClearedCells = cleared; _simulationResults.HexUnClearedCells = uncleared; _simulationResults.HexTotalMoves = totalMoves; _simulationResults.HexBombsFound = hexBombsFound.Count; _simulationResults.HexMappedBombs = hexBombsFound.ToList(); foreach (var cell in hexMap.Graph.GetAllCells()) { if (cell.TerrainType.Id == hexMap.ClearedTerrain.Id) { _simulationResults.HexCoveredCells.Add(cell.Coordinate3.To2D(hexMap.OffsetType)); } } }