I think its done
This commit is contained in:
@@ -1,16 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ConsoleApp.Maps;
|
||||
using ConsoleApp.PathPlanners;
|
||||
using ConsoleApp.Sim;
|
||||
using HexCore;
|
||||
using ImTools;
|
||||
using Microsoft.VisualBasic;
|
||||
|
||||
namespace ConsoleApp
|
||||
{
|
||||
@@ -23,8 +17,9 @@ namespace ConsoleApp
|
||||
private IMineMap _mineMap;
|
||||
private IReactivePathPlanner _reactivePathPlanner;
|
||||
private HashSet<Coordinate2D> hexBombsFound = new HashSet<Coordinate2D>();
|
||||
private List<Coordinate2D> testingPath = new List<Coordinate2D>();
|
||||
private ISimulationResults _simulationResults;
|
||||
private HashSet<ICell> squareBombsFound = new HashSet<ICell>();
|
||||
|
||||
|
||||
|
||||
public SimRunner(IMapFactory mapFactory, IVehicle vehicle, IPathPlanner pathPlanner, IReactivePathPlanner reactivePathPlanner, ISimulationResults simulationResults)
|
||||
@@ -47,6 +42,8 @@ namespace ConsoleApp
|
||||
|
||||
}
|
||||
|
||||
#region HexSimulation
|
||||
|
||||
private void HexSimulation()
|
||||
{
|
||||
var hexMap = _mapFactory.GetHexMap();
|
||||
@@ -80,7 +77,7 @@ namespace ConsoleApp
|
||||
if (!optimalPath.TryDequeue(out var nextOptimal))
|
||||
{
|
||||
finished = true;
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hexMap.Graph.IsCellBlocked(nextOptimal))
|
||||
@@ -99,6 +96,13 @@ namespace ConsoleApp
|
||||
_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));
|
||||
}
|
||||
}
|
||||
|
||||
private (int, int) CoveredCells()
|
||||
@@ -137,14 +141,113 @@ namespace ConsoleApp
|
||||
hexMap.Graph.BlockCells(cellsToBlock);
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region SquareSimulation
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private (int, int) CoveredSquareCells()
|
||||
{
|
||||
var cleared = 0;
|
||||
var uncleared = 0;
|
||||
var map = _mapFactory.GetSquareMap();
|
||||
foreach (var cellState in map.Map)
|
||||
{
|
||||
switch (cellState.Coverage)
|
||||
{
|
||||
case Coverage.Covered:
|
||||
cleared++;
|
||||
break;
|
||||
case Coverage.Uncovered:
|
||||
uncleared++;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
return (cleared, uncleared);
|
||||
}
|
||||
|
||||
private bool CheckForMines(List<Cell> detector)
|
||||
{
|
||||
var found = false;
|
||||
foreach (var cell in detector.Where(cell => _mineMap.GetCell(cell.X, cell.Y)))
|
||||
{
|
||||
if(!squareBombsFound.Add(cell)) continue;
|
||||
found = true;
|
||||
BlockSquareCells(cell);
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
private void BlockSquareCells(Cell cell)
|
||||
{
|
||||
var map = _mapFactory.GetSquareMap();
|
||||
var cellsToBlock = map.GetRange(cell, _vehicle.DetectorRadius);
|
||||
foreach (var blockCell in cellsToBlock)
|
||||
{
|
||||
blockCell.Blocked = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user