diff --git a/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml b/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml
index 83db942..94ec944 100644
--- a/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml
+++ b/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml
@@ -34,12 +34,19 @@
+
+
+
+
+
+
+
diff --git a/.idea/.idea.RobotIntelFinal/.idea/workspace.xml b/.idea/.idea.RobotIntelFinal/.idea/workspace.xml
index 0d747c3..8de59d7 100644
--- a/.idea/.idea.RobotIntelFinal/.idea/workspace.xml
+++ b/.idea/.idea.RobotIntelFinal/.idea/workspace.xml
@@ -18,29 +18,29 @@
-
-
-
-
-
+
-
-
-
+
+
+
+
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
@@ -58,31 +58,56 @@
-
+
-
-
+
-
-
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -95,34 +120,37 @@
-
-
-
-
-
-
-
-
+
+
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
@@ -140,7 +168,7 @@
-
+
@@ -200,7 +228,7 @@
-
+
@@ -240,33 +268,18 @@
-
- file://$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs
- 87
-
-
-
-
-
-
-
-
-
-
-
- file://$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs
- 85
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ConsoleApp/ConsoleApp.csproj b/ConsoleApp/ConsoleApp.csproj
index 6d8ae3b..3bc0189 100644
--- a/ConsoleApp/ConsoleApp.csproj
+++ b/ConsoleApp/ConsoleApp.csproj
@@ -22,6 +22,13 @@
PreserveNewest
+
+ PreserveNewest
+
+
+
+
+
diff --git a/ConsoleApp/Maps/HexMap.cs b/ConsoleApp/Maps/HexMap.cs
index bbb7b51..ffe61a4 100644
--- a/ConsoleApp/Maps/HexMap.cs
+++ b/ConsoleApp/Maps/HexMap.cs
@@ -17,6 +17,9 @@ namespace ConsoleApp.Maps
public OffsetTypes OffsetType { get; }
public MovementType DefaultMovement { get; }
+ public TerrainType ClearedTerrain { get; }
+
+ public TerrainType UnclearedTerrain { get; }
///
@@ -28,35 +31,28 @@ namespace ConsoleApp.Maps
{
//Set Offset Type for 2d -> 3d conversion
OffsetType = OffsetTypes.OddRowsRight;
- //convert to cm
- x *= 100;
- y *= 100;
-
- //calculate number of cells on x and y axis
- var xCellCount = (int)Math.Ceiling((decimal) (x) / 25);
- var yCellCount = (int)Math.Ceiling((decimal) (y) / 25);
- Height = yCellCount;
- Width = xCellCount;
+ Height = y;
+ Width = x;
- var unclearedTerrain = new TerrainType(1, "uncleared");
- var clearedTerrain = new TerrainType(2, "cleared");
+ UnclearedTerrain = new TerrainType(1, "uncleared");
+ ClearedTerrain = new TerrainType(2, "cleared");
DefaultMovement = new MovementType(1, "default");
var movementTypes = new MovementTypes(
- new ITerrainType[] { unclearedTerrain, clearedTerrain },
+ new ITerrainType[] { UnclearedTerrain, ClearedTerrain },
new Dictionary>
{
[DefaultMovement] = new Dictionary
{
- [unclearedTerrain] = 1,
- [clearedTerrain] = 2
+ [UnclearedTerrain] = 1,
+ [ClearedTerrain] = 2
}
}
);
- Graph = GraphFactory.CreateRectangularGraph(Width, Height, movementTypes, unclearedTerrain);
+ Graph = GraphFactory.CreateRectangularGraph(Width, Height, movementTypes, UnclearedTerrain);
}
-
+
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/IHexMap.cs b/ConsoleApp/Maps/IHexMap.cs
index a979480..555868b 100644
--- a/ConsoleApp/Maps/IHexMap.cs
+++ b/ConsoleApp/Maps/IHexMap.cs
@@ -9,5 +9,7 @@ namespace ConsoleApp.Maps
int Width { get; }
int Height { get; }
MovementType DefaultMovement { get; }
+ public TerrainType ClearedTerrain { get; }
+ public TerrainType UnclearedTerrain { get; }
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/IMapFactory.cs b/ConsoleApp/Maps/IMapFactory.cs
index 59cd0d3..b369ba3 100644
--- a/ConsoleApp/Maps/IMapFactory.cs
+++ b/ConsoleApp/Maps/IMapFactory.cs
@@ -7,7 +7,6 @@ namespace ConsoleApp.Maps
{
int Height { get; }
int Width { get; }
- int CellWidth { get; }
void GenerateMaps(int x, int y, double minePercentage);
IHexMap GetHexMap();
ISquareMap GetSquareMap();
diff --git a/ConsoleApp/Maps/IMineMap.cs b/ConsoleApp/Maps/IMineMap.cs
index b21ed22..5e66fff 100644
--- a/ConsoleApp/Maps/IMineMap.cs
+++ b/ConsoleApp/Maps/IMineMap.cs
@@ -3,5 +3,8 @@ namespace ConsoleApp.Maps
public interface IMineMap
{
bool[,] Map { get; }
+
+ int TotalBombs { get; }
+ bool GetCell(int x, int y);
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/MapExtensions.cs b/ConsoleApp/Maps/MapExtensions.cs
index 8a046b4..4e3e0ab 100644
--- a/ConsoleApp/Maps/MapExtensions.cs
+++ b/ConsoleApp/Maps/MapExtensions.cs
@@ -15,6 +15,5 @@ namespace ConsoleApp.Maps
}
}
}
-
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/MapFactory.cs b/ConsoleApp/Maps/MapFactory.cs
index a7418dc..8d1d423 100644
--- a/ConsoleApp/Maps/MapFactory.cs
+++ b/ConsoleApp/Maps/MapFactory.cs
@@ -10,7 +10,6 @@ namespace ConsoleApp.Maps
private int _defaultWidth;
public int Height { get; protected set; }
public int Width { get; protected set; }
- public int CellWidth { get; }
@@ -22,11 +21,17 @@ namespace ConsoleApp.Maps
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);
+ //convert to cm
+ x *= 100;
+ y *= 100;
+ //calculate number of cells on x and y axis
+ var xCellCount = (int)Math.Ceiling((decimal) (x) / 25);
+ var yCellCount = (int)Math.Ceiling((decimal) (y) / 25);
+ Width = xCellCount;
+ Height = yCellCount;
+ _squareMap = new SquareMap(xCellCount, yCellCount);
+ _hexMap = new HexMap(xCellCount, yCellCount);
+ _mineMap = new MineMap(xCellCount, yCellCount, minePercentage);
}
public IHexMap GetHexMap() => _hexMap ?? throw new NullReferenceException("hex map not initialized");
public ISquareMap GetSquareMap() => _squareMap ?? throw new NullReferenceException("square map not initialized");
@@ -34,7 +39,6 @@ namespace ConsoleApp.Maps
public MapFactory(IVehicle vehicle)
{
- CellWidth = vehicle.Width/2;
_defaultHeight = 0;
_defaultWidth = 0;
Height = _defaultHeight;
diff --git a/ConsoleApp/Maps/MineMap.cs b/ConsoleApp/Maps/MineMap.cs
index bd2b8b1..c157a45 100644
--- a/ConsoleApp/Maps/MineMap.cs
+++ b/ConsoleApp/Maps/MineMap.cs
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
+using System.IO;
+using HexCore;
namespace ConsoleApp.Maps
{
@@ -9,24 +11,44 @@ namespace ConsoleApp.Maps
private int _x;
private int _y;
public bool[,] Map { get; }
+ public int TotalBombs { get; }
+ private List _placedMines;
+
public MineMap(int x, int y, double minePercentage)
{
_x = x;
_y = y;
- _mineCount = x*y*((int)minePercentage/100);
+ _placedMines = new List();
+ _mineCount = (int)(x*y*(minePercentage/100));
+ TotalBombs = _mineCount;
Map = new bool[x, y];
Map.Fill2DArray(false);
PlaceMines();
+ using(TextWriter tw = new StreamWriter("/Users/brady.bodily/Documents/Repositories/CS5890_Robot_Intelligence/RobotIntelFinal/ConsoleApp/Output/Mines.txt"))
+ {
+ foreach (var s in _placedMines)
+ tw.WriteLine($"{s.X} {s.Y}");
+ }
}
+ public bool GetCell(int x, int y) => Map[x,y];
+
private void PlaceMines()
{
var rand = new Random();
- for (int i = 0; i < _mineCount; i++)
+ for (var i = 0; i < _mineCount; i++)
{
- var x = rand.Next(_x);
- var y = rand.Next(_y);
- Map[x, y] = true;
+ var x = rand.Next(5,_x-5);
+ var y = rand.Next(5,_y-5);
+ if (Map[x, y] == true)
+ {
+ i--;
+ }
+ else
+ {
+ Map[x, y] = true;
+ _placedMines.Add(new Cell(x,y));
+ }
}
}
}
diff --git a/ConsoleApp/Maps/SquareMap.cs b/ConsoleApp/Maps/SquareMap.cs
index 3ad78b6..2c92e55 100644
--- a/ConsoleApp/Maps/SquareMap.cs
+++ b/ConsoleApp/Maps/SquareMap.cs
@@ -19,26 +19,21 @@ namespace ConsoleApp.Maps
///
public SquareMap(int x, int y)
{
- //convert to cm
- x *= 100;
- y *= 100;
- //calculate number of cells on x and y axis
- var xCellCount = (int)Math.Ceiling((decimal) (x) / 25);
- var yCellCount = (int)Math.Ceiling((decimal) (y) / 25);
+
//set Width and height Properties
- Width = xCellCount-1;
- Height = yCellCount-1;
+ Width = x-1;
+ Height = y-1;
//Initialize Map
- Map = new Cell[xCellCount, yCellCount];
+ Map = new Cell[x, y];
//set last cell;
StartingCell = Map[0, 0];
- for (int i = 0; i < xCellCount; i++)
+ for (int i = 0; i < x; i++)
{
- for (int j = 0; j < yCellCount; j++)
+ for (int j = 0; j < y; j++)
{
Map[i,j] = new Cell(i, j);
}
diff --git a/ConsoleApp/Output/DetectedMines.txt b/ConsoleApp/Output/DetectedMines.txt
new file mode 100644
index 0000000..cc278b8
--- /dev/null
+++ b/ConsoleApp/Output/DetectedMines.txt
@@ -0,0 +1,7 @@
+8 5
+8 6
+5 11
+9 10
+13 9
+13 14
+10 13
diff --git a/ConsoleApp/Output/Mines.txt b/ConsoleApp/Output/Mines.txt
new file mode 100644
index 0000000..a2cd0e2
--- /dev/null
+++ b/ConsoleApp/Output/Mines.txt
@@ -0,0 +1,8 @@
+5 11
+8 6
+13 14
+9 10
+13 9
+10 13
+10 6
+8 5
diff --git a/ConsoleApp/Output/SavedList.txt b/ConsoleApp/Output/SavedList.txt
new file mode 100644
index 0000000..1c83a93
--- /dev/null
+++ b/ConsoleApp/Output/SavedList.txt
@@ -0,0 +1,150 @@
+0 0
+1 0
+2 0
+3 0
+4 0
+5 0
+6 0
+7 0
+8 0
+9 0
+10 0
+11 0
+12 0
+13 0
+14 0
+15 0
+16 0
+17 0
+18 0
+19 0
+19 1
+19 2
+19 3
+18 3
+17 3
+16 3
+15 3
+14 3
+13 3
+12 3
+11 3
+10 3
+9 3
+9 2
+8 2
+7 2
+6 3
+5 3
+4 3
+3 3
+2 3
+1 3
+0 3
+1 4
+0 5
+0 6
+1 6
+2 6
+3 6
+4 6
+5 6
+6 6
+5 7
+6 8
+6 9
+7 9
+14 6
+15 6
+16 6
+17 6
+18 6
+19 6
+19 7
+19 8
+19 9
+18 9
+17 9
+16 9
+15 9
+16 10
+15 11
+15 12
+14 12
+15 12
+15 13
+16 14
+15 15
+15 16
+14 17
+13 17
+12 17
+11 17
+11 16
+10 15
+10 16
+9 16
+8 15
+8 14
+7 13
+6 14
+5 14
+4 14
+3 13
+3 12
+2 11
+3 10
+3 9
+1 9
+0 9
+1 10
+0 11
+0 12
+1 12
+2 12
+3 12
+3 13
+4 14
+4 15
+5 16
+5 17
+6 17
+7 17
+8 17
+9 17
+10 17
+11 17
+12 17
+13 17
+14 17
+15 16
+15 15
+16 14
+15 13
+15 12
+17 12
+18 12
+19 12
+19 13
+19 14
+19 15
+18 15
+17 15
+16 15
+15 15
+15 16
+14 17
+13 17
+12 17
+11 17
+11 16
+10 16
+9 16
+8 15
+6 15
+5 15
+4 15
+3 15
+2 15
+1 15
+0 15
diff --git a/ConsoleApp/Output/test.png b/ConsoleApp/Output/test.png
new file mode 100644
index 0000000..5b5e68a
Binary files /dev/null and b/ConsoleApp/Output/test.png differ
diff --git a/ConsoleApp/PathPlanners/IReactivePathPlanner.cs b/ConsoleApp/PathPlanners/IReactivePathPlanner.cs
index 68375a1..404d781 100644
--- a/ConsoleApp/PathPlanners/IReactivePathPlanner.cs
+++ b/ConsoleApp/PathPlanners/IReactivePathPlanner.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using ConsoleApp.Maps;
using HexCore;
namespace ConsoleApp.PathPlanners
@@ -6,5 +7,6 @@ namespace ConsoleApp.PathPlanners
public interface IReactivePathPlanner
{
Queue ReactiveHexPath { get; }
+ void GenerateReactiveHexPath(IHexMap hexMap, Queue optimalPath, Coordinate2D vehicleCurrentHexCell);
}
}
\ No newline at end of file
diff --git a/ConsoleApp/PathPlanners/PathPlanner.cs b/ConsoleApp/PathPlanners/PathPlanner.cs
index 5f50a66..d195b27 100644
--- a/ConsoleApp/PathPlanners/PathPlanner.cs
+++ b/ConsoleApp/PathPlanners/PathPlanner.cs
@@ -55,7 +55,7 @@ namespace ConsoleApp.PathPlanners
return path;
}
-
+
public Queue GenerateOptimalHexPath(IHexMap hexMap, IVehicle vehicle)
{
var currentPostion = vehicle.CurrentHexCell;
@@ -64,55 +64,44 @@ namespace ConsoleApp.PathPlanners
var path = new List();
while (!finished)
{
+ //Heading East
if (currentHeading == GlobalDirection.East)
{
path.AddRange(hexMap.Graph.GetShortestPath(
currentPostion,
- new Coordinate2D(hexMap.Width, currentPostion.Y, hexMap.OffsetType),
+ new Coordinate2D(hexMap.Width-1, currentPostion.Y, hexMap.OffsetType),
hexMap.DefaultMovement));
- currentPostion = new Coordinate2D(hexMap.Width, currentPostion.Y, hexMap.OffsetType);
+ currentPostion = new Coordinate2D(hexMap.Width-1, currentPostion.Y, hexMap.OffsetType);
}
-
- else if(currentHeading == GlobalDirection.West)
+ //Heading West
+ 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)
+ //Check for finish
+ if (currentPostion.Y + (vehicle.DetectorRadius * 2) >= hexMap.Height - 1)
{
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))
+ //Move Up edges of map
+ var tmpPosition = currentPostion;
+ var range = hexMap.Graph.GetRange(currentPostion, vehicle.DetectorRadius * 2);
+ for (var i = currentPostion.Y; i < currentPostion.Y + vehicle.DetectorRadius * 2; i++)
{
- 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);
+ var newCoord = new Coordinate2D(currentPostion.X, i, hexMap.OffsetType);
+ if (range.Contains(newCoord))
+ tmpPosition = newCoord;
+
}
+
path.AddRange(hexMap.Graph.GetShortestPath(
currentPostion,
tmpPosition,
@@ -122,9 +111,11 @@ namespace ConsoleApp.PathPlanners
currentHeading = GlobalDirection.West;
else
currentHeading = GlobalDirection.East;
-
-
+
+
+
}
+
return new Queue(path);
}
}
diff --git a/ConsoleApp/PathPlanners/ReactivePathPlanner.cs b/ConsoleApp/PathPlanners/ReactivePathPlanner.cs
index a77e9b2..258bd4d 100644
--- a/ConsoleApp/PathPlanners/ReactivePathPlanner.cs
+++ b/ConsoleApp/PathPlanners/ReactivePathPlanner.cs
@@ -1,20 +1,44 @@
using System.Collections.Generic;
+using ConsoleApp.Maps;
using HexCore;
namespace ConsoleApp.PathPlanners
{
public class ReactivePathPlanner : IReactivePathPlanner
{
- public Queue ReactiveHexPath { get; }
+ private Queue _reactiveHexPath;
+ public Queue ReactiveHexPath => _reactiveHexPath;
+
public ReactivePathPlanner()
{
- ReactiveHexPath = new Queue();
+ _reactiveHexPath = new Queue();
}
-
- public void GenerateReactiveHexPath(Graph graph, ref List optimalPath, Coordinate2D minePosition)
+ public void GenerateReactiveHexPath(IHexMap hexMap, Queue optimalPath,
+ Coordinate2D vehicleCurrentHexCell)
{
+ //Clean out any old path
+ _reactiveHexPath.Clear();
+ //If the optimal path is empty well we are done, otherwise pop 1
+ if (!optimalPath.TryDequeue(out var convergentPoint))
+ return;
+
+ //Dequeue until the cell is not blocked
+ while (hexMap.Graph.IsCellBlocked(convergentPoint))
+ {
+ //if optimal path is empty were done and we can not clear around this position, otherwise
+ //lest pop another.
+ if (!optimalPath.TryDequeue(out convergentPoint))
+ return;
+ }
+
+ var reactivePath = hexMap.Graph.GetShortestPath(vehicleCurrentHexCell, convergentPoint, hexMap.DefaultMovement);
+ foreach (var node in reactivePath)
+ {
+ _reactiveHexPath.Enqueue(node);
+ }
}
+
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Program.cs b/ConsoleApp/Program.cs
index 4cc3a51..625b13b 100644
--- a/ConsoleApp/Program.cs
+++ b/ConsoleApp/Program.cs
@@ -1,4 +1,8 @@
using System;
+using System.Diagnostics;
+using System.IO;
+using System.Reflection;
+using System.Threading;
using ConsoleApp.Maps;
namespace ConsoleApp
@@ -13,9 +17,33 @@ namespace ConsoleApp
_bootstrapper = BootStrapper.BootstrapSystem(new CoreModule());
_userConsole = new UserConsole();
Initialization();
+ GenerateImages();
Console.WriteLine("Program Completed");
}
+ private static void GenerateImages()
+ {
+ // var generateMap= "python3 ConsoleApp/plot.py";
+ // System.Diagnostics.Process.Start("CMD.exe",generateMap);
+ //
+ var file = Path.Combine("./",Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"plot.py");
+ ProcessStartInfo startInfo = new ProcessStartInfo()
+ {
+ FileName = "python3",
+ Arguments = file,
+ UseShellExecute = true
+ };
+ Process proc = new Process()
+ {
+ StartInfo = startInfo,
+ };
+ proc.Start();
+ while (!proc.HasExited)
+ {
+ Thread.Sleep(500);
+ }
+ }
+
private static void Initialization()
{
_userConsole.PrintStartMenu();
diff --git a/ConsoleApp/Sim/DetectionHead.cs b/ConsoleApp/Sim/DetectionHead.cs
index a510d3c..f9d4c12 100644
--- a/ConsoleApp/Sim/DetectionHead.cs
+++ b/ConsoleApp/Sim/DetectionHead.cs
@@ -10,7 +10,16 @@ namespace ConsoleApp.Sim
Graph graph,
Coordinate2D centerCoordinate,
int detectorRadius,
- GlobalDirection direction) => graph.GetRange(centerCoordinate, detectorRadius);
+ int vehicleTurnRadius)
+ {
+ var detectorCells = graph.GetRange(centerCoordinate, detectorRadius);
+ // var vehicleCells = graph.GetRange(centerCoordinate, vehicleTurnRadius);
+ // foreach (var vehicleCell in vehicleCells)
+ // {
+ // detectorCells.Remove(vehicleCell);
+ // }
+ return detectorCells;
+ }
public static List| GetCoveredCells(
ISquareMap squareMap,
diff --git a/ConsoleApp/Sim/IVehicle.cs b/ConsoleApp/Sim/IVehicle.cs
index 3db6ae0..95c1a01 100644
--- a/ConsoleApp/Sim/IVehicle.cs
+++ b/ConsoleApp/Sim/IVehicle.cs
@@ -1,4 +1,5 @@
using ConsoleApp.Maps;
+using HexCore;
namespace ConsoleApp.Sim
{
@@ -6,11 +7,9 @@ namespace ConsoleApp.Sim
{
int Length { get; }
int Width { get; }
- int DetectorOffset { get;}
+ int TurnRadius { get; }
int DetectorRadius { get;}
- HexCore.Coordinate2D CurrentHexCell { get; set; }
- Heading HexHeading { get; set; }
- Heading SquareHeading { get; set; }
+ Coordinate2D CurrentHexCell { get; set; }
ICell CurrentSquareCell { get; set; }
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Sim/Vehicle.cs b/ConsoleApp/Sim/Vehicle.cs
index e4cc62d..e1424a2 100644
--- a/ConsoleApp/Sim/Vehicle.cs
+++ b/ConsoleApp/Sim/Vehicle.cs
@@ -1,3 +1,5 @@
+using System;
+using System.Collections.Generic;
using ConsoleApp.Maps;
namespace ConsoleApp.Sim
@@ -6,12 +8,9 @@ namespace ConsoleApp.Sim
{
public int Length { get; }
public int Width { get; }
-
- public int DetectorOffset { get;}
+ public int TurnRadius { get; }
public int DetectorRadius { get;}
public HexCore.Coordinate2D CurrentHexCell { get; set; }
- public Heading HexHeading { get; set; }
- public Heading SquareHeading { get; set; }
public ICell CurrentSquareCell { get; set; }
@@ -20,12 +19,17 @@ namespace ConsoleApp.Sim
public Vehicle(IJsonDeserializor jsonDeserializor)
{
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;
+ var length = config.Length;
+ length *= 100;
+ Length = (int)Math.Ceiling((decimal)length/ 25);
+ var width = config.Width;
+ width *= 100;
+ Width = (int)Math.Ceiling((decimal)width/ 25);
+ DetectorRadius = (int)Math.Floor(((decimal)config.DetectorRadius * 100)/25)/2;
+ TurnRadius = (int)Math.Ceiling(Math.Sqrt(Math.Pow(config.Length, 2) * Math.Pow(config.Width, 2))/2);
+ // if (DetectorRadius <= TurnRadius)
+ // throw new ArgumentException("Detection radius must be larger than the vehicle turn radius");
+
}
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Sim/VehicleConfiguration.cs b/ConsoleApp/Sim/VehicleConfiguration.cs
index 74c2b50..91b47a0 100644
--- a/ConsoleApp/Sim/VehicleConfiguration.cs
+++ b/ConsoleApp/Sim/VehicleConfiguration.cs
@@ -5,6 +5,5 @@ namespace ConsoleApp.Sim
public int Length { get; set; }
public int Width { get; set; }
public int DetectorRadius { get; set; }
- public int DetectorOffset { get; set; }
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Sim/VehicleConfiguration.json b/ConsoleApp/Sim/VehicleConfiguration.json
index adb580b..8db1cfd 100644
--- a/ConsoleApp/Sim/VehicleConfiguration.json
+++ b/ConsoleApp/Sim/VehicleConfiguration.json
@@ -1,6 +1,5 @@
{
- "Length": 3,
- "Width": 2,
- "DetectorRadius": 3,
- "DetectorOffset": 2
-}
\ No newline at end of file
+ "Length": 1,
+ "Width": 1,
+ "DetectorRadius": 1
+}
diff --git a/ConsoleApp/SimRunner.cs b/ConsoleApp/SimRunner.cs
index be04c2d..647a15c 100644
--- a/ConsoleApp/SimRunner.cs
+++ b/ConsoleApp/SimRunner.cs
@@ -1,11 +1,16 @@
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
{
@@ -14,16 +19,15 @@ namespace ConsoleApp
private IMapFactory _mapFactory;
private IVehicle _vehicle;
- private int _cellWidth;
private IPathPlanner _pathPlanner;
private IMineMap _mineMap;
private IReactivePathPlanner _reactivePathPlanner;
+ private HashSet hexBombsFound = new HashSet();
+ private List testingPath = new List();
public SimRunner(IMapFactory mapFactory, IVehicle vehicle, IPathPlanner pathPlanner, IReactivePathPlanner reactivePathPlanner)
{
-
- _cellWidth = mapFactory.CellWidth;
_mapFactory = mapFactory;
_vehicle = vehicle;
_pathPlanner = pathPlanner;
@@ -44,9 +48,123 @@ namespace ConsoleApp
var hexMap = _mapFactory.GetHexMap();
_vehicle.CurrentHexCell = new Coordinate2D(0, 0, OffsetTypes.OddRowsRight);
var optimalPath = _pathPlanner.GenerateOptimalHexPath(hexMap, _vehicle);
- var reactivePath = _reactivePathPlanner.ReactiveHexPath;
+ var minimumMoves = optimalPath.Count;
+ var finished = false;
+ var totalMoves = 0;
+ while (!finished)
+ {
+ totalMoves += 1;
+ testingPath.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;
+ break;
+ }
+
+ var replan = false;
+ //if the next optimal cell is blocked then we need to replan around it.
+ while (hexMap.Graph.IsCellBlocked(nextOptimal))
+ {
+ replan = true;
+ if (optimalPath.TryDequeue(out nextOptimal)) continue;
+ finished = true;
+ break;
+ }
+ if(replan)
+ {
+ var tmpPath =
+ hexMap.Graph.GetShortestPath(_vehicle.CurrentHexCell, nextOptimal, hexMap.DefaultMovement);
+ if (Math.Abs(_vehicle.CurrentHexCell.X - nextOptimal.X) > 1 || Math.Abs(_vehicle.CurrentHexCell.Y - nextOptimal.Y) > 1)
+ optimalPath.Dequeue();
+ tmpPath.AddRange(optimalPath);
+
+ optimalPath.Clear();
+ foreach (var cell in tmpPath)
+ {
+ optimalPath.Enqueue(cell);
+ }
+ optimalPath.TryDequeue(out nextOptimal);
+ }
+
+ var last = testingPath[testingPath.Count-1];
+ if (Math.Abs(last.X - nextOptimal.X) > 1 || Math.Abs(last.Y - nextOptimal.Y) > 1)
+ Console.WriteLine("To big of a gap");
+
+ _vehicle.CurrentHexCell = nextOptimal;
+ }
+ }
+
+
+ //Debugging information
+ using(TextWriter tw = new StreamWriter("/Users/brady.bodily/Documents/Repositories/CS5890_Robot_Intelligence/RobotIntelFinal/ConsoleApp/Output/SavedList.txt"))
+ {
+ foreach (Coordinate2D s in testingPath)
+ tw.WriteLine($"{s.X} {s.Y}");
+ }
+ using(TextWriter tw = new StreamWriter("/Users/brady.bodily/Documents/Repositories/CS5890_Robot_Intelligence/RobotIntelFinal/ConsoleApp/Output/DetectedMines.txt"))
+ {
+ foreach (Coordinate2D s in hexBombsFound)
+ tw.WriteLine($"{s.X} {s.Y}");
+ }
+ var covered = CoveredCells();
+ Console.WriteLine($"Total cells traversed: {totalMoves} \n" +
+ $"Minimum required: {minimumMoves}");
+ Console.WriteLine($"Total bombs found: {hexBombsFound.Count}/{_mineMap.TotalBombs}");
+
}
-
+
+ private int CoveredCells()
+ {
+ var hexMap = _mapFactory.GetHexMap();
+ //for()
+ return 0;
+ }
+
+
+ private bool CheckCells(List detectionCells)
+ {
+ var found = false;
+ foreach (var cell in detectionCells.Where(cell => _mineMap.GetCell(cell.X, cell.Y)))
+ {
+ if (!hexBombsFound.Add(cell)) continue;
+ BlockCells(cell);
+ found = true;
+ }
+ return found;
+ }
+
+ private void BlockCells(Coordinate2D cell)
+ {
+ var hexMap = _mapFactory.GetHexMap();
+ var cellsToBlock = hexMap.Graph.GetRange(cell, _vehicle.Width / 2);
+ hexMap.Graph.BlockCells(cellsToBlock);
+
+ // //debugging
+ // foreach (var celllll in cellsToBlock)
+ // {
+ // Console.WriteLine($"({celllll.X}, {celllll.Y}) Blocked: {hexMap.Graph.GetCellState(celllll).IsBlocked}");
+ // }
+ }
+
private void SquareSimulation()
{
diff --git a/ConsoleApp/UserConsole.cs b/ConsoleApp/UserConsole.cs
index f59b44e..1eae039 100644
--- a/ConsoleApp/UserConsole.cs
+++ b/ConsoleApp/UserConsole.cs
@@ -22,9 +22,9 @@ namespace ConsoleApp
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: ");
+ Console.WriteLine($"Enter map width: ");
var x = GetUserInput();
if (!int.TryParse(x, out var width))
diff --git a/ConsoleApp/plot.py b/ConsoleApp/plot.py
new file mode 100644
index 0000000..bf2fd78
--- /dev/null
+++ b/ConsoleApp/plot.py
@@ -0,0 +1,39 @@
+import numpy as np
+import matplotlib.pyplot as plt
+import matplotlib
+
+
+if __name__ == "__main__":
+ xc = []
+ yc = []
+ xm = []
+ ym = []
+ xf = []
+ yf = []
+ with open("/Users/brady.bodily/Documents/Repositories/CS5890_Robot_Intelligence/RobotIntelFinal/ConsoleApp/Output/SavedList.txt") as c:
+ for line in c:
+ x, y = line.split()
+ xc.append(int(x))
+ yc.append(int(y))
+
+ with open("/Users/brady.bodily/Documents/Repositories/CS5890_Robot_Intelligence/RobotIntelFinal/ConsoleApp/Output/Mines.txt") as m:
+ for line in m:
+ x, y = line.split()
+ xm.append(int(x))
+ ym.append(int(y))
+
+ with open("/Users/brady.bodily/Documents/Repositories/CS5890_Robot_Intelligence/RobotIntelFinal/ConsoleApp/Output/DetectedMines.txt") as f:
+ for line in f:
+ x, y = line.split()
+ xf.append(int(x))
+ yf.append(int(y))
+ fig = plt.figure()
+ plt.plot(xc, yc)
+ plt.plot(xc, yc, 'o', label='vehicle', color='blue')
+ plt.plot(xm, ym, 'o', label='all mines', color='red')
+ plt.plot(xf, yf, 'o', label='detected mines', color='orange')
+ plt.title('test 9')
+ plt.legend(loc='lower left', fontsize='xx-small')
+
+ matplotlib.pyplot.savefig('/Users/brady.bodily/Documents/Repositories/CS5890_Robot_Intelligence/RobotIntelFinal/ConsoleApp/Output/test.png')
+ plt.close(fig)
\ No newline at end of file
| | |