Getting close
This commit is contained in:
@@ -22,6 +22,13 @@
|
||||
<None Update="Sim\VehicleConfiguration.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="plot.py">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Output" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -17,6 +17,9 @@ namespace ConsoleApp.Maps
|
||||
|
||||
public OffsetTypes OffsetType { get; }
|
||||
public MovementType DefaultMovement { get; }
|
||||
public TerrainType ClearedTerrain { get; }
|
||||
|
||||
public TerrainType UnclearedTerrain { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -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<IMovementType, Dictionary<ITerrainType, int>>
|
||||
{
|
||||
[DefaultMovement] = new Dictionary<ITerrainType, int>
|
||||
{
|
||||
[unclearedTerrain] = 1,
|
||||
[clearedTerrain] = 2
|
||||
[UnclearedTerrain] = 1,
|
||||
[ClearedTerrain] = 2
|
||||
}
|
||||
}
|
||||
);
|
||||
Graph = GraphFactory.CreateRectangularGraph(Width, Height, movementTypes, unclearedTerrain);
|
||||
Graph = GraphFactory.CreateRectangularGraph(Width, Height, movementTypes, UnclearedTerrain);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,5 +9,7 @@ namespace ConsoleApp.Maps
|
||||
int Width { get; }
|
||||
int Height { get; }
|
||||
MovementType DefaultMovement { get; }
|
||||
public TerrainType ClearedTerrain { get; }
|
||||
public TerrainType UnclearedTerrain { get; }
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -3,5 +3,8 @@ namespace ConsoleApp.Maps
|
||||
public interface IMineMap
|
||||
{
|
||||
bool[,] Map { get; }
|
||||
|
||||
int TotalBombs { get; }
|
||||
bool GetCell(int x, int y);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,5 @@ namespace ConsoleApp.Maps
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Cell> _placedMines;
|
||||
|
||||
public MineMap(int x, int y, double minePercentage)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_mineCount = x*y*((int)minePercentage/100);
|
||||
_placedMines = new List<Cell>();
|
||||
_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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,26 +19,21 @@ namespace ConsoleApp.Maps
|
||||
/// <param name="y"></param>
|
||||
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);
|
||||
}
|
||||
|
||||
7
ConsoleApp/Output/DetectedMines.txt
Normal file
7
ConsoleApp/Output/DetectedMines.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
8 5
|
||||
8 6
|
||||
5 11
|
||||
9 10
|
||||
13 9
|
||||
13 14
|
||||
10 13
|
||||
8
ConsoleApp/Output/Mines.txt
Normal file
8
ConsoleApp/Output/Mines.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
5 11
|
||||
8 6
|
||||
13 14
|
||||
9 10
|
||||
13 9
|
||||
10 13
|
||||
10 6
|
||||
8 5
|
||||
150
ConsoleApp/Output/SavedList.txt
Normal file
150
ConsoleApp/Output/SavedList.txt
Normal file
@@ -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
|
||||
BIN
ConsoleApp/Output/test.png
Normal file
BIN
ConsoleApp/Output/test.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
@@ -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<Coordinate2D> ReactiveHexPath { get; }
|
||||
void GenerateReactiveHexPath(IHexMap hexMap, Queue<Coordinate2D> optimalPath, Coordinate2D vehicleCurrentHexCell);
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ namespace ConsoleApp.PathPlanners
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
public Queue<Coordinate2D> GenerateOptimalHexPath(IHexMap hexMap, IVehicle vehicle)
|
||||
{
|
||||
var currentPostion = vehicle.CurrentHexCell;
|
||||
@@ -64,55 +64,44 @@ namespace ConsoleApp.PathPlanners
|
||||
var path = new List<Coordinate2D>();
|
||||
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<Coordinate2D>(path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,44 @@
|
||||
using System.Collections.Generic;
|
||||
using ConsoleApp.Maps;
|
||||
using HexCore;
|
||||
|
||||
namespace ConsoleApp.PathPlanners
|
||||
{
|
||||
public class ReactivePathPlanner : IReactivePathPlanner
|
||||
{
|
||||
public Queue<Coordinate2D> ReactiveHexPath { get; }
|
||||
private Queue<Coordinate2D> _reactiveHexPath;
|
||||
public Queue<Coordinate2D> ReactiveHexPath => _reactiveHexPath;
|
||||
|
||||
|
||||
public ReactivePathPlanner()
|
||||
{
|
||||
ReactiveHexPath = new Queue<Coordinate2D>();
|
||||
_reactiveHexPath = new Queue<Coordinate2D>();
|
||||
}
|
||||
|
||||
public void GenerateReactiveHexPath(Graph graph, ref List<Coordinate3D> optimalPath, Coordinate2D minePosition)
|
||||
public void GenerateReactiveHexPath(IHexMap hexMap, Queue<Coordinate2D> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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<Cell> GetCoveredCells(
|
||||
ISquareMap squareMap,
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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<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;
|
||||
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");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
{
|
||||
"Length": 3,
|
||||
"Width": 2,
|
||||
"DetectorRadius": 3,
|
||||
"DetectorOffset": 2
|
||||
}
|
||||
"Length": 1,
|
||||
"Width": 1,
|
||||
"DetectorRadius": 1
|
||||
}
|
||||
|
||||
@@ -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<Coordinate2D> hexBombsFound = new HashSet<Coordinate2D>();
|
||||
private List<Coordinate2D> testingPath = new List<Coordinate2D>();
|
||||
|
||||
|
||||
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<Coordinate2D> 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()
|
||||
{
|
||||
|
||||
@@ -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))
|
||||
|
||||
39
ConsoleApp/plot.py
Normal file
39
ConsoleApp/plot.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user