diff --git a/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml b/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml
index d36be7c..2c926b7 100644
--- a/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml
+++ b/.idea/.idea.RobotIntelFinal/.idea/contentModel.xml
@@ -11,7 +11,6 @@
-
@@ -39,9 +38,13 @@
-
-
-
+
+
+
+
+
+
+
diff --git a/.idea/.idea.RobotIntelFinal/.idea/workspace.xml b/.idea/.idea.RobotIntelFinal/.idea/workspace.xml
index e89dcd6..0a6ccca 100644
--- a/.idea/.idea.RobotIntelFinal/.idea/workspace.xml
+++ b/.idea/.idea.RobotIntelFinal/.idea/workspace.xml
@@ -18,19 +18,23 @@
+
+
-
+
+
+
-
-
-
+
+
+
@@ -77,15 +81,21 @@
-
-
-
-
+
+
+
-
-
+
+
+
+
+
+
+
+
+
@@ -163,7 +173,7 @@
-
+
@@ -195,14 +205,27 @@
34
-
+
-
+
+
+ file://$PROJECT_DIR$/ConsoleApp/PathPlanners/PathPlanner.cs
+ 61
+
+
+
+
+
+
+
+
+
+
diff --git a/ConsoleApp/ConsoleApp.csproj b/ConsoleApp/ConsoleApp.csproj
index 0715900..02c0777 100644
--- a/ConsoleApp/ConsoleApp.csproj
+++ b/ConsoleApp/ConsoleApp.csproj
@@ -19,7 +19,7 @@
-
+
PreserveNewest
diff --git a/ConsoleApp/Maps/HexMap.cs b/ConsoleApp/Maps/HexMap.cs
index 39b2311..bbb7b51 100644
--- a/ConsoleApp/Maps/HexMap.cs
+++ b/ConsoleApp/Maps/HexMap.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using HexCore;
+using ImTools;
namespace ConsoleApp.Maps
{
@@ -12,6 +14,10 @@ namespace ConsoleApp.Maps
public int Height { get; }
public Graph Graph { get; }
+
+ public OffsetTypes OffsetType { get; }
+ public MovementType DefaultMovement { get; }
+
///
/// Generate Hex map with cells of 25cm X 25cm
@@ -20,6 +26,8 @@ namespace ConsoleApp.Maps
///
public HexMap(int x, int y)
{
+ //Set Offset Type for 2d -> 3d conversion
+ OffsetType = OffsetTypes.OddRowsRight;
//convert to cm
x *= 100;
y *= 100;
@@ -34,12 +42,12 @@ namespace ConsoleApp.Maps
var unclearedTerrain = new TerrainType(1, "uncleared");
var clearedTerrain = new TerrainType(2, "cleared");
- var movement = new MovementType(1, "default");
+ DefaultMovement = new MovementType(1, "default");
var movementTypes = new MovementTypes(
new ITerrainType[] { unclearedTerrain, clearedTerrain },
new Dictionary>
{
- [movement] = new Dictionary
+ [DefaultMovement] = new Dictionary
{
[unclearedTerrain] = 1,
[clearedTerrain] = 2
@@ -49,5 +57,6 @@ namespace ConsoleApp.Maps
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 f535182..a979480 100644
--- a/ConsoleApp/Maps/IHexMap.cs
+++ b/ConsoleApp/Maps/IHexMap.cs
@@ -5,5 +5,9 @@ namespace ConsoleApp.Maps
public interface IHexMap
{
Graph Graph { get; }
+ OffsetTypes OffsetType { get; }
+ int Width { get; }
+ int Height { get; }
+ MovementType DefaultMovement { get; }
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/ISquareMap.cs b/ConsoleApp/Maps/ISquareMap.cs
index 7c5bf05..3d5e915 100644
--- a/ConsoleApp/Maps/ISquareMap.cs
+++ b/ConsoleApp/Maps/ISquareMap.cs
@@ -12,5 +12,6 @@ namespace ConsoleApp.Maps
Cell GetCell(int x, int y);
int Height { get; }
int Width { get; }
+ List GetRange(Cell centerCell, int radius);
}
}
\ No newline at end of file
diff --git a/ConsoleApp/Maps/MapFactory.cs b/ConsoleApp/Maps/MapFactory.cs
index 383e613..1866971 100644
--- a/ConsoleApp/Maps/MapFactory.cs
+++ b/ConsoleApp/Maps/MapFactory.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using ConsoleApp.Vehicle;
namespace ConsoleApp.Maps
{
diff --git a/ConsoleApp/Maps/SquareMap.cs b/ConsoleApp/Maps/SquareMap.cs
index 287a70d..3ad78b6 100644
--- a/ConsoleApp/Maps/SquareMap.cs
+++ b/ConsoleApp/Maps/SquareMap.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
-using HexCore;
-using ImTools;
+
namespace ConsoleApp.Maps
{
@@ -20,7 +19,6 @@ namespace ConsoleApp.Maps
///
public SquareMap(int x, int y)
{
- HexGraph = default;
//convert to cm
x *= 100;
y *= 100;
@@ -63,8 +61,49 @@ namespace ConsoleApp.Maps
return possibles;
}
-
- public Graph HexGraph { get; }
+
+ public List GetRange(Cell centerCell, int radius)
+ {
+ var inRange = new List();
+ var cx = centerCell.X;
+ var cy = centerCell.Y;
+ var topLeft = GetTopCellInBoundingBox(cx, cy, radius);
+ var bottomRight = GetBottomCellInBoundingBox(cx, cy, radius);
+ for (var i = topLeft.X; i < bottomRight.X; i++)
+ {
+ for (var j = bottomRight.Y; j < topLeft.Y; j++)
+ {
+ if (Math.Pow(i - cx, 2) + Math.Pow(j - cy, 2) < Math.Pow(radius,2))
+ {
+ inRange.Add(Map[i,j]);
+ }
+ }
+ }
+ return inRange;
+ }
+
+ private Cell GetTopCellInBoundingBox(int cx, int cy, int radius)
+ {
+ int topX, topY;
+ if (cy + radius > Height) topY = Height;
+ else
+ topY = cy + radius;
+ if (cx - radius < 0) topX = 0;
+ else
+ topX = cx - radius;
+ return Map[topX, topY];
+ }
+ private Cell GetBottomCellInBoundingBox(int cx, int cy, int radius)
+ {
+ int bottomX, bottomY;
+ if (cy - radius > 0) bottomY = 0;
+ else
+ bottomY = cy - radius;
+ if (cx + radius < Width) bottomX = Width;
+ else
+ bottomX = cx + radius;
+ return Map[bottomX, bottomY];
+ }
public Cell GetCell(int x, int y) => Map[x, y];
diff --git a/ConsoleApp/PathPlanners/IPathPlanner.cs b/ConsoleApp/PathPlanners/IPathPlanner.cs
index a48b27d..a9bfdf7 100644
--- a/ConsoleApp/PathPlanners/IPathPlanner.cs
+++ b/ConsoleApp/PathPlanners/IPathPlanner.cs
@@ -1,12 +1,13 @@
using System.Collections.Generic;
using ConsoleApp.Maps;
+using ConsoleApp.Vehicle;
namespace ConsoleApp.PathPlanners
{
public interface IPathPlanner
{
Queue GenerateOptimalSquarePath(ISquareMap map, IVehicle vehicle);
- Queue GenerateOptimalHexPath(HexMap hexMap, IVehicle vehicle);
+ Queue GenerateOptimalHexPath(IHexMap hexMap, IVehicle vehicle);
}
}
\ No newline at end of file
diff --git a/ConsoleApp/PathPlanners/PathPlanner.cs b/ConsoleApp/PathPlanners/PathPlanner.cs
index 52f005d..a88d179 100644
--- a/ConsoleApp/PathPlanners/PathPlanner.cs
+++ b/ConsoleApp/PathPlanners/PathPlanner.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using ConsoleApp.Maps;
+using ConsoleApp.Vehicle;
+using HexCore;
namespace ConsoleApp.PathPlanners
{
@@ -11,7 +13,7 @@ namespace ConsoleApp.PathPlanners
var path = new Queue();
var myCell = map.StartingCell;
var finished = false;
- var width_cm = (double)(vehicle.DetectorWidth) * 100;
+ var width_cm = (double)(vehicle.DetectorRadius) * 100 * 2;
var swathOffset = (int)Math.Floor((decimal) (width_cm) / 25) + 1;
var currentHeading = GlobalDirection.North;
while (!finished)
@@ -53,8 +55,11 @@ namespace ConsoleApp.PathPlanners
return path;
}
- public Queue GenerateOptimalHexPath(HexMap 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();
}
}
diff --git a/ConsoleApp/SimRunner.cs b/ConsoleApp/SimRunner.cs
index efd89da..6aad005 100644
--- a/ConsoleApp/SimRunner.cs
+++ b/ConsoleApp/SimRunner.cs
@@ -4,6 +4,7 @@ using System.Threading;
using System.Threading.Tasks;
using ConsoleApp.Maps;
using ConsoleApp.PathPlanners;
+using ConsoleApp.Vehicle;
using HexCore;
namespace ConsoleApp
@@ -39,7 +40,7 @@ namespace ConsoleApp
{
var hexMap = _mapFactory.GetHexMap();
_vehicle.CurrentHexCell = new Coordinate2D(0, 0, OffsetTypes.OddRowsRight);
- //var optimalPath = _pathPlanner.GenerateOptimalHexPath(hexMap, _vehicle);
+ var optimalPath = _pathPlanner.GenerateOptimalHexPath(hexMap, _vehicle);
}
diff --git a/ConsoleApp/Vehicle/DetectionHead.cs b/ConsoleApp/Vehicle/DetectionHead.cs
new file mode 100644
index 0000000..3217927
--- /dev/null
+++ b/ConsoleApp/Vehicle/DetectionHead.cs
@@ -0,0 +1,20 @@
+using System.Collections.Generic;
+using ConsoleApp.Maps;
+using HexCore;
+
+namespace ConsoleApp.Vehicle
+{
+ public class DetectionHead
+ {
+ public List GetCoveredCells(
+ Graph graph,
+ Coordinate2D centerCoordinate,
+ int detectorRadius,
+ GlobalDirection direction) => graph.GetRange(centerCoordinate, detectorRadius);
+
+ public List| GetCoveredCells(
+ ISquareMap squareMap,
+ Cell centerCell,
+ int detectorRadius) => squareMap.GetRange(centerCell, detectorRadius);
+ }
+}
\ No newline at end of file
diff --git a/ConsoleApp/IVehicle.cs b/ConsoleApp/Vehicle/IVehicle.cs
similarity index 84%
rename from ConsoleApp/IVehicle.cs
rename to ConsoleApp/Vehicle/IVehicle.cs
index 4d47053..94fe591 100644
--- a/ConsoleApp/IVehicle.cs
+++ b/ConsoleApp/Vehicle/IVehicle.cs
@@ -1,13 +1,13 @@
using ConsoleApp.Maps;
-namespace ConsoleApp
+namespace ConsoleApp.Vehicle
{
public interface IVehicle
{
int Length { get; }
int Width { get; }
int DetectorOffset { get;}
- int DetectorWidth { get;}
+ int DetectorRadius { get;}
HexCore.Coordinate2D CurrentHexCell { get; set; }
Heading HexHeading { get; set; }
Heading SquareHeading { get; set; }
diff --git a/ConsoleApp/Vehicle.cs b/ConsoleApp/Vehicle/Vehicle.cs
similarity index 72%
rename from ConsoleApp/Vehicle.cs
rename to ConsoleApp/Vehicle/Vehicle.cs
index 78b6503..3a07573 100644
--- a/ConsoleApp/Vehicle.cs
+++ b/ConsoleApp/Vehicle/Vehicle.cs
@@ -1,7 +1,6 @@
-using System;
using ConsoleApp.Maps;
-namespace ConsoleApp
+namespace ConsoleApp.Vehicle
{
public class Vehicle : IVehicle
{
@@ -9,25 +8,25 @@ namespace ConsoleApp
public int Width { get; }
public int DetectorOffset { get;}
- public int DetectorWidth { 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; }
+ public DetectionHead DetectionHead { get; }
public Vehicle(IJsonDeserializor jsonDeserializor)
{
- var config = jsonDeserializor.DeserializeObject("/Users/brady.bodily/Documents/Repositories/CS5890_Robot_Intelligence/RobotIntelFinal/ConsoleApp/VehicleConfiguration.json");
+ var config = jsonDeserializor.DeserializeObject("/Users/brady.bodily/Documents/Repositories/CS5890_Robot_Intelligence/RobotIntelFinal/ConsoleApp/Vehicle/VehicleConfiguration.json");
Length = config.Length;
Width = config.Width;
- DetectorWidth = config.DetectorWidth;
+ DetectorRadius = config.DetectorRadius;
DetectorOffset = config.DetectorOffset;
CurrentHexCell = default;
CurrentSquareCell = default;
- HexHeading = default;
- SquareHeading = default;
+ DetectionHead = new DetectionHead();
}
}
}
\ No newline at end of file
diff --git a/ConsoleApp/VehicleConfiguration.cs b/ConsoleApp/Vehicle/VehicleConfiguration.cs
similarity index 70%
rename from ConsoleApp/VehicleConfiguration.cs
rename to ConsoleApp/Vehicle/VehicleConfiguration.cs
index 2b84226..42411a5 100644
--- a/ConsoleApp/VehicleConfiguration.cs
+++ b/ConsoleApp/Vehicle/VehicleConfiguration.cs
@@ -1,10 +1,10 @@
-namespace ConsoleApp
+namespace ConsoleApp.Vehicle
{
public class VehicleConfiguration
{
public int Length { get; set; }
public int Width { get; set; }
- public int DetectorWidth { get; set; }
+ public int DetectorRadius { get; set; }
public int DetectorOffset { get; set; }
}
}
\ No newline at end of file
diff --git a/ConsoleApp/VehicleConfiguration.json b/ConsoleApp/Vehicle/VehicleConfiguration.json
similarity index 100%
rename from ConsoleApp/VehicleConfiguration.json
rename to ConsoleApp/Vehicle/VehicleConfiguration.json
| | | |