Back up
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="VehicleConfiguration.json">
|
||||
<None Update="Vehicle\VehicleConfiguration.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Generate Hex map with cells of 25cm X 25cm
|
||||
@@ -20,6 +26,8 @@ namespace ConsoleApp.Maps
|
||||
/// <param name="y"></param>
|
||||
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<IMovementType, Dictionary<ITerrainType, int>>
|
||||
{
|
||||
[movement] = new Dictionary<ITerrainType, int>
|
||||
[DefaultMovement] = new Dictionary<ITerrainType, int>
|
||||
{
|
||||
[unclearedTerrain] = 1,
|
||||
[clearedTerrain] = 2
|
||||
@@ -49,5 +57,6 @@ namespace ConsoleApp.Maps
|
||||
Graph = GraphFactory.CreateRectangularGraph(Width, Height, movementTypes, unclearedTerrain);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -12,5 +12,6 @@ namespace ConsoleApp.Maps
|
||||
Cell GetCell(int x, int y);
|
||||
int Height { get; }
|
||||
int Width { get; }
|
||||
List<Cell> GetRange(Cell centerCell, int radius);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ConsoleApp.Vehicle;
|
||||
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using HexCore;
|
||||
using ImTools;
|
||||
|
||||
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
@@ -20,7 +19,6 @@ namespace ConsoleApp.Maps
|
||||
/// <param name="y"></param>
|
||||
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<Cell> GetRange(Cell centerCell, int radius)
|
||||
{
|
||||
var inRange = new List<Cell>();
|
||||
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];
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using ConsoleApp.Maps;
|
||||
using ConsoleApp.Vehicle;
|
||||
|
||||
namespace ConsoleApp.PathPlanners
|
||||
{
|
||||
public interface IPathPlanner
|
||||
{
|
||||
Queue<ICell> GenerateOptimalSquarePath(ISquareMap map, IVehicle vehicle);
|
||||
Queue<ICell> GenerateOptimalHexPath(HexMap hexMap, IVehicle vehicle);
|
||||
Queue<ICell> GenerateOptimalHexPath(IHexMap hexMap, IVehicle vehicle);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<ICell>();
|
||||
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<ICell> GenerateOptimalHexPath(HexMap hexMap, IVehicle vehicle)
|
||||
public Queue<ICell> 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
20
ConsoleApp/Vehicle/DetectionHead.cs
Normal file
20
ConsoleApp/Vehicle/DetectionHead.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
using ConsoleApp.Maps;
|
||||
using HexCore;
|
||||
|
||||
namespace ConsoleApp.Vehicle
|
||||
{
|
||||
public class DetectionHead
|
||||
{
|
||||
public List<Coordinate2D> GetCoveredCells(
|
||||
Graph graph,
|
||||
Coordinate2D centerCoordinate,
|
||||
int detectorRadius,
|
||||
GlobalDirection direction) => graph.GetRange(centerCoordinate, detectorRadius);
|
||||
|
||||
public List<Cell> GetCoveredCells(
|
||||
ISquareMap squareMap,
|
||||
Cell centerCell,
|
||||
int detectorRadius) => squareMap.GetRange(centerCell, detectorRadius);
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
@@ -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<VehicleConfiguration>("/Users/brady.bodily/Documents/Repositories/CS5890_Robot_Intelligence/RobotIntelFinal/ConsoleApp/VehicleConfiguration.json");
|
||||
var config = jsonDeserializor.DeserializeObject<VehicleConfiguration>("/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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user