diff --git a/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml b/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml
index 2c926b7..83db942 100644
--- a/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml
+++ b/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml
@@ -20,8 +20,11 @@
+
+
+
@@ -33,18 +36,20 @@
+
+
-
-
-
+
+
+
diff --git a/.idea/.idea.RobotIntelFinal/.idea/workspace.xml b/.idea/.idea.RobotIntelFinal/.idea/workspace.xml
index 0a6ccca..0d747c3 100644
--- a/.idea/.idea.RobotIntelFinal/.idea/workspace.xml
+++ b/.idea/.idea.RobotIntelFinal/.idea/workspace.xml
@@ -18,23 +18,29 @@
-
+
+
+
+
+
-
-
-
-
+
+
+
-
+
-
-
-
+
+
+
+
+
+
@@ -55,47 +61,68 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -173,7 +200,7 @@
-
+
@@ -205,26 +232,39 @@
34
-
+
-
+
file://$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs
- 61
-
+ 87
+
-
+
-
+
-
+
+
+
+ file://$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs
+ 85
+
+
+
+
+
+
+
+
+
diff --git a/ConsoleApp/ConsoleApp.csproj b/ConsoleApp/ConsoleApp.csproj
index 02c0777..6d8ae3b 100644
--- a/ConsoleApp/ConsoleApp.csproj
+++ b/ConsoleApp/ConsoleApp.csproj
@@ -19,7 +19,7 @@
-
+
PreserveNewest
diff --git a/ConsoleApp/CoreModule.cs b/ConsoleApp/CoreModule.cs
index 53e0122..e0e2585 100644
--- a/ConsoleApp/CoreModule.cs
+++ b/ConsoleApp/CoreModule.cs
@@ -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(Reuse.Singleton);
container.Register(Reuse.Singleton);
container.Register(Reuse.Singleton);
+ container.Register(Reuse.Singleton);
}
diff --git a/ConsoleApp/Maps/Cell.cs b/ConsoleApp/Maps/Cell.cs
index a5b5f14..ef9bfd4 100644
--- a/ConsoleApp/Maps/Cell.cs
+++ b/ConsoleApp/Maps/Cell.cs
@@ -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;
}
diff --git a/ConsoleApp/Maps/ICell.cs b/ConsoleApp/Maps/ICell.cs
index 4faabb8..db8db85 100644
--- a/ConsoleApp/Maps/ICell.cs
+++ b/ConsoleApp/Maps/ICell.cs
@@ -4,5 +4,6 @@ namespace ConsoleApp.Maps
{
int X { get; }
int Y { get; }
+ Coverage Coverage { get; set; }
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/IMapFactory.cs b/ConsoleApp/Maps/IMapFactory.cs
index ec72df4..59cd0d3 100644
--- a/ConsoleApp/Maps/IMapFactory.cs
+++ b/ConsoleApp/Maps/IMapFactory.cs
@@ -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();
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/IMineMap.cs b/ConsoleApp/Maps/IMineMap.cs
new file mode 100644
index 0000000..b21ed22
--- /dev/null
+++ b/ConsoleApp/Maps/IMineMap.cs
@@ -0,0 +1,7 @@
+namespace ConsoleApp.Maps
+{
+ public interface IMineMap
+ {
+ bool[,] Map { get; }
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/MapExtensions.cs b/ConsoleApp/Maps/MapExtensions.cs
new file mode 100644
index 0000000..8a046b4
--- /dev/null
+++ b/ConsoleApp/Maps/MapExtensions.cs
@@ -0,0 +1,20 @@
+namespace ConsoleApp.Maps
+{
+ public static class MapExtensions
+ {
+ public static void Fill2DArray(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;
+ }
+ }
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/MapFactory.cs b/ConsoleApp/Maps/MapFactory.cs
index 1866971..a7418dc 100644
--- a/ConsoleApp/Maps/MapFactory.cs
+++ b/ConsoleApp/Maps/MapFactory.cs
@@ -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)
{
diff --git a/ConsoleApp/Maps/MineMap.cs b/ConsoleApp/Maps/MineMap.cs
new file mode 100644
index 0000000..bd2b8b1
--- /dev/null
+++ b/ConsoleApp/Maps/MineMap.cs
@@ -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;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/PathPlanners/IPathPlanner.cs b/ConsoleApp/PathPlanners/IPathPlanner.cs
index a9bfdf7..7c8a4a0 100644
--- a/ConsoleApp/PathPlanners/IPathPlanner.cs
+++ b/ConsoleApp/PathPlanners/IPathPlanner.cs
@@ -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 GenerateOptimalSquarePath(ISquareMap map, IVehicle vehicle);
- Queue GenerateOptimalHexPath(IHexMap hexMap, IVehicle vehicle);
+ Queue GenerateOptimalHexPath(IHexMap hexMap, IVehicle vehicle);
}
}
\ No newline at end of file
diff --git a/ConsoleApp/PathPlanners/IReactivePathPlanner.cs b/ConsoleApp/PathPlanners/IReactivePathPlanner.cs
new file mode 100644
index 0000000..68375a1
--- /dev/null
+++ b/ConsoleApp/PathPlanners/IReactivePathPlanner.cs
@@ -0,0 +1,10 @@
+using System.Collections.Generic;
+using HexCore;
+
+namespace ConsoleApp.PathPlanners
+{
+ public interface IReactivePathPlanner
+ {
+ Queue ReactiveHexPath { get; }
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/PathPlanners/PathPlanner.cs b/ConsoleApp/PathPlanners/PathPlanner.cs
index a88d179..5f50a66 100644
--- a/ConsoleApp/PathPlanners/PathPlanner.cs
+++ b/ConsoleApp/PathPlanners/PathPlanner.cs
@@ -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 GenerateOptimalHexPath(IHexMap hexMap, IVehicle vehicle)
+ public Queue 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();
+ 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(path);
}
}
}
\ No newline at end of file
diff --git a/ConsoleApp/PathPlanners/ReactivePathPlanner.cs b/ConsoleApp/PathPlanners/ReactivePathPlanner.cs
new file mode 100644
index 0000000..a77e9b2
--- /dev/null
+++ b/ConsoleApp/PathPlanners/ReactivePathPlanner.cs
@@ -0,0 +1,20 @@
+using System.Collections.Generic;
+using HexCore;
+
+namespace ConsoleApp.PathPlanners
+{
+ public class ReactivePathPlanner : IReactivePathPlanner
+ {
+ public Queue ReactiveHexPath { get; }
+
+ public ReactivePathPlanner()
+ {
+ ReactiveHexPath = new Queue();
+ }
+
+ public void GenerateReactiveHexPath(Graph graph, ref List optimalPath, Coordinate2D minePosition)
+ {
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/Program.cs b/ConsoleApp/Program.cs
index ca6d342..4cc3a51 100644
--- a/ConsoleApp/Program.cs
+++ b/ConsoleApp/Program.cs
@@ -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();
var simRunner = _bootstrapper.Resolve();
- mapFactory.GenerateMaps(x, y);
+ mapFactory.GenerateMaps(x, y, minePercentage);
simRunner.Run();
}
diff --git a/ConsoleApp/Vehicle/DetectionHead.cs b/ConsoleApp/Sim/DetectionHead.cs
similarity index 71%
rename from ConsoleApp/Vehicle/DetectionHead.cs
rename to ConsoleApp/Sim/DetectionHead.cs
index 3217927..a510d3c 100644
--- a/ConsoleApp/Vehicle/DetectionHead.cs
+++ b/ConsoleApp/Sim/DetectionHead.cs
@@ -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 GetCoveredCells(
+ public static List GetCoveredCells(
Graph graph,
Coordinate2D centerCoordinate,
int detectorRadius,
GlobalDirection direction) => graph.GetRange(centerCoordinate, detectorRadius);
- public List GetCoveredCells(
+ public static List| GetCoveredCells(
ISquareMap squareMap,
Cell centerCell,
int detectorRadius) => squareMap.GetRange(centerCell, detectorRadius);
diff --git a/ConsoleApp/Vehicle/IVehicle.cs b/ConsoleApp/Sim/IVehicle.cs
similarity index 92%
rename from ConsoleApp/Vehicle/IVehicle.cs
rename to ConsoleApp/Sim/IVehicle.cs
index 94fe591..3db6ae0 100644
--- a/ConsoleApp/Vehicle/IVehicle.cs
+++ b/ConsoleApp/Sim/IVehicle.cs
@@ -1,6 +1,6 @@
using ConsoleApp.Maps;
-namespace ConsoleApp.Vehicle
+namespace ConsoleApp.Sim
{
public interface IVehicle
{
diff --git a/ConsoleApp/Vehicle/Vehicle.cs b/ConsoleApp/Sim/Vehicle.cs
similarity index 80%
rename from ConsoleApp/Vehicle/Vehicle.cs
rename to ConsoleApp/Sim/Vehicle.cs
index 3a07573..e4cc62d 100644
--- a/ConsoleApp/Vehicle/Vehicle.cs
+++ b/ConsoleApp/Sim/Vehicle.cs
@@ -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("/Users/brady.bodily/Documents/Repositories/CS5890_Robot_Intelligence/RobotIntelFinal/ConsoleApp/Vehicle/VehicleConfiguration.json");
+ var config = jsonDeserializor.DeserializeObject("/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();
}
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Vehicle/VehicleConfiguration.cs b/ConsoleApp/Sim/VehicleConfiguration.cs
similarity index 88%
rename from ConsoleApp/Vehicle/VehicleConfiguration.cs
rename to ConsoleApp/Sim/VehicleConfiguration.cs
index 42411a5..74c2b50 100644
--- a/ConsoleApp/Vehicle/VehicleConfiguration.cs
+++ b/ConsoleApp/Sim/VehicleConfiguration.cs
@@ -1,4 +1,4 @@
-namespace ConsoleApp.Vehicle
+namespace ConsoleApp.Sim
{
public class VehicleConfiguration
{
diff --git a/ConsoleApp/Sim/VehicleConfiguration.json b/ConsoleApp/Sim/VehicleConfiguration.json
new file mode 100644
index 0000000..adb580b
--- /dev/null
+++ b/ConsoleApp/Sim/VehicleConfiguration.json
@@ -0,0 +1,6 @@
+{
+ "Length": 3,
+ "Width": 2,
+ "DetectorRadius": 3,
+ "DetectorOffset": 2
+}
\ No newline at end of file
diff --git a/ConsoleApp/SimRunner.cs b/ConsoleApp/SimRunner.cs
index 6aad005..be04c2d 100644
--- a/ConsoleApp/SimRunner.cs
+++ b/ConsoleApp/SimRunner.cs
@@ -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;
}
diff --git a/ConsoleApp/UserConsole.cs b/ConsoleApp/UserConsole.cs
index b76ee46..f59b44e 100644
--- a/ConsoleApp/UserConsole.cs
+++ b/ConsoleApp/UserConsole.cs
@@ -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;
+ }
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Vehicle/VehicleConfiguration.json b/ConsoleApp/Vehicle/VehicleConfiguration.json
deleted file mode 100644
index aaa1b9f..0000000
--- a/ConsoleApp/Vehicle/VehicleConfiguration.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "Length": 3,
- "Width": 2,
- "DetectorWidth": 3,
- "DetectorOffset": 1
-}
\ No newline at end of file
| |