Created Mine Map and ReactivePlanner

This commit is contained in:
2020-12-15 18:19:07 -07:00
parent 45eca3b572
commit 4edcef4664
24 changed files with 309 additions and 84 deletions

View File

@@ -20,8 +20,11 @@
<e p="ICell.cs" t="Include" />
<e p="IHexMap.cs" t="Include" />
<e p="IMapFactory.cs" t="Include" />
<e p="IMineMap.cs" t="Include" />
<e p="ISquareMap.cs" t="Include" />
<e p="MapExtensions.cs" t="Include" />
<e p="MapFactory.cs" t="Include" />
<e p="MineMap.cs" t="Include" />
<e p="SquareMap.cs" t="Include" />
</e>
<e p="obj" t="ExcludeRecursive">
@@ -33,18 +36,20 @@
</e>
<e p="PathPlanners" t="Include">
<e p="IPathPlanner.cs" t="Include" />
<e p="IReactivePathPlanner.cs" t="Include" />
<e p="PathPlanner.cs" t="Include" />
<e p="ReactivePathPlanner.cs" t="Include" />
</e>
<e p="Program.cs" t="Include" />
<e p="SimRunner.cs" t="Include" />
<e p="UserConsole.cs" t="Include" />
<e p="Vehicle" t="Include">
<e p="Sim" t="Include">
<e p="DetectionHead.cs" t="Include" />
<e p="IVehicle.cs" t="Include" />
<e p="Vehicle.cs" t="Include" />
<e p="VehicleConfiguration.cs" t="Include" />
<e p="VehicleConfiguration.json" t="Include" />
</e>
<e p="SimRunner.cs" t="Include" />
<e p="UserConsole.cs" t="Include" />
</e>
<e p="packages" t="ExcludeRecursive" />
<e p="RobotIntelFinal.sln" t="IncludeFlat" />

View File

@@ -18,23 +18,29 @@
</component>
<component name="ChangeListManager">
<list default="true" id="dafcaeb7-80aa-43a3-a480-786fafb78c0b" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/ConsoleApp/Vehicle/DetectionHead.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/ConsoleApp/Maps/IMineMap.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/ConsoleApp/Maps/MapExtensions.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/ConsoleApp/Maps/MineMap.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/ConsoleApp/PathPlanners/IReactivePathPlanner.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/ConsoleApp/PathPlanners/ReactivePathPlanner.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.RobotIntelFinal/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.RobotIntelFinal/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/ConsoleApp.csproj" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/ConsoleApp.csproj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/CoreModule.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/CoreModule.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/IVehicle.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Vehicle/IVehicle.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/HexMap.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/HexMap.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/IHexMap.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/IHexMap.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/ISquareMap.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/ISquareMap.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/Cell.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/Cell.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/ICell.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/ICell.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/IMapFactory.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/IMapFactory.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/MapFactory.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/MapFactory.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Maps/SquareMap.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Maps/SquareMap.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/PathPlanners/IPathPlanner.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/PathPlanners/IPathPlanner.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Program.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Program.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/SimRunner.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/SimRunner.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Vehicle.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Vehicle/Vehicle.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/VehicleConfiguration.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Vehicle/VehicleConfiguration.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/VehicleConfiguration.json" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Vehicle/VehicleConfiguration.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/UserConsole.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/UserConsole.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Vehicle/DetectionHead.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Sim/DetectionHead.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Vehicle/IVehicle.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Sim/IVehicle.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Vehicle/Vehicle.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Sim/Vehicle.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Vehicle/VehicleConfiguration.cs" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Sim/VehicleConfiguration.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ConsoleApp/Vehicle/VehicleConfiguration.json" beforeDir="false" afterPath="$PROJECT_DIR$/ConsoleApp/Sim/VehicleConfiguration.json" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -55,47 +61,68 @@
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/DecompilerCache/decompiler/EE5CA5D4-EDEB-48AE-9C0D-FE354330FB77/0b/0953c23b/GraphFactory.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///Dummy.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///Dummy.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///Dummy.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/DecompilerCache/decompiler/EE5CA5D4-EDEB-48AE-9C0D-FE354330FB77/f7/268fdeac/Graph.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///Dummy.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/DecompilerCache/decompiler/EE5CA5D4-EDEB-48AE-9C0D-FE354330FB77/84/4eb9c798/GraphUtils.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/SourcesCache/8B2EA1A3-95EB-49F7-AF97-CA55CE776F10/4/Container.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///Dummy.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///Dummy.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/SourcesCache/EB067793-5C3F-4219-AEF1-3AB117C20649/39B/EqualityComparer.CoreCLR.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/SourcesCache/EB067793-5C3F-4219-AEF1-3AB117C20649/11/Array.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///Dummy.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/SourcesCache/EB067793-5C3F-4219-AEF1-3AB117C20649/3A4/List.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///Dummy.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///Dummy.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/SourcesCache/7AFCB195-1BDF-4087-9F2D-5BFCFC407B2B/30/Where.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/SourcesCache/8B2EA1A3-95EB-49F7-AF97-CA55CE776F10/4/Container.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/SourcesCache/EB067793-5C3F-4219-AEF1-3AB117C20649/389/Comparer.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///Dummy.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///Dummy.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///Dummy.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/DecompilerCache/decompiler/EE5CA5D4-EDEB-48AE-9C0D-FE354330FB77/3d/c367b191/Coordinate3D.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///Dummy.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///Dummy.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///Dummy.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/DecompilerCache/decompiler/EE5CA5D4-EDEB-48AE-9C0D-FE354330FB77/14/12025305/MovementTypes.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///Dummy.cs" root0="SKIP_HIGHLIGHTING" />
</component>
<component name="IdeDocumentHistory">
<changedPaths>
<option value="$PROJECT_DIR$/ConsoleApp/Maps/Heading.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/Direction.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/CoreModule.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/IPathPlanner.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/PathPlanner.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/GlobalDirection.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/HexCoordinates.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/Cell.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/ICell.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/MapFactory.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/IMapFactory.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/IVehicle.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/IMap.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/UserConsole.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Program.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Vehicle.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/SimRunner.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/PathPlanners/IPathPlanner.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/IHexMap.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/HexMap.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/SquareMap.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/ISquareMap.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Vehicle/DetectionHead.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Vehicle/Vehicle.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Vehicle/VehicleConfiguration.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Vehicle/IVehicle.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Sim/DetectionHead.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/Cell.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/ICell.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/PathPlanners/IPathPlanner.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/ConsoleApp.csproj" />
<option value="$PROJECT_DIR$/ConsoleApp/Sim/Vehicle.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Sim/VehicleConfiguration.json" />
<option value="$PROJECT_DIR$/ConsoleApp/CoreModule.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/UserConsole.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Program.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/CellExtensions.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/MapExtensions.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/SquareMap.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/MineMap.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/IMineMap.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/MapFactory.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/Maps/IMapFactory.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/SimRunner.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/PathPlanners/IReactivePathPlanner.cs" />
<option value="$PROJECT_DIR$/ConsoleApp/PathPlanners/ReactivePathPlanner.cs" />
</changedPaths>
</component>
<component name="ProjectId" id="1lIZ7IfsUjzqV2Jb1obOFvGFAfp" />
@@ -173,7 +200,7 @@
<workItem from="1607982179018" duration="634000" />
<workItem from="1607983288378" duration="86000" />
<workItem from="1607983862958" duration="7777000" />
<workItem from="1607993290571" duration="28469000" />
<workItem from="1607993290571" duration="36241000" />
</task>
<servers />
</component>
@@ -205,26 +232,39 @@
<line>34</line>
<properties documentPath="$PROJECT_DIR$/ConsoleApp/PathPlanner.cs" initialLine="34" containingFunctionPresentation="method 'GenerateOptimalSquarePath'">
<startOffsets>
<option value="1512" />
<option value="1527" />
</startOffsets>
<endOffsets>
<option value="1528" />
<option value="1543" />
</endOffsets>
</properties>
<option name="timeStamp" value="24" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DotNet Breakpoints">
<url>file://$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs</url>
<line>61</line>
<properties documentPath="$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs" initialLine="62" containingFunctionPresentation="method 'GenerateOptimalHexPath'">
<line>87</line>
<properties documentPath="$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs" initialLine="87" containingFunctionPresentation="method 'GenerateOptimalHexPath'">
<startOffsets>
<option value="2509" />
<option value="3651" />
</startOffsets>
<endOffsets>
<option value="2530" />
<option value="3667" />
</endOffsets>
</properties>
<option name="timeStamp" value="34" />
<option name="timeStamp" value="44" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DotNet Breakpoints">
<url>file://$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs</url>
<line>85</line>
<properties documentPath="$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs" initialLine="85" containingFunctionPresentation="method 'GenerateOptimalHexPath'">
<startOffsets>
<option value="3546" />
</startOffsets>
<endOffsets>
<option value="3612" />
</endOffsets>
</properties>
<option name="timeStamp" value="46" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>

View File

@@ -19,7 +19,7 @@
</ItemGroup>
<ItemGroup>
<None Update="Vehicle\VehicleConfiguration.json">
<None Update="Sim\VehicleConfiguration.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

View File

@@ -1,7 +1,6 @@
using System.Text.Json;
using System.Threading;
using ConsoleApp.Maps;
using ConsoleApp.PathPlanners;
using ConsoleApp.Sim;
using DryIoc;
namespace ConsoleApp
@@ -15,6 +14,7 @@ namespace ConsoleApp
container.Register<IVehicle, Vehicle>(Reuse.Singleton);
container.Register<IJsonDeserializor, JsonDeserializor>(Reuse.Singleton);
container.Register<IPathPlanner, PathPlanner>(Reuse.Singleton);
container.Register<IReactivePathPlanner, ReactivePathPlanner>(Reuse.Singleton);
}

View File

@@ -2,16 +2,22 @@ using System;
namespace ConsoleApp.Maps
{
public enum Coverage
{
Uncoverd,
Covered
}
public struct Cell : ICell
{
public int X { get; }
public int Y { get; }
public Coverage Coverage { get; set; }
public Cell(int x, int y)
{
X = x;
Y = y;
Coverage = Coverage.Uncoverd;
}

View File

@@ -4,5 +4,6 @@ namespace ConsoleApp.Maps
{
int X { get; }
int Y { get; }
Coverage Coverage { get; set; }
}
}

View File

@@ -8,8 +8,9 @@ namespace ConsoleApp.Maps
int Height { get; }
int Width { get; }
int CellWidth { get; }
void GenerateMaps(int x, int y);
void GenerateMaps(int x, int y, double minePercentage);
IHexMap GetHexMap();
ISquareMap GetSquareMap();
IMineMap GetMineMap();
}
}

View File

@@ -0,0 +1,7 @@
namespace ConsoleApp.Maps
{
public interface IMineMap
{
bool[,] Map { get; }
}
}

View File

@@ -0,0 +1,20 @@
namespace ConsoleApp.Maps
{
public static class MapExtensions
{
public static void Fill2DArray<T>(this T[,] arr, T value)
{
int numRows = arr.GetLength(0);
int numCols = arr.GetLength(1);
for (int i = 0; i < numRows; ++i)
{
for (int j = 0; j < numCols; ++j)
{
arr[i, j] = value;
}
}
}
}
}

View File

@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using ConsoleApp.Vehicle;
using ConsoleApp.Sim;
namespace ConsoleApp.Maps
{
@@ -17,16 +17,20 @@ namespace ConsoleApp.Maps
private ISquareMap _squareMap;
private IHexMap _hexMap;
private IMineMap _mineMap;
public void GenerateMaps(int x, int y)
public void GenerateMaps(int x, int y, double minePercentage)
{
Width = x;
Height = y;
_squareMap = new SquareMap(x, y);
_hexMap = new HexMap(x, y);
_mineMap = new MineMap(x, y, minePercentage);
}
public IHexMap GetHexMap() => _hexMap ?? throw new NullReferenceException("hex map not initialized");
public ISquareMap GetSquareMap() => _squareMap ?? throw new NullReferenceException("square map not initialized");
public IMineMap GetMineMap() => _mineMap ?? throw new NullReferenceException("mine map not initialized");
public MapFactory(IVehicle vehicle)
{

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
namespace ConsoleApp.Maps
{
public class MineMap : IMineMap
{
private int _mineCount;
private int _x;
private int _y;
public bool[,] Map { get; }
public MineMap(int x, int y, double minePercentage)
{
_x = x;
_y = y;
_mineCount = x*y*((int)minePercentage/100);
Map = new bool[x, y];
Map.Fill2DArray(false);
PlaceMines();
}
private void PlaceMines()
{
var rand = new Random();
for (int i = 0; i < _mineCount; i++)
{
var x = rand.Next(_x);
var y = rand.Next(_y);
Map[x, y] = true;
}
}
}
}

View File

@@ -1,13 +1,14 @@
using System.Collections.Generic;
using ConsoleApp.Maps;
using ConsoleApp.Vehicle;
using ConsoleApp.Sim;
using HexCore;
namespace ConsoleApp.PathPlanners
{
public interface IPathPlanner
{
Queue<ICell> GenerateOptimalSquarePath(ISquareMap map, IVehicle vehicle);
Queue<ICell> GenerateOptimalHexPath(IHexMap hexMap, IVehicle vehicle);
Queue<Coordinate2D> GenerateOptimalHexPath(IHexMap hexMap, IVehicle vehicle);
}
}

View File

@@ -0,0 +1,10 @@
using System.Collections.Generic;
using HexCore;
namespace ConsoleApp.PathPlanners
{
public interface IReactivePathPlanner
{
Queue<Coordinate2D> ReactiveHexPath { get; }
}
}

View File

@@ -1,7 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ConsoleApp.Maps;
using ConsoleApp.Vehicle;
using ConsoleApp.Sim;
using HexCore;
namespace ConsoleApp.PathPlanners
@@ -55,12 +56,76 @@ namespace ConsoleApp.PathPlanners
return path;
}
public Queue<ICell> GenerateOptimalHexPath(IHexMap hexMap, IVehicle vehicle)
public Queue<Coordinate2D> GenerateOptimalHexPath(IHexMap hexMap, IVehicle vehicle)
{
// var t = hexMap.Graph.GetMovementRange(
// new Coordinate2D(0, 0, hexMap.OffsetType), 2, hexMap.DefaultMovement);
// Console.WriteLine(t);
throw new NotImplementedException();
var currentPostion = vehicle.CurrentHexCell;
var currentHeading = GlobalDirection.East;
var finished = false;
var path = new List<Coordinate2D>();
while (!finished)
{
if (currentHeading == GlobalDirection.East)
{
path.AddRange(hexMap.Graph.GetShortestPath(
currentPostion,
new Coordinate2D(hexMap.Width, currentPostion.Y, hexMap.OffsetType),
hexMap.DefaultMovement));
currentPostion = new Coordinate2D(hexMap.Width, currentPostion.Y, hexMap.OffsetType);
}
else if(currentHeading == GlobalDirection.West)
{
path.AddRange(hexMap.Graph.GetShortestPath(
currentPostion,
new Coordinate2D(0, currentPostion.Y, hexMap.OffsetType),
hexMap.DefaultMovement));
currentPostion = new Coordinate2D(0, currentPostion.Y, hexMap.OffsetType);
}
if (currentPostion.Y + vehicle.DetectorRadius * 2 > hexMap.Height)
{
finished = true;
break;
}
Coordinate2D tmpPosition;
if(currentHeading == GlobalDirection.East)
tmpPosition = new Coordinate3D(
currentPostion.To3D().X-1,
currentPostion.To3D().Y,
currentPostion.To3D().Z+1).To2D(hexMap.OffsetType);
else
tmpPosition = new Coordinate3D(
currentPostion.To3D().X,
currentPostion.To3D().Y-1,
currentPostion.To3D().Z+1).To2D(hexMap.OffsetType);
while (hexMap.Graph.GetRange(currentPostion, vehicle.DetectorRadius*2).Contains(tmpPosition))
{
if(currentHeading == GlobalDirection.East)
tmpPosition = new Coordinate3D(
tmpPosition.To3D().X-1,
tmpPosition.To3D().Y,
tmpPosition.To3D().Z+1).To2D(hexMap.OffsetType);
else
tmpPosition = new Coordinate3D(
tmpPosition.To3D().X,
tmpPosition.To3D().Y-1,
tmpPosition.To3D().Z+1).To2D(hexMap.OffsetType);
}
path.AddRange(hexMap.Graph.GetShortestPath(
currentPostion,
tmpPosition,
hexMap.DefaultMovement));
currentPostion = tmpPosition;
if (currentHeading == GlobalDirection.East)
currentHeading = GlobalDirection.West;
else
currentHeading = GlobalDirection.East;
}
return new Queue<Coordinate2D>(path);
}
}
}

View File

@@ -0,0 +1,20 @@
using System.Collections.Generic;
using HexCore;
namespace ConsoleApp.PathPlanners
{
public class ReactivePathPlanner : IReactivePathPlanner
{
public Queue<Coordinate2D> ReactiveHexPath { get; }
public ReactivePathPlanner()
{
ReactiveHexPath = new Queue<Coordinate2D>();
}
public void GenerateReactiveHexPath(Graph graph, ref List<Coordinate3D> optimalPath, Coordinate2D minePosition)
{
}
}
}

View File

@@ -19,25 +19,26 @@ namespace ConsoleApp
private static void Initialization()
{
_userConsole.PrintStartMenu();
var input = _userConsole.GetUserInput();
var input = UserConsole.GetUserInput();
if (input == "1")
{
var (x,y) = _userConsole.GetMapDimensions();
RunSimulation(x, y);
var minePercentage = UserConsole.GetMinePercentage();
RunSimulation(x, y, minePercentage);
}
else
{
_userConsole.PrintInvalidInput();
UserConsole.PrintInvalidInput();
Initialization();
}
}
private static void RunSimulation(int x,int y)
private static void RunSimulation(int x, int y, double minePercentage)
{
var mapFactory = _bootstrapper.Resolve<IMapFactory>();
var simRunner = _bootstrapper.Resolve<ISimRunner>();
mapFactory.GenerateMaps(x, y);
mapFactory.GenerateMaps(x, y, minePercentage);
simRunner.Run();
}

View File

@@ -2,17 +2,17 @@ using System.Collections.Generic;
using ConsoleApp.Maps;
using HexCore;
namespace ConsoleApp.Vehicle
namespace ConsoleApp.Sim
{
public class DetectionHead
public static class DetectionHead
{
public List<Coordinate2D> GetCoveredCells(
public static List<Coordinate2D> GetCoveredCells(
Graph graph,
Coordinate2D centerCoordinate,
int detectorRadius,
GlobalDirection direction) => graph.GetRange(centerCoordinate, detectorRadius);
public List<Cell> GetCoveredCells(
public static List<Cell> GetCoveredCells(
ISquareMap squareMap,
Cell centerCell,
int detectorRadius) => squareMap.GetRange(centerCell, detectorRadius);

View File

@@ -1,6 +1,6 @@
using ConsoleApp.Maps;
namespace ConsoleApp.Vehicle
namespace ConsoleApp.Sim
{
public interface IVehicle
{

View File

@@ -1,6 +1,6 @@
using ConsoleApp.Maps;
namespace ConsoleApp.Vehicle
namespace ConsoleApp.Sim
{
public class Vehicle : IVehicle
{
@@ -13,20 +13,19 @@ namespace ConsoleApp.Vehicle
public Heading HexHeading { get; set; }
public Heading SquareHeading { get; set; }
public ICell CurrentSquareCell { get; set; }
public DetectionHead DetectionHead { get; }
public Vehicle(IJsonDeserializor jsonDeserializor)
{
var config = jsonDeserializor.DeserializeObject<VehicleConfiguration>("/Users/brady.bodily/Documents/Repositories/CS5890_Robot_Intelligence/RobotIntelFinal/ConsoleApp/Vehicle/VehicleConfiguration.json");
var config = jsonDeserializor.DeserializeObject<VehicleConfiguration>("/Users/brady.bodily/Documents/Repositories/CS5890_Robot_Intelligence/RobotIntelFinal/ConsoleApp/Sim/VehicleConfiguration.json");
Length = config.Length;
Width = config.Width;
DetectorRadius = config.DetectorRadius;
DetectorOffset = config.DetectorOffset;
CurrentHexCell = default;
CurrentSquareCell = default;
DetectionHead = new DetectionHead();
}
}
}

View File

@@ -1,4 +1,4 @@
namespace ConsoleApp.Vehicle
namespace ConsoleApp.Sim
{
public class VehicleConfiguration
{

View File

@@ -0,0 +1,6 @@
{
"Length": 3,
"Width": 2,
"DetectorRadius": 3,
"DetectorOffset": 2
}

View File

@@ -4,7 +4,7 @@ using System.Threading;
using System.Threading.Tasks;
using ConsoleApp.Maps;
using ConsoleApp.PathPlanners;
using ConsoleApp.Vehicle;
using ConsoleApp.Sim;
using HexCore;
namespace ConsoleApp
@@ -16,20 +16,23 @@ namespace ConsoleApp
private int _cellWidth;
private IPathPlanner _pathPlanner;
private IMineMap _mineMap;
private IReactivePathPlanner _reactivePathPlanner;
public SimRunner(IMapFactory mapFactory, IVehicle vehicle, IPathPlanner pathPlanner)
public SimRunner(IMapFactory mapFactory, IVehicle vehicle, IPathPlanner pathPlanner, IReactivePathPlanner reactivePathPlanner)
{
_cellWidth = mapFactory.CellWidth;
_mapFactory = mapFactory;
_vehicle = vehicle;
_pathPlanner = pathPlanner;
_reactivePathPlanner = reactivePathPlanner;
}
public void Run()
{
_mineMap = _mapFactory.GetMineMap();
SquareSimulation();
HexSimulation();
// while(!squareTask.IsCompleted && !hexTask.IsCompleted){Thread.Sleep(500);}
@@ -41,6 +44,7 @@ namespace ConsoleApp
var hexMap = _mapFactory.GetHexMap();
_vehicle.CurrentHexCell = new Coordinate2D(0, 0, OffsetTypes.OddRowsRight);
var optimalPath = _pathPlanner.GenerateOptimalHexPath(hexMap, _vehicle);
var reactivePath = _reactivePathPlanner.ReactiveHexPath;
}

View File

@@ -18,14 +18,11 @@ namespace ConsoleApp
$"\t 2: Load custom map. \n");
}
public string GetUserInput() => Console.ReadLine();
public static string GetUserInput() => Console.ReadLine();
public void PrintInvalidInput()
{
Console.WriteLine($"Invalid input try again \n");
}
public static void PrintInvalidInput() => Console.WriteLine($"Invalid input try again \n");
public (int width, int height) GetMapDimensions()
public (int width, int height) GetMapDimensions()
{
Console.WriteLine($"Enter map height: ");
var x = GetUserInput();
@@ -38,12 +35,23 @@ namespace ConsoleApp
Console.WriteLine($"Enter map height: ");
var y = GetUserInput();
if(!int.TryParse(y, out var height))
{
PrintInvalidInput();
GetMapDimensions();
}
if (int.TryParse(y, out var height)) return (width, height);
PrintInvalidInput();
GetMapDimensions();
return (width, height);
}
public static double GetMinePercentage()
{
Console.WriteLine($"Enter desired percentage of mines: ");
var x = GetUserInput();
if (double.TryParse(x, out var percent)) return percent;
PrintInvalidInput();
GetMinePercentage();
return percent;
}
}
}

View File

@@ -1,6 +0,0 @@
{
"Length": 3,
"Width": 2,
"DetectorWidth": 3,
"DetectorOffset": 1
}